diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 53f1c9deaeda..000f8a3c26f6 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -697,45 +697,6 @@ const completeCreateNewWalletOnboardingFlow = async (driver, password) => { await onboardingPinExtension(driver); }; -const importWrongSRPOnboardingFlow = async (driver, seedPhrase) => { - // agree to terms of use - await driver.clickElement('[data-testid="onboarding-terms-checkbox"]'); - - // welcome - await driver.clickElement('[data-testid="onboarding-import-wallet"]'); - - // metrics - await driver.clickElement('[data-testid="metametrics-no-thanks"]'); - - // import with recovery phrase - await driver.pasteIntoField( - '[data-testid="import-srp__srp-word-0"]', - seedPhrase, - ); - - const warningText = 'Invalid Secret Recovery Phrase'; - const warnings = await driver.findElements('.import-srp__banner-alert-text'); - const warning = warnings[1]; - - assert.equal(await warning.getText(), warningText); -}; - -const selectDropdownByNum = async (elements, index) => { - await elements[index].click(); -}; - -const testSRPDropdownIterations = async (options, driver, iterations) => { - for (let i = 0; i < iterations; i++) { - await selectDropdownByNum(options, i); - await new Promise((resolve) => setTimeout(resolve, 1000)); - - const formFields = await driver.findElements('.import-srp__srp-word-label'); - const expectedNumFields = 12 + i * 3; - const actualNumFields = formFields.length; - assert.equal(actualNumFields, expectedNumFields); - } -}; - const openSRPRevealQuiz = async (driver) => { // navigate settings to reveal SRP await driver.clickElement('[data-testid="account-options-menu-button"]'); @@ -1358,8 +1319,6 @@ module.exports = { closeSRPReveal, tapAndHoldToRevealSRP, createDownloadFolder, - importWrongSRPOnboardingFlow, - testSRPDropdownIterations, openDapp, openDappConnectionsPage, createDappTransaction, diff --git a/test/e2e/page-objects/flows/network.flow.ts b/test/e2e/page-objects/flows/network.flow.ts new file mode 100644 index 000000000000..fc77db8895bd --- /dev/null +++ b/test/e2e/page-objects/flows/network.flow.ts @@ -0,0 +1,60 @@ +import { Driver } from '../../webdriver/driver'; +import HeaderNavbar from '../pages/header-navbar'; +import SelectNetwork from '../pages/dialog/select-network'; +import NetworkSwitchModalConfirmation from '../pages/dialog/network-switch-modal-confirmation'; + +/** + * Switches to a specified network in the header bar. + * + * @param driver + * @param networkName - The name of the network to switch to. + * @param toggleShowTestNetwork - A boolean indicating whether to toggle the display of test networks. Defaults to false. + */ +export const switchToNetworkFlow = async ( + driver: Driver, + networkName: string, + toggleShowTestNetwork: boolean = false, +) => { + console.log(`Switch to network ${networkName} in header bar`); + const headerNavbar = new HeaderNavbar(driver); + await headerNavbar.check_pageIsLoaded(); + await headerNavbar.clickSwitchNetworkDropDown(); + + const selectNetworkDialog = new SelectNetwork(driver); + await selectNetworkDialog.check_pageIsLoaded(); + if (toggleShowTestNetwork) { + await selectNetworkDialog.toggleShowTestNetwork(); + } + await selectNetworkDialog.selectNetworkName(networkName); + await headerNavbar.check_currentSelectedNetwork(networkName); +}; + +/** + * Search for a network in the select network dialog and switches to it. + * + * @param driver + * @param networkName - The name of the network to search for and switch to. + */ +export const searchAndSwitchToNetworkFlow = async ( + driver: Driver, + networkName: string, +) => { + console.log( + `Search in select network dialog and switch to network ${networkName}`, + ); + const headerNavbar = new HeaderNavbar(driver); + await headerNavbar.check_pageIsLoaded(); + await headerNavbar.clickSwitchNetworkDropDown(); + + const selectNetworkDialog = new SelectNetwork(driver); + await selectNetworkDialog.check_pageIsLoaded(); + await selectNetworkDialog.fillNetworkSearchInput(networkName); + await selectNetworkDialog.clickAddButton(); + + const networkSwitchModalConfirmation = new NetworkSwitchModalConfirmation( + driver, + ); + await networkSwitchModalConfirmation.check_pageIsLoaded(); + await networkSwitchModalConfirmation.clickApproveButton(); + await headerNavbar.check_currentSelectedNetwork(networkName); +}; diff --git a/test/e2e/page-objects/flows/onboarding.flow.ts b/test/e2e/page-objects/flows/onboarding.flow.ts index 70a4f7df82f2..b5fda9e0c276 100644 --- a/test/e2e/page-objects/flows/onboarding.flow.ts +++ b/test/e2e/page-objects/flows/onboarding.flow.ts @@ -6,48 +6,52 @@ import StartOnboardingPage from '../pages/onboarding/start-onboarding-page'; import SecureWalletPage from '../pages/onboarding/secure-wallet-page'; import OnboardingCompletePage from '../pages/onboarding/onboarding-complete-page'; -export const importSRPOnboardingFlow = async (driver: Driver) => { - console.log('start import srp onboarding flow '); +export const createNewWalletOnboardingFlow = async (driver: Driver) => { + console.log('Starting the creation of a new wallet onboarding flow'); await driver.navigate(); const startOnboardingPage = new StartOnboardingPage(driver); await startOnboardingPage.check_pageIsLoaded(); await startOnboardingPage.checkTermsCheckbox(); - await startOnboardingPage.clickImportWalletButton(); + await startOnboardingPage.clickCreateWalletButton(); const onboardingMetricsPage = new OnboardingMetricsPage(driver); await onboardingMetricsPage.check_pageIsLoaded(); await onboardingMetricsPage.clickNoThanksButton(); - const onboardingSrpPage = new OnboardingSrpPage(driver); - await onboardingSrpPage.check_pageIsLoaded(); - await onboardingSrpPage.fillSrp(); - await onboardingSrpPage.clickConfirmButton(); - const onboardingPasswordPage = new OnboardingPasswordPage(driver); await onboardingPasswordPage.check_pageIsLoaded(); - await onboardingPasswordPage.createImportedWalletPassword(); + await onboardingPasswordPage.createWalletPassword(); + + const secureWalletPage = new SecureWalletPage(driver); + await secureWalletPage.check_pageIsLoaded(); + await secureWalletPage.revealAndConfirmSRP(); }; -export const completeCreateNewWalletOnboardingFlow = async (driver: Driver) => { - console.log('start to complete create new wallet onboarding flow '); +export const importSRPOnboardingFlow = async (driver: Driver) => { + console.log('Starting the import of SRP onboarding flow'); await driver.navigate(); const startOnboardingPage = new StartOnboardingPage(driver); await startOnboardingPage.check_pageIsLoaded(); await startOnboardingPage.checkTermsCheckbox(); - await startOnboardingPage.clickCreateWalletButton(); + await startOnboardingPage.clickImportWalletButton(); const onboardingMetricsPage = new OnboardingMetricsPage(driver); await onboardingMetricsPage.check_pageIsLoaded(); await onboardingMetricsPage.clickNoThanksButton(); + const onboardingSrpPage = new OnboardingSrpPage(driver); + await onboardingSrpPage.check_pageIsLoaded(); + await onboardingSrpPage.fillSrp(); + await onboardingSrpPage.clickConfirmButton(); + const onboardingPasswordPage = new OnboardingPasswordPage(driver); await onboardingPasswordPage.check_pageIsLoaded(); - await onboardingPasswordPage.createWalletPassword(); - - const secureWalletPage = new SecureWalletPage(driver); - await secureWalletPage.check_pageIsLoaded(); - await secureWalletPage.revealAndConfirmSRP(); + await onboardingPasswordPage.createImportedWalletPassword(); +}; +export const completeCreateNewWalletOnboardingFlow = async (driver: Driver) => { + console.log('start to complete create new wallet onboarding flow '); + await createNewWalletOnboardingFlow(driver); const onboardingCompletePage = new OnboardingCompletePage(driver); await onboardingCompletePage.check_pageIsLoaded(); await onboardingCompletePage.check_congratulationsMessageIsDisplayed(); diff --git a/test/e2e/page-objects/pages/dialog/network-switch-modal-confirmation.ts b/test/e2e/page-objects/pages/dialog/network-switch-modal-confirmation.ts index a12aa0804771..8a51194605f7 100644 --- a/test/e2e/page-objects/pages/dialog/network-switch-modal-confirmation.ts +++ b/test/e2e/page-objects/pages/dialog/network-switch-modal-confirmation.ts @@ -1,13 +1,33 @@ import { Driver } from '../../../webdriver/driver'; -class networkSwitchModalConfirmation { +class NetworkSwitchModalConfirmation { private driver: Driver; - private submitButton: string; + private readonly submitButton = '[data-testid="confirmation-submit-button"]'; + + private readonly addNetworkMessage = { + text: 'Want to add this network?', + tag: 'h3', + }; constructor(driver: Driver) { this.driver = driver; - this.submitButton = '[data-testid="confirmation-submit-button"]'; + } + + async check_pageIsLoaded(): Promise { + try { + await this.driver.waitForMultipleSelectors([ + this.addNetworkMessage, + this.submitButton, + ]); + } catch (e) { + console.log( + 'Timeout while waiting for add network confirmation modal to be loaded', + e, + ); + throw e; + } + console.log('Add network confirmation modal is loaded'); } async clickApproveButton(): Promise { @@ -16,4 +36,4 @@ class networkSwitchModalConfirmation { } } -export default networkSwitchModalConfirmation; +export default NetworkSwitchModalConfirmation; diff --git a/test/e2e/page-objects/pages/dialog/select-network.ts b/test/e2e/page-objects/pages/dialog/select-network.ts index 6e71e5d311d5..2c399a4118d8 100644 --- a/test/e2e/page-objects/pages/dialog/select-network.ts +++ b/test/e2e/page-objects/pages/dialog/select-network.ts @@ -5,29 +5,47 @@ class SelectNetwork { private networkName: string | undefined; - private addNetworkButton: object; + private readonly addNetworkButton = { + tag: 'button', + text: 'Add a custom network', + }; - private closeButton: string; + private readonly closeButton = 'button[aria-label="Close"]'; - private toggleButton: string; + private readonly searchInput = + '[data-testid="network-redesign-modal-search-input"]'; - private searchInput: string; + private readonly selectNetworkMessage = { + text: 'Select a network', + tag: 'h4', + }; + + private readonly toggleButton = '.toggle-button > div'; constructor(driver: Driver) { this.driver = driver; - this.addNetworkButton = { - tag: 'button', - text: 'Add a custom network', - }; - this.closeButton = 'button[aria-label="Close"]'; - this.toggleButton = '.toggle-button > div'; - this.searchInput = '[data-testid="network-redesign-modal-search-input"]'; } - async clickNetworkName(networkName: string): Promise { + async check_pageIsLoaded(): Promise { + try { + await this.driver.waitForMultipleSelectors([ + this.selectNetworkMessage, + this.searchInput, + ]); + } catch (e) { + console.log( + 'Timeout while waiting for select network dialog to be loaded', + e, + ); + throw e; + } + console.log('Select network dialog is loaded'); + } + + async selectNetworkName(networkName: string): Promise { console.log(`Click ${networkName}`); this.networkName = `[data-testid="${networkName}"]`; - await this.driver.clickElement(this.networkName); + await this.driver.clickElementAndWaitToDisappear(this.networkName); } async addNewNetwork(): Promise { @@ -40,8 +58,8 @@ class SelectNetwork { await this.driver.clickElementAndWaitToDisappear(this.closeButton); } - async clickToggleButton(): Promise { - console.log('Click Toggle Button'); + async toggleShowTestNetwork(): Promise { + console.log('Toggle show test network in select network dialog'); await this.driver.clickElement(this.toggleButton); } diff --git a/test/e2e/page-objects/pages/header-navbar.ts b/test/e2e/page-objects/pages/header-navbar.ts index 10127350a796..100c23b851e4 100644 --- a/test/e2e/page-objects/pages/header-navbar.ts +++ b/test/e2e/page-objects/pages/header-navbar.ts @@ -5,7 +5,7 @@ class HeaderNavbar { private readonly accountMenuButton = '[data-testid="account-menu-icon"]'; - private readonly accountOptionMenu = + private readonly threeDotMenuButton = '[data-testid="account-options-menu-button"]'; private readonly accountSnapButton = { text: 'Snaps', tag: 'div' }; @@ -15,11 +15,6 @@ class HeaderNavbar { private readonly mmiPortfolioButton = '[data-testid="global-menu-mmi-portfolio"]'; - private readonly selectNetworkMessage = { - text: 'Select a network', - tag: 'h4', - }; - private readonly settingsButton = '[data-testid="global-menu-settings"]'; private readonly switchNetworkDropDown = '[data-testid="network-display"]'; @@ -32,7 +27,7 @@ class HeaderNavbar { try { await this.driver.waitForMultipleSelectors([ this.accountMenuButton, - this.accountOptionMenu, + this.threeDotMenuButton, ]); } catch (e) { console.log('Timeout while waiting for header navbar to be loaded', e); @@ -42,11 +37,7 @@ class HeaderNavbar { } async lockMetaMask(): Promise { - await this.driver.clickElement(this.accountOptionMenu); - // fix race condition with mmi build - if (process.env.MMI) { - await this.driver.waitForSelector(this.mmiPortfolioButton); - } + await this.openThreeDotMenu(); await this.driver.clickElement(this.lockMetaMaskButton); } @@ -54,19 +45,24 @@ class HeaderNavbar { await this.driver.clickElement(this.accountMenuButton); } + async openThreeDotMenu(): Promise { + console.log('Open account options menu'); + await this.driver.clickElement(this.threeDotMenuButton); + // fix race condition with mmi build + if (process.env.MMI) { + await this.driver.waitForSelector(this.mmiPortfolioButton); + } + } + async openSnapListPage(): Promise { console.log('Open account snap page'); - await this.driver.clickElement(this.accountOptionMenu); + await this.openThreeDotMenu(); await this.driver.clickElement(this.accountSnapButton); } async openSettingsPage(): Promise { console.log('Open settings page'); - await this.driver.clickElement(this.accountOptionMenu); - // fix race condition with mmi build - if (process.env.MMI) { - await this.driver.waitForSelector(this.mmiPortfolioButton); - } + await this.openThreeDotMenu(); await this.driver.clickElement(this.settingsButton); } @@ -82,28 +78,6 @@ class HeaderNavbar { ); } - /** - * Switches to the specified network. - * - * @param networkName - The name of the network to switch to. - */ - async switchToNetwork(networkName: string): Promise { - console.log(`Switch to network ${networkName} in header bar`); - await this.driver.clickElement(this.switchNetworkDropDown); - await this.driver.waitForSelector(this.selectNetworkMessage); - await this.driver.clickElementAndWaitToDisappear( - `[data-testid="${networkName}"]`, - ); - // check the toaster message is displayed and the network is correctly selected - await this.driver.waitForSelector({ - tag: 'h6', - text: `“${networkName}” was successfully added!`, - }); - await this.driver.waitForSelector( - `${this.switchNetworkDropDown}[aria-label="Network Menu ${networkName}"]`, - ); - } - /** * Verifies that the displayed account label in header matches the expected label. * diff --git a/test/e2e/page-objects/pages/homepage.ts b/test/e2e/page-objects/pages/homepage.ts index 7d1f519bb640..7c322b0f2cbb 100644 --- a/test/e2e/page-objects/pages/homepage.ts +++ b/test/e2e/page-objects/pages/homepage.ts @@ -85,6 +85,21 @@ class HomePage { await this.driver.clickElement(this.nftIconOnActivityList); } + /** + * Checks if the toaster message for adding a network is displayed on the homepage. + * + * @param networkName - The name of the network that was added. + */ + async check_addNetworkMessageIsDisplayed(networkName: string): Promise { + console.log( + `Check the toaster message for adding network ${networkName} is displayed on homepage`, + ); + await this.driver.waitForSelector({ + tag: 'h6', + text: `“${networkName}” was successfully added!`, + }); + } + /** * This function checks if the specified number of confirmed transactions are displayed in the activity list on homepage. * It waits up to 10 seconds for the expected number of confirmed transactions to be visible. diff --git a/test/e2e/tests/account/snap-account-signatures.spec.ts b/test/e2e/tests/account/snap-account-signatures.spec.ts index 98cfe9b18337..0c528b1dc20c 100644 --- a/test/e2e/tests/account/snap-account-signatures.spec.ts +++ b/test/e2e/tests/account/snap-account-signatures.spec.ts @@ -18,7 +18,7 @@ import SnapSimpleKeyringPage from '../../page-objects/pages/snap-simple-keyring- import TestDapp from '../../page-objects/pages/test-dapp'; describe('Snap Account Signatures @no-mmi', function (this: Suite) { - this.timeout(150000); // This test is very long, so we need an unusually high timeout + this.timeout(200000); // This test is very long, so we need an unusually high timeout // Run sync, async approve, and async reject flows // (in Jest we could do this with test.each, but that does not exist here) diff --git a/test/e2e/tests/network/switch-network.spec.ts b/test/e2e/tests/network/switch-network.spec.ts index b684a4a8ef1e..a45e634dbbec 100644 --- a/test/e2e/tests/network/switch-network.spec.ts +++ b/test/e2e/tests/network/switch-network.spec.ts @@ -5,9 +5,11 @@ import FixtureBuilder from '../../fixture-builder'; import { Ganache } from '../../seeder/ganache'; import { loginWithBalanceValidation } from '../../page-objects/flows/login.flow'; import HomePage from '../../page-objects/pages/homepage'; -import ModalConfirmation from '../../page-objects/pages/dialog/network-switch-modal-confirmation'; import HeaderNavbar from '../../page-objects/pages/header-navbar'; -import SelectNetwork from '../../page-objects/pages/dialog/select-network'; +import { + switchToNetworkFlow, + searchAndSwitchToNetworkFlow, +} from '../../page-objects/flows/network.flow'; describe('Switch network - ', function (this: Suite) { it('Switch networks to existing and new networks', async function () { @@ -26,40 +28,27 @@ describe('Switch network - ', function (this: Suite) { }) => { await loginWithBalanceValidation(driver, ganacheServer); const homePage = new HomePage(driver); - const headerNavbar = new HeaderNavbar(driver); - const selectNetwork = new SelectNetwork(driver); - const networkSwitchConfirmation = new ModalConfirmation(driver); // Validate the default network is Localhost 8545 - await headerNavbar.check_currentSelectedNetwork('Localhost 8545'); + await new HeaderNavbar(driver).check_currentSelectedNetwork( + 'Localhost 8545', + ); // Validate the switch network functionality to Ethereum Mainnet - await headerNavbar.clickSwitchNetworkDropDown(); - await selectNetwork.clickNetworkName('Ethereum Mainnet'); - await homePage.check_expectedBalanceIsDisplayed('25'); - await headerNavbar.check_currentSelectedNetwork('Ethereum Mainnet'); + await switchToNetworkFlow(driver, 'Ethereum Mainnet'); + await homePage.check_ganacheBalanceIsDisplayed(ganacheServer); + // Validate the switch network functionality to test network - await headerNavbar.clickSwitchNetworkDropDown(); - await selectNetwork.clickToggleButton(); - await selectNetwork.clickNetworkName('Localhost 8545'); - await homePage.check_expectedBalanceIsDisplayed('25'); - await headerNavbar.check_currentSelectedNetwork('Localhost 8545'); + await switchToNetworkFlow(driver, 'Localhost 8545', true); + await homePage.check_ganacheBalanceIsDisplayed(ganacheServer); // Add Arbitrum network and perform the switch network functionality - await headerNavbar.clickSwitchNetworkDropDown(); - await selectNetwork.fillNetworkSearchInput('Arbitrum One'); - await selectNetwork.clickAddButton(); - await networkSwitchConfirmation.clickApproveButton(); - await headerNavbar.clickSwitchNetworkDropDown(); - await selectNetwork.clickNetworkName('Arbitrum One'); - await homePage.check_expectedBalanceIsDisplayed('25'); - await headerNavbar.check_currentSelectedNetwork('Arbitrum One'); + await searchAndSwitchToNetworkFlow(driver, 'Arbitrum One'); + await homePage.check_ganacheBalanceIsDisplayed(ganacheServer); // Validate the switch network functionality back to Ethereum Mainnet - await headerNavbar.clickSwitchNetworkDropDown(); - await selectNetwork.clickNetworkName('Ethereum Mainnet'); - await homePage.check_expectedBalanceIsDisplayed('25'); - await headerNavbar.check_currentSelectedNetwork('Ethereum Mainnet'); + await switchToNetworkFlow(driver, 'Ethereum Mainnet'); + await homePage.check_ganacheBalanceIsDisplayed(ganacheServer); }, ); }); diff --git a/test/e2e/tests/onboarding/onboarding.spec.ts b/test/e2e/tests/onboarding/onboarding.spec.ts index 1af2d5170841..aa04ca151f86 100644 --- a/test/e2e/tests/onboarding/onboarding.spec.ts +++ b/test/e2e/tests/onboarding/onboarding.spec.ts @@ -20,6 +20,7 @@ import { completeImportSRPOnboardingFlow, importSRPOnboardingFlow, } from '../../page-objects/flows/onboarding.flow'; +import { switchToNetworkFlow } from '../../page-objects/flows/network.flow'; describe('MetaMask onboarding @no-mmi', function () { const ganacheOptions2 = { @@ -186,7 +187,8 @@ describe('MetaMask onboarding @no-mmi', function () { const homePage = new HomePage(driver); await homePage.check_pageIsLoaded(); - await homePage.headerNavbar.switchToNetwork(networkName); + await switchToNetworkFlow(driver, networkName); + await homePage.check_addNetworkMessageIsDisplayed(networkName); // Check the correct balance for the custom network is displayed if (secondaryGanacheServer && Array.isArray(secondaryGanacheServer)) { diff --git a/test/e2e/tests/privacy/account-tracker-api-usage.spec.ts b/test/e2e/tests/privacy/account-tracker-api-usage.spec.ts index f0cd40cb7373..24f2318fa13b 100644 --- a/test/e2e/tests/privacy/account-tracker-api-usage.spec.ts +++ b/test/e2e/tests/privacy/account-tracker-api-usage.spec.ts @@ -4,11 +4,12 @@ import { MockedEndpoint } from 'mockttp'; import FixtureBuilder from '../../fixture-builder'; import { defaultGanacheOptions, - unlockWallet, veryLargeDelayMs, withFixtures, } from '../../helpers'; import { Mockttp } from '../../mock-e2e'; +import HomePage from '../../page-objects/pages/homepage'; +import { loginWithoutBalanceValidation } from '../../page-objects/flows/login.flow'; async function mockInfura(mockServer: Mockttp): Promise { const blockNumber = { value: 0 }; @@ -122,7 +123,9 @@ describe('Account Tracker API Usage', function () { )} request has been made to infura before opening the UI`, ); - await unlockWallet(driver); + await loginWithoutBalanceValidation(driver); + const homepage = new HomePage(driver); + await homepage.check_pageIsLoaded(); await driver.delay(veryLargeDelayMs); allInfuraJsonRpcRequests = await getAllInfuraJsonRpcRequests( @@ -158,7 +161,9 @@ describe('Account Tracker API Usage', function () { testSpecificMock: mockInfura, }, async ({ driver, mockedEndpoint }) => { - await unlockWallet(driver); + await loginWithoutBalanceValidation(driver); + const homepage = new HomePage(driver); + await homepage.check_pageIsLoaded(); await driver.delay(veryLargeDelayMs); const initialInfuraJsonRpcRequests = await getAllInfuraJsonRpcRequests( mockedEndpoint, diff --git a/test/e2e/tests/privacy/onboarding-infura-call-privacy.spec.ts b/test/e2e/tests/privacy/onboarding-infura-call-privacy.spec.ts new file mode 100644 index 000000000000..b18d713d9474 --- /dev/null +++ b/test/e2e/tests/privacy/onboarding-infura-call-privacy.spec.ts @@ -0,0 +1,188 @@ +import assert from 'assert'; +import { Mockttp, MockedEndpoint } from 'mockttp'; +import { withFixtures, regularDelayMs } from '../../helpers'; +import FixtureBuilder from '../../fixture-builder'; +import HomePage from '../../page-objects/pages/homepage'; +import OnboardingCompletePage from '../../page-objects/pages/onboarding/onboarding-complete-page'; +import { + importSRPOnboardingFlow, + createNewWalletOnboardingFlow, +} from '../../page-objects/flows/onboarding.flow'; + +// Mock function implementation for Infura requests +async function mockInfura(mockServer: Mockttp): Promise { + const infuraUrl = + 'https://mainnet.infura.io/v3/00000000000000000000000000000000'; + const sampleAddress = '1111111111111111111111111111111111111111'; + return [ + await mockServer + .forPost(infuraUrl) + .withJsonBodyIncluding({ method: 'eth_blockNumber' }) + .thenCallback(() => { + return { + statusCode: 200, + json: { + jsonrpc: '2.0', + id: '1111111111111111', + result: '0x1', + }, + }; + }), + await mockServer + .forPost(infuraUrl) + .withJsonBodyIncluding({ method: 'eth_getBalance' }) + .thenCallback(() => { + return { + statusCode: 200, + json: { + jsonrpc: '2.0', + id: '1111111111111111', + result: '0x0', + }, + }; + }), + await mockServer + .forPost(infuraUrl) + .withJsonBodyIncluding({ method: 'eth_getBlockByNumber' }) + .thenCallback(() => { + return { + statusCode: 200, + json: { + jsonrpc: '2.0', + id: '1111111111111111', + result: {}, + }, + }; + }), + await mockServer + .forPost(infuraUrl) + .withJsonBodyIncluding({ method: 'eth_call' }) + .thenCallback(() => { + return { + statusCode: 200, + json: { + jsonrpc: '2.0', + id: '1111111111111111', + result: `0x000000000000000000000000${sampleAddress}`, + }, + }; + }), + await mockServer + .forPost(infuraUrl) + .withJsonBodyIncluding({ method: 'net_version' }) + .thenCallback(() => { + return { + statusCode: 200, + json: { id: 8262367391254633, jsonrpc: '2.0', result: '1337' }, + }; + }), + ]; +} + +describe('MetaMask onboarding @no-mmi', function () { + it("doesn't make any network requests to infura before create new wallet onboarding is completed", async function () { + await withFixtures( + { + fixtures: new FixtureBuilder({ onboarding: true }) + .withNetworkControllerOnMainnet() + .build(), + title: this.test?.fullTitle(), + testSpecificMock: mockInfura, + }, + async ({ driver, mockedEndpoint: mockedEndpoints }) => { + await createNewWalletOnboardingFlow(driver); + + // Check no requests are made before completing creat new wallet onboarding + // Intended delay to ensure we cover at least 1 polling loop of time for the network request + await driver.delay(regularDelayMs); + for (const mockedEndpoint of mockedEndpoints) { + const isPending = await mockedEndpoint.isPending(); + assert.equal( + isPending, + true, + `${mockedEndpoint} mock should still be pending before onboarding`, + ); + const requests = await mockedEndpoint.getSeenRequests(); + assert.equal( + requests.length, + 0, + `${mockedEndpoint} should make no requests before onboarding`, + ); + } + + // complete create new wallet onboarding + const onboardingCompletePage = new OnboardingCompletePage(driver); + await onboardingCompletePage.check_pageIsLoaded(); + await onboardingCompletePage.completeOnboarding(); + const homePage = new HomePage(driver); + await homePage.check_pageIsLoaded(); + await homePage.check_expectedBalanceIsDisplayed(); + + // network requests happen here + for (const mockedEndpoint of mockedEndpoints) { + await driver.wait(async () => { + const isPending = await mockedEndpoint.isPending(); + return isPending === false; + }, driver.timeout); + + const requests = await mockedEndpoint.getSeenRequests(); + assert.equal( + requests.length > 0, + true, + `${mockedEndpoint} should make requests after onboarding`, + ); + } + }, + ); + }); + + it("doesn't make any network requests to infura before onboarding by import is completed", async function () { + await withFixtures( + { + fixtures: new FixtureBuilder({ onboarding: true }) + .withNetworkControllerOnMainnet() + .build(), + title: this.test?.fullTitle(), + testSpecificMock: mockInfura, + }, + async ({ driver, mockedEndpoint: mockedEndpoints }) => { + await importSRPOnboardingFlow(driver); + + // Check no requests before completing onboarding + // Intended delay to ensure we cover at least 1 polling loop of time for the network request + await driver.delay(regularDelayMs); + for (const mockedEndpoint of mockedEndpoints) { + const requests = await mockedEndpoint.getSeenRequests(); + assert.equal( + requests.length, + 0, + `${mockedEndpoint} should make no requests before import wallet onboarding complete`, + ); + } + + // complete import wallet onboarding + const onboardingCompletePage = new OnboardingCompletePage(driver); + await onboardingCompletePage.check_pageIsLoaded(); + await onboardingCompletePage.completeOnboarding(); + const homePage = new HomePage(driver); + await homePage.check_pageIsLoaded(); + await homePage.check_expectedBalanceIsDisplayed(); + + // requests happen here + for (const mockedEndpoint of mockedEndpoints) { + await driver.wait(async () => { + const isPending = await mockedEndpoint.isPending(); + return isPending === false; + }, driver.timeout); + + const requests = await mockedEndpoint.getSeenRequests(); + assert.equal( + requests.length > 0, + true, + `${mockedEndpoint} should make requests after onboarding`, + ); + } + }, + ); + }); +}); diff --git a/test/e2e/tests/privacy/onboarding-privacy.spec.js b/test/e2e/tests/privacy/onboarding-privacy.spec.js deleted file mode 100644 index 7febe8eb1a9f..000000000000 --- a/test/e2e/tests/privacy/onboarding-privacy.spec.js +++ /dev/null @@ -1,283 +0,0 @@ -const { strict: assert } = require('assert'); -const { - TEST_SEED_PHRASE, - withFixtures, - importSRPOnboardingFlow, - defaultGanacheOptions, - onboardingBeginCreateNewWallet, - onboardingChooseMetametricsOption, - onboardingCreatePassword, - onboardingRevealAndConfirmSRP, - onboardingCompleteWalletCreation, - regularDelayMs, -} = require('../../helpers'); -const FixtureBuilder = require('../../fixture-builder'); - -describe('MetaMask onboarding @no-mmi', function () { - it("doesn't make any network requests to infura before onboarding is completed", async function () { - async function mockInfura(mockServer) { - const infuraUrl = - 'https://mainnet.infura.io/v3/00000000000000000000000000000000'; - const sampleAddress = '1111111111111111111111111111111111111111'; - - return [ - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_blockNumber' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: '0x1', - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_getBalance' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: '0x0', - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_getBlockByNumber' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: {}, - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_call' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: `0x000000000000000000000000${sampleAddress}`, - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'net_version' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { id: 8262367391254633, jsonrpc: '2.0', result: '1337' }, - }; - }), - ]; - } - - await withFixtures( - { - fixtures: new FixtureBuilder({ onboarding: true }) - .withNetworkControllerOnMainnet() - .build(), - ganacheOptions: defaultGanacheOptions, - title: this.test.fullTitle(), - testSpecificMock: mockInfura, - }, - async ({ driver, mockedEndpoint: mockedEndpoints }) => { - const password = 'password'; - - await driver.navigate(); - - await onboardingBeginCreateNewWallet(driver); - await onboardingChooseMetametricsOption(driver, false); - await onboardingCreatePassword(driver, password); - await onboardingRevealAndConfirmSRP(driver); - await onboardingCompleteWalletCreation(driver); - - // pin extension walkthrough screen - await driver.clickElement('[data-testid="pin-extension-next"]'); - - await driver.delay(regularDelayMs); - - for (let i = 0; i < mockedEndpoints.length; i += 1) { - const mockedEndpoint = await mockedEndpoints[i]; - const isPending = await mockedEndpoint.isPending(); - assert.equal( - isPending, - true, - `${mockedEndpoints[i]} mock should still be pending before onboarding`, - ); - const requests = await mockedEndpoint.getSeenRequests(); - - assert.equal( - requests.length, - 0, - `${mockedEndpoints[i]} should make no requests before onboarding`, - ); - } - - await driver.clickElement('[data-testid="pin-extension-done"]'); - // requests happen here! - - for (let i = 0; i < mockedEndpoints.length; i += 1) { - const mockedEndpoint = await mockedEndpoints[i]; - - await driver.wait(async () => { - const isPending = await mockedEndpoint.isPending(); - return isPending === false; - }, driver.timeout); - - const requests = await mockedEndpoint.getSeenRequests(); - - assert.equal( - requests.length > 0, - true, - `${mockedEndpoints[i]} should make requests after onboarding`, - ); - } - }, - ); - }); - - it("doesn't make any network requests to infura before onboarding by import is completed", async function () { - async function mockInfura(mockServer) { - const infuraUrl = - 'https://mainnet.infura.io/v3/00000000000000000000000000000000'; - const sampleAddress = '1111111111111111111111111111111111111111'; - - return [ - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_blockNumber' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: '0x1', - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_getBalance' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: '0x0', - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_getBlockByNumber' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: {}, - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'eth_call' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { - jsonrpc: '2.0', - id: '1111111111111111', - result: `0x000000000000000000000000${sampleAddress}`, - }, - }; - }), - await mockServer - .forPost(infuraUrl) - .withJsonBodyIncluding({ method: 'net_version' }) - .thenCallback(() => { - return { - statusCode: 200, - json: { id: 8262367391254633, jsonrpc: '2.0', result: '1337' }, - }; - }), - ]; - } - - await withFixtures( - { - fixtures: new FixtureBuilder({ onboarding: true }) - .withNetworkControllerOnMainnet() - .build(), - ganacheOptions: defaultGanacheOptions, - title: this.test.fullTitle(), - testSpecificMock: mockInfura, - }, - async ({ driver, mockedEndpoint: mockedEndpoints }) => { - const password = 'password'; - - await driver.navigate(); - - await importSRPOnboardingFlow(driver, TEST_SEED_PHRASE, password); - - await driver.delay(regularDelayMs); - - for (let i = 0; i < mockedEndpoints.length; i += 1) { - const mockedEndpoint = await mockedEndpoints[i]; - const requests = await mockedEndpoint.getSeenRequests(); - - assert.equal( - requests.length, - 0, - `${mockedEndpoints[i]} should make no requests before onboarding`, - ); - } - - // complete - await driver.clickElement('[data-testid="onboarding-complete-done"]'); - - // pin extension - await driver.clickElement('[data-testid="pin-extension-next"]'); - await driver.clickElement('[data-testid="pin-extension-done"]'); - - // pin extension walkthrough screen - await driver.findElement('[data-testid="account-menu-icon"]'); - // requests happen here! - - for (let i = 0; i < mockedEndpoints.length; i += 1) { - const mockedEndpoint = await mockedEndpoints[i]; - - await driver.wait(async () => { - const isPending = await mockedEndpoint.isPending(); - return isPending === false; - }, driver.timeout); - - const requests = await mockedEndpoint.getSeenRequests(); - - assert.equal( - requests.length > 0, - true, - `${mockedEndpoints[i]} should make requests after onboarding`, - ); - } - }, - ); - }); -});