From e1ce248364f5e4cad6514a1b2ba78e8b325bdfe9 Mon Sep 17 00:00:00 2001 From: Peter <53189696+PeterYinusa@users.noreply.github.com> Date: Fri, 17 Mar 2023 09:55:52 +0000 Subject: [PATCH] e2e test erc20 fixtures (#18154) * add fixture * update test * update test * wait for ETH balance --- test/e2e/fixture-builder.js | 37 ++++++++++++ test/e2e/tests/send-hex-address.spec.js | 79 +++++++------------------ test/e2e/tests/send-to-contract.spec.js | 24 +------- 3 files changed, 58 insertions(+), 82 deletions(-) diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index 145d6bfc0..a56197f4e 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -701,6 +701,43 @@ class FixtureBuilder { return this; } + withTokensControllerERC20() { + merge(this.fixture.data.TokensController, { + tokens: [ + { + address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`, + symbol: 'TST', + decimals: 4, + image: + 'https://static.metafi.codefi.network/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png', + isERC721: false, + aggregators: [], + }, + ], + ignoredTokens: [], + detectedTokens: [], + allTokens: { + '0x539': { + '0x5cfe73b6021e818b776b421b1c4db2474086a7e1': [ + { + address: `__FIXTURE_SUBSTITUTION__CONTRACT${SMART_CONTRACTS.HST}`, + symbol: 'TST', + decimals: 4, + image: + 'https://static.metafi.codefi.network/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png', + isERC721: false, + aggregators: [], + }, + ], + }, + }, + allIgnoredTokens: {}, + allDetectedTokens: {}, + suggestedAssets: [], + }); + return this; + } + withTransactionController(data) { merge( this.fixture.data.TransactionController diff --git a/test/e2e/tests/send-hex-address.spec.js b/test/e2e/tests/send-hex-address.spec.js index fcde57874..32301d325 100644 --- a/test/e2e/tests/send-hex-address.spec.js +++ b/test/e2e/tests/send-hex-address.spec.js @@ -123,43 +123,20 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await withFixtures( { dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), + fixtures: new FixtureBuilder().withTokensControllerERC20().build(), ganacheOptions, smartContract, title: this.test.title, failOnConsoleError: false, }, - async ({ driver, contractRegistry }) => { - const contractAddress = await contractRegistry.getContractAddress( - smartContract, - ); + async ({ driver }) => { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); - let windowHandles = await driver.getAllWindowHandles(); - const extension = windowHandles[0]; - - // Using the line below to make wait time deterministic and avoid using a delay - // See more here https://github.com/MetaMask/metamask-extension/pull/15604/files#r949300551 - await driver.findClickableElement('#deployButton'); - - // Add token - await driver.clickElement('#watchAsset'); - await driver.waitUntilXWindowHandles(3); - windowHandles = await driver.getAllWindowHandles(); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.clickElement({ text: 'Add token', tag: 'button' }); - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindow(extension); + await driver.waitForSelector({ + css: '[data-testid="eth-overview__primary-currency"]', + text: '24.9977 ETH', + }); // Send TST await driver.clickElement('[data-testid="home__asset-tab"]'); @@ -175,7 +152,10 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { css: '.ens-input__selected-input__title', text: hexPrefixedAddress, }); - await driver.delay(2000); + await driver.waitForSelector({ + css: '.transaction-detail-item', + text: '0.00008346 ETH', + }); await driver.clickElement({ text: 'Next', tag: 'button' }); // Confirm transaction @@ -208,42 +188,20 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await withFixtures( { dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), + fixtures: new FixtureBuilder().withTokensControllerERC20().build(), ganacheOptions, smartContract, title: this.test.title, failOnConsoleError: false, }, - async ({ driver, contractRegistry }) => { - const contractAddress = await contractRegistry.getContractAddress( - smartContract, - ); + async ({ driver }) => { await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - - // Create TST - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); - - let windowHandles = await driver.getAllWindowHandles(); - const extension = windowHandles[0]; - - // Add token - await driver.findClickableElement('#deployButton'); - await driver.clickElement('#watchAsset'); - await driver.waitUntilXWindowHandles(3); - windowHandles = await driver.getAllWindowHandles(); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.clickElement({ text: 'Add token', tag: 'button' }); - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindow(extension); + await driver.waitForSelector({ + css: '[data-testid="eth-overview__primary-currency"]', + text: '24.9977 ETH', + }); // Send TST await driver.clickElement('[data-testid="home__asset-tab"]'); @@ -259,7 +217,10 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { css: '.ens-input__selected-input__title', text: hexPrefixedAddress, }); - await driver.delay(2000); + await driver.waitForSelector({ + css: '.transaction-detail-item', + text: '0.00008346 ETH', + }); await driver.clickElement({ text: 'Next', tag: 'button' }); // Confirm transaction diff --git a/test/e2e/tests/send-to-contract.spec.js b/test/e2e/tests/send-to-contract.spec.js index e7dffa5e7..62a6a58e4 100644 --- a/test/e2e/tests/send-to-contract.spec.js +++ b/test/e2e/tests/send-to-contract.spec.js @@ -18,9 +18,7 @@ describe('Send ERC20 token to contract address', function () { await withFixtures( { dapp: true, - fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDapp() - .build(), + fixtures: new FixtureBuilder().withTokensControllerERC20().build(), ganacheOptions, smartContract, title: this.test.title, @@ -34,26 +32,6 @@ describe('Send ERC20 token to contract address', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - // Create TST - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); - let windowHandles = await driver.getAllWindowHandles(); - const extension = windowHandles[0]; - - // Add token - await driver.findClickableElement('#deployButton'); - await driver.clickElement('#watchAsset'); - await driver.waitUntilXWindowHandles(3); - windowHandles = await driver.getAllWindowHandles(); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.clickElement({ text: 'Add token', tag: 'button' }); - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindow(extension); - // Send TST await driver.clickElement('[data-testid="home__asset-tab"]'); await driver.clickElement('.token-cell');