Skip to content

Commit

Permalink
feature(17901): fix address-book Sends to an address book entry e2e…
Browse files Browse the repository at this point in the history
… 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 <[email protected]>
  • Loading branch information
DDDDDanica and legobeat authored May 30, 2023
1 parent dfafdbb commit 8dc6bf1
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 40 deletions.
20 changes: 20 additions & 0 deletions test/e2e/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -537,4 +555,6 @@ module.exports = {
defaultGanacheOptions,
sendTransaction,
findAnotherAccountFromAccountList,
assertAccountBalanceForDOM,
locateAccountBalanceDOM,
};
10 changes: 8 additions & 2 deletions test/e2e/tests/address-book.spec.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -12,6 +16,7 @@ describe('Address Book', function () {
},
],
};

it('Sends to an address book entry', async function () {
await withFixtures(
{
Expand All @@ -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',
Expand Down
15 changes: 7 additions & 8 deletions test/e2e/tests/contract-interactions.spec.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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);
},
);
});
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/tests/metamask-responsive-ui.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
TEST_SEED_PHRASE_TWO,
convertToHexValue,
withFixtures,
assertAccountBalanceForDOM,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');

Expand Down Expand Up @@ -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);
},
);
});
Expand Down
13 changes: 7 additions & 6 deletions test/e2e/tests/navigate-transactions.spec.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand Down Expand Up @@ -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);
},
);
});
Expand Down
7 changes: 2 additions & 5 deletions test/e2e/tests/onboarding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
importSRPOnboardingFlow,
importWrongSRPOnboardingFlow,
testSRPDropdownIterations,
assertAccountBalanceForDOM,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');

Expand Down Expand Up @@ -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);
},
);
});
Expand Down
11 changes: 9 additions & 2 deletions test/e2e/tests/send-eth.spec.js
Original file line number Diff line number Diff line change
@@ -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 () {
Expand All @@ -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(
Expand Down
19 changes: 8 additions & 11 deletions test/e2e/tests/send-hex-address.spec.js
Original file line number Diff line number Diff line change
@@ -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');

Expand Down Expand Up @@ -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"]');
Expand Down Expand Up @@ -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"]');
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/tests/simple-send.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
convertToHexValue,
withFixtures,
sendTransaction,
assertAccountBalanceForDOM,
} = require('../helpers');
const FixtureBuilder = require('../fixture-builder');

Expand All @@ -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',
Expand Down

0 comments on commit 8dc6bf1

Please sign in to comment.