From 8dc6bf1111161772939c7b439cb4ff127736f910 Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Tue, 30 May 2023 13:44:56 +0100 Subject: [PATCH] feature(17901): fix address-book `Sends to an address book entry` e2e against MV3 build (#19330) * feature(17901): fix address-book `Sends to an address book entry` e2e against MV3 build * feature(17901): add balance guide for send-eth e2e as well --------- Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com> --- test/e2e/helpers.js | 20 +++++++++++++++++++ test/e2e/tests/address-book.spec.js | 10 ++++++++-- test/e2e/tests/contract-interactions.spec.js | 15 +++++++------- test/e2e/tests/metamask-responsive-ui.spec.js | 7 ++----- test/e2e/tests/navigate-transactions.spec.js | 13 ++++++------ test/e2e/tests/onboarding.spec.js | 7 ++----- test/e2e/tests/send-eth.spec.js | 11 ++++++++-- test/e2e/tests/send-hex-address.spec.js | 19 ++++++++---------- test/e2e/tests/simple-send.spec.js | 5 ++++- 9 files changed, 67 insertions(+), 40 deletions(-) diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index aaa2d8b16..ed062a98e 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -511,6 +511,24 @@ const TEST_SEED_PHRASE = const TEST_SEED_PHRASE_TWO = 'phrase upgrade clock rough situate wedding elder clever doctor stamp excess tent'; +// Usually happens when onboarded to make sure the state is retrieved from metamaskState properly +const assertAccountBalanceForDOM = async (driver, ganacheServer) => { + const balance = await ganacheServer.getBalance(); + const balanceElement = await driver.findElement( + '[data-testid="eth-overview__primary-currency"]', + ); + assert.equal(`${balance}\nETH`, await balanceElement.getText()); +}; + +// Usually happens after txn is made +const locateAccountBalanceDOM = async (driver, ganacheServer) => { + const balance = await ganacheServer.getBalance(); + await driver.waitForSelector({ + css: '[data-testid="eth-overview__primary-currency"]', + text: `${balance} ETH`, + }); +}; + module.exports = { DAPP_URL, DAPP_ONE_URL, @@ -537,4 +555,6 @@ module.exports = { defaultGanacheOptions, sendTransaction, findAnotherAccountFromAccountList, + assertAccountBalanceForDOM, + locateAccountBalanceDOM, }; diff --git a/test/e2e/tests/address-book.spec.js b/test/e2e/tests/address-book.spec.js index af1214521..b1c40f409 100644 --- a/test/e2e/tests/address-book.spec.js +++ b/test/e2e/tests/address-book.spec.js @@ -1,5 +1,9 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + assertAccountBalanceForDOM, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Address Book', function () { @@ -12,6 +16,7 @@ describe('Address Book', function () { }, ], }; + it('Sends to an address book entry', async function () { await withFixtures( { @@ -33,11 +38,12 @@ describe('Address Book', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); + await assertAccountBalanceForDOM(driver, ganacheServer); await driver.clickElement('[data-testid="eth-overview-send"]'); const recipientRowTitle = await driver.findElement( '.send__select-recipient-wrapper__group-item__title', diff --git a/test/e2e/tests/contract-interactions.spec.js b/test/e2e/tests/contract-interactions.spec.js index 780b21c5f..02e95d7bd 100644 --- a/test/e2e/tests/contract-interactions.spec.js +++ b/test/e2e/tests/contract-interactions.spec.js @@ -1,5 +1,9 @@ -const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + locateAccountBalanceDOM, +} = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -89,12 +93,7 @@ describe('Deploy contract and call contract methods', function () { // renders the correct ETH balance await driver.switchToWindow(extension); - const balance = await ganacheServer.getBalance(); - const balanceElement = await driver.waitForSelector({ - css: '[data-testid="eth-overview__primary-currency"]', - text: balance, - }); - assert.equal(`${balance}\nETH`, await balanceElement.getText()); + await locateAccountBalanceDOM(driver, ganacheServer); }, ); }); diff --git a/test/e2e/tests/metamask-responsive-ui.spec.js b/test/e2e/tests/metamask-responsive-ui.spec.js index fe2ae4c1a..5d69b8c7c 100644 --- a/test/e2e/tests/metamask-responsive-ui.spec.js +++ b/test/e2e/tests/metamask-responsive-ui.spec.js @@ -3,6 +3,7 @@ const { TEST_SEED_PHRASE_TWO, convertToHexValue, withFixtures, + assertAccountBalanceForDOM, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -108,11 +109,7 @@ describe('MetaMask Responsive UI', function () { await driver.press('#confirm-password', driver.Key.ENTER); // balance renders - const balance = await ganacheServer.getBalance(); - await driver.waitForSelector({ - css: '[data-testid="eth-overview__primary-currency"]', - text: `${balance} ETH`, - }); + await assertAccountBalanceForDOM(driver, ganacheServer); }, ); }); diff --git a/test/e2e/tests/navigate-transactions.spec.js b/test/e2e/tests/navigate-transactions.spec.js index 438ef5028..507071f4a 100644 --- a/test/e2e/tests/navigate-transactions.spec.js +++ b/test/e2e/tests/navigate-transactions.spec.js @@ -1,5 +1,10 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + locateAccountBalanceDOM, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Navigate transactions', function () { @@ -227,11 +232,7 @@ describe('Navigate transactions', function () { // reject transactions await driver.clickElement({ text: 'Reject 4', tag: 'a' }); await driver.clickElement({ text: 'Reject all', tag: 'button' }); - const balance = await ganacheServer.getBalance(); - const balanceElement = await driver.findElement( - '[data-testid="eth-overview__primary-currency"]', - ); - assert.equal(`${balance}\nETH`, await balanceElement.getText()); + await locateAccountBalanceDOM(driver, ganacheServer); }, ); }); diff --git a/test/e2e/tests/onboarding.spec.js b/test/e2e/tests/onboarding.spec.js index a585d4896..e00b96a61 100644 --- a/test/e2e/tests/onboarding.spec.js +++ b/test/e2e/tests/onboarding.spec.js @@ -9,6 +9,7 @@ const { importSRPOnboardingFlow, importWrongSRPOnboardingFlow, testSRPDropdownIterations, + assertAccountBalanceForDOM, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -304,11 +305,7 @@ describe('MetaMask onboarding', function () { ); assert.equal(await networkDisplay.getText(), networkName); - const balance = await secondaryGanacheServer.getBalance(); - const balanceElement = await driver.findElement( - '[data-testid="eth-overview__primary-currency"]', - ); - assert.equal(`${balance}\nETH`, await balanceElement.getText()); + await assertAccountBalanceForDOM(driver, secondaryGanacheServer); }, ); }); diff --git a/test/e2e/tests/send-eth.spec.js b/test/e2e/tests/send-eth.spec.js index dd2ae8650..7869e52cb 100644 --- a/test/e2e/tests/send-eth.spec.js +++ b/test/e2e/tests/send-eth.spec.js @@ -1,6 +1,11 @@ const { strict: assert } = require('assert'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); -const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + assertAccountBalanceForDOM, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Send ETH from inside MetaMask using default gas', function () { @@ -20,11 +25,13 @@ describe('Send ETH from inside MetaMask using default gas', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); + await assertAccountBalanceForDOM(driver, ganacheServer); + await driver.clickElement('[data-testid="eth-overview-send"]'); await driver.fill( diff --git a/test/e2e/tests/send-hex-address.spec.js b/test/e2e/tests/send-hex-address.spec.js index c971f4f01..b1d8edfad 100644 --- a/test/e2e/tests/send-hex-address.spec.js +++ b/test/e2e/tests/send-hex-address.spec.js @@ -1,5 +1,9 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + assertAccountBalanceForDOM, +} = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -133,11 +137,7 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - const balanceAfterDeployment = await ganacheServer.getBalance(); - await driver.waitForSelector({ - css: '[data-testid="eth-overview__primary-currency"]', - text: `${balanceAfterDeployment} ETH`, - }); + await assertAccountBalanceForDOM(driver, ganacheServer); // Send TST await driver.clickElement('[data-testid="home__asset-tab"]'); @@ -198,11 +198,8 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - const balanceAfterDeployment = await ganacheServer.getBalance(); - await driver.waitForSelector({ - css: '[data-testid="eth-overview__primary-currency"]', - text: `${balanceAfterDeployment} ETH`, - }); + + await assertAccountBalanceForDOM(driver, ganacheServer); // Send TST await driver.clickElement('[data-testid="home__asset-tab"]'); diff --git a/test/e2e/tests/simple-send.spec.js b/test/e2e/tests/simple-send.spec.js index b5b083ed8..9e6293b74 100644 --- a/test/e2e/tests/simple-send.spec.js +++ b/test/e2e/tests/simple-send.spec.js @@ -2,6 +2,7 @@ const { convertToHexValue, withFixtures, sendTransaction, + assertAccountBalanceForDOM, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -22,10 +23,12 @@ describe('Simple send', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); + await assertAccountBalanceForDOM(driver, ganacheServer); + await sendTransaction( driver, '0x985c30949c92df7a0bd42e0f3e3d539ece98db24',