-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix: add resync mechanism to sync Snap accounts states with client accounts cp-13.11.0 #37987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,20 @@ function* ulidGenerator(ulids = mockULIDs) { | |
| throw new Error('should not be called after exhausting provided IDs'); | ||
| } | ||
|
|
||
| /** | ||
| * Utility function that waits for all pending promises to be resolved. | ||
| * This is necessary when testing asynchronous execution flows that are | ||
| * initiated by synchronous calls. | ||
| * | ||
| * @returns A promise that resolves when all pending promises are completed. | ||
| */ | ||
| async function waitForAllPromises() { | ||
| // Wait for next tick to flush all pending promises. It's requires since | ||
| // we are testing some asynchronous execution flows that are started by | ||
| // synchronous calls. | ||
| await new Promise(process.nextTick); | ||
| } | ||
|
|
||
| /** | ||
| * Generate mock patches for a complete state replacement. | ||
| * | ||
|
|
@@ -728,6 +742,34 @@ describe('MetaMaskController', () => { | |
| }); | ||
| }); | ||
|
|
||
| describe('#submitPasswordOrEncryptionKey', () => { | ||
| const password = 'a-fake-password'; | ||
|
|
||
| it('should call resyncAccounts and alignWallets asynchronously when submitPasswordOrEncryptionKey is called', async () => { | ||
| const mockAlignWallets = jest.fn(); | ||
| const mockResyncAccounts = jest.fn(); | ||
|
|
||
| // We only trigger this behavior when the feature flag is enabled. | ||
| jest | ||
| .spyOn(metamaskController, 'isMultichainAccountsFeatureState2Enabled') | ||
| .mockReturnValue(true); | ||
|
|
||
| metamaskController.multichainAccountService = { | ||
| init: jest.fn(), | ||
| resyncAccounts: mockResyncAccounts, | ||
| alignWallets: mockAlignWallets, | ||
| }; | ||
|
|
||
| await metamaskController.createNewVaultAndRestore(password, TEST_SEED); | ||
| await metamaskController.submitPasswordOrEncryptionKey({ password }); | ||
|
|
||
| await waitForAllPromises(); | ||
|
|
||
| expect(mockResyncAccounts).toHaveBeenCalled(); | ||
| expect(mockAlignWallets).toHaveBeenCalled(); | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Race condition in async test verificationThe test uses
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's ok for now, I'll keep this simple. |
||
| }); | ||
|
|
||
| describe('setLocked', () => { | ||
| it('should lock KeyringController', async () => { | ||
| await metamaskController.createNewVaultAndKeychain('password'); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Unconditional multichain service calls cause runtime errors
The conditional compilation directives around
multichainAccountService.init()were removed, butmultichainAccountServiceis only defined in builds with themultichainflag enabled. This causes the code to attempt calling methods onundefinedin non-multichain builds, resulting in runtime errors. The same issue affects theresyncAndAlignAccountsfunction which callsresyncAccounts()andalignWallets()on the potentially undefined service.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually removed it cause we were already using the service without the codefence. Anyway, this code fence should be entirely remove at some point.