diff --git a/test/e2e/helpers/identity/user-storage/userStorageMockttpController.ts b/test/e2e/helpers/identity/user-storage/userStorageMockttpController.ts index 88a5aabf706b..24191873cc43 100644 --- a/test/e2e/helpers/identity/user-storage/userStorageMockttpController.ts +++ b/test/e2e/helpers/identity/user-storage/userStorageMockttpController.ts @@ -91,6 +91,9 @@ export class UserStorageMockttpController { request: Pick, statusCode: number = 200, ) => { + // #region agent log + console.log(`[SYNC_DEBUG:onGet] path=${path}, url=${request.path}`); + // #endregion const srpIdentifier = getSrpIdentifierFromHeaders(request.headers); const internalPathData = this.paths.get(path); @@ -154,6 +157,9 @@ export class UserStorageMockttpController { request: Pick, statusCode: number = 204, ) => { + // #region agent log + console.log(`[SYNC_DEBUG:onPut] path=${path}, url=${request.path}`); + // #endregion const srpIdentifier = getSrpIdentifierFromHeaders(request.headers); const isFeatureEntry = determineIfFeatureEntryFromURL(request.path); @@ -330,6 +336,15 @@ export class UserStorageMockttpController { }, ) => { const previouslySetupPath = this.paths.get(path); + // #region agent log + const hadPreviousData = !!previouslySetupPath; + const previousResponseCount = previouslySetupPath?.response?.length ?? 0; + const newResponseCount = + overrides?.getResponse?.length ?? previousResponseCount; + console.log( + `[SYNC_DEBUG:setupPath] path=${path}, hadPreviousData=${hadPreviousData}, previousResponseCount=${previousResponseCount}, newResponseCount=${newResponseCount}`, + ); + // #endregion this.paths.set(path, { response: overrides?.getResponse || previouslySetupPath?.response || [], @@ -357,5 +372,8 @@ export class UserStorageMockttpController { .thenCallback((request) => this.onDelete(path, request, overrides?.deleteStatusCode), ); + // #region agent log + console.log(`[SYNC_DEBUG:setupPath] Handlers registered for path=${path}`); + // #endregion }; } diff --git a/test/e2e/page-objects/pages/home/homepage.ts b/test/e2e/page-objects/pages/home/homepage.ts index 86e85c424e41..a286cad69af7 100644 --- a/test/e2e/page-objects/pages/home/homepage.ts +++ b/test/e2e/page-objects/pages/home/homepage.ts @@ -453,9 +453,26 @@ class HomePage { ); await this.driver.delay(POST_UNLOCK_DELAY); console.log('Check if account syncing has synced at least once'); + // #region agent log + let pollCount = 0; + // #endregion await this.driver.waitUntil( async () => { const uiState = await getCleanAppState(this.driver); + // #region agent log + pollCount += 1; + const syncState = + uiState?.metamask?.hasAccountTreeSyncingSyncedAtLeastOnce; + const isSignedIn = uiState?.metamask?.isSignedIn; + const isUnlocked = uiState?.metamask?.isUnlocked; + const isBackupAndSyncEnabled = + uiState?.metamask?.isBackupAndSyncEnabled; + const isAccountSyncingEnabled = + uiState?.metamask?.isAccountSyncingEnabled; + console.log( + `[SYNC_DEBUG:poll#${pollCount}] syncState=${syncState}, isSignedIn=${isSignedIn}, isUnlocked=${isUnlocked}, isBackupAndSyncEnabled=${isBackupAndSyncEnabled}, isAccountSyncingEnabled=${isAccountSyncingEnabled}`, + ); + // #endregion // Check for nullish, as the state we might seems to be `null` sometimes. return ( uiState?.metamask?.hasAccountTreeSyncingSyncedAtLeastOnce === true diff --git a/test/e2e/tests/identity/mocks.ts b/test/e2e/tests/identity/mocks.ts index 5d181941570a..ba46cf0038ad 100644 --- a/test/e2e/tests/identity/mocks.ts +++ b/test/e2e/tests/identity/mocks.ts @@ -31,46 +31,22 @@ export async function mockIdentityServices( mockAPICall(server, AuthMocks.getMockAuthAccessTokenResponse()); // Storage - if ( - !userStorageMockttpControllerInstance?.paths.get( - USER_STORAGE_FEATURE_NAMES.accounts, - ) - ) { - userStorageMockttpControllerInstance.setupPath( - USER_STORAGE_FEATURE_NAMES.accounts, - server, - ); - } - if ( - !userStorageMockttpControllerInstance?.paths.get( - USER_STORAGE_FEATURE_NAMES.addressBook, - ) - ) { - userStorageMockttpControllerInstance.setupPath( - USER_STORAGE_FEATURE_NAMES.addressBook, - server, - ); - } - if ( - !userStorageMockttpControllerInstance?.paths.get( - USER_STORAGE_WALLETS_FEATURE_KEY, - ) - ) { - userStorageMockttpControllerInstance.setupPath( - USER_STORAGE_WALLETS_FEATURE_KEY, - server, - ); - } - if ( - !userStorageMockttpControllerInstance?.paths.get( - USER_STORAGE_GROUPS_FEATURE_KEY, - ) - ) { - userStorageMockttpControllerInstance.setupPath( - USER_STORAGE_GROUPS_FEATURE_KEY, - server, - ); - } + userStorageMockttpControllerInstance.setupPath( + USER_STORAGE_FEATURE_NAMES.accounts, + server, + ); + userStorageMockttpControllerInstance.setupPath( + USER_STORAGE_FEATURE_NAMES.addressBook, + server, + ); + userStorageMockttpControllerInstance.setupPath( + USER_STORAGE_WALLETS_FEATURE_KEY, + server, + ); + userStorageMockttpControllerInstance.setupPath( + USER_STORAGE_GROUPS_FEATURE_KEY, + server, + ); } export const MOCK_SRP_E2E_IDENTIFIER_BASE_KEY = 'MOCK_SRP_IDENTIFIER'; @@ -163,17 +139,6 @@ export async function mockInfuraAndAccountSync( ): Promise { const accounts = options.accountsToMockBalances ?? []; - // Set up User Storage / Account Sync mock - userStorageMockttpController.setupPath( - USER_STORAGE_WALLETS_FEATURE_KEY, - mockServer, - ); - - userStorageMockttpController.setupPath( - USER_STORAGE_GROUPS_FEATURE_KEY, - mockServer, - ); - // Account Balances if (accounts.length > 0) { accounts.forEach((account) => { @@ -195,7 +160,7 @@ export async function mockInfuraAndAccountSync( }); } - mockIdentityServices(mockServer, userStorageMockttpController); + await mockIdentityServices(mockServer, userStorageMockttpController); } /**