Skip to content

fix: enhance session comparison (SDK V2)#1365

Merged
ffmcgee725 merged 4 commits into
mainfrom
jc/session-upgrade-check-adjustment
Oct 10, 2025
Merged

fix: enhance session comparison (SDK V2)#1365
ffmcgee725 merged 4 commits into
mainfrom
jc/session-upgrade-check-adjustment

Conversation

@ffmcgee725

@ffmcgee725 ffmcgee725 commented Oct 10, 2025

Copy link
Copy Markdown
Member

Explanation

When we are managing session upgrade in both transports, we currently check is sessionScopes have changes but we should also be checking if the accounts are the same ones as well, and if not, upgrade the session.

This PR creates an enhanced scope checking utility function to be used in both transports.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

Note

Adds isSameScopesAndAccounts and updates transports to recreate sessions when scopes or proposed accounts differ; includes comprehensive tests.

  • Utils:
    • Add isSameScopesAndAccounts(currentScopes, proposedScopes, walletSession, proposedCaipAccountIds) to validate both scopes and CAIP accounts against existing sessionScopes.
  • Transports:
    • multichain/transports/default and multichain/transports/mwp now use isSameScopesAndAccounts when connecting/resuming; recreate (create + revoke) session if mismatch.
  • Tests:
    • Add extensive unit tests for isSameScopesAndAccounts, covering exact matches, mismatched scopes, subset accounts, empty/absent accounts, ordering differences, and multiple accounts per scope.

Written by Cursor Bugbot for commit 21a6ce2. This will update automatically on new commits. Configure here.

@ffmcgee725
ffmcgee725 marked this pull request as ready for review October 10, 2025 10:39
@ffmcgee725
ffmcgee725 requested a review from a team as a code owner October 10, 2025 10:39
@codecov

codecov Bot commented Oct 10, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.99%. Comparing base (7587a0e) to head (21a6ce2).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1365   +/-   ##
=======================================
  Coverage   74.99%   74.99%           
=======================================
  Files         184      184           
  Lines        4519     4519           
  Branches     1108     1108           
=======================================
  Hits         3389     3389           
  Misses       1130     1130           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +166 to +171
const existingAccountIds: CaipAccountId[] = [];
for (const scopeObject of Object.values(walletSession.sessionScopes)) {
if (scopeObject.accounts) {
existingAccountIds.push(...scopeObject.accounts);
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const existingAccountIds: CaipAccountId[] = [];
for (const scopeObject of Object.values(walletSession.sessionScopes)) {
if (scopeObject.accounts) {
existingAccountIds.push(...scopeObject.accounts);
}
}
const existingAccountIds: CaipAccountId[] = Object.values(walletSession.sessionScopes)
.filter(({accounts}) => Boolean(accounts))
.flatMap(({accounts}) => accounts)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wenfix wenfix left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@sonarqubecloud

Copy link
Copy Markdown

@ffmcgee725
ffmcgee725 merged commit c2cb539 into main Oct 10, 2025
44 checks passed
@ffmcgee725
ffmcgee725 deleted the jc/session-upgrade-check-adjustment branch October 10, 2025 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants