diff --git a/test/e2e/tests/send-hex-address.spec.js b/test/e2e/tests/send-hex-address.spec.js index af815c238..5c5bbf0a9 100644 --- a/test/e2e/tests/send-hex-address.spec.js +++ b/test/e2e/tests/send-hex-address.spec.js @@ -1,5 +1,6 @@ const { strict: assert } = require('assert'); const { convertToHexValue, withFixtures } = require('../helpers'); +const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const hexPrefixedAddress = '0x2f318C334780961FB129D2a6c30D0763d9a5C970'; const nonHexPrefixedAddress = hexPrefixedAddress.substring(2); @@ -119,6 +120,7 @@ describe('Send ETH to a 40 character hexadecimal address', function () { }); describe('Send ERC20 to a 40 character hexadecimal address', function () { + const smartContract = SMART_CONTRACTS.HST; const ganacheOptions = { accounts: [ { @@ -134,39 +136,29 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { dapp: true, fixtures: 'connected-state', ganacheOptions, + smartContract, title: this.test.title, failOnConsoleError: false, }, - async ({ driver }) => { + async ({ driver, contractRegistry }) => { + const contractAddress = await contractRegistry.getContractAddress( + smartContract, + ); 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/'); - await driver.clickElement('#createToken'); - await driver.waitUntilXWindowHandles(3); + await driver.openNewPage( + `http://127.0.0.1:8080/?contract=${contractAddress}`, + ); let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; - const dapp = await driver.switchToWindowWithTitle( - 'E2E Test Dapp', - windowHandles, - ); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.clickElement({ text: 'Confirm', tag: 'button' }); - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindow(extension); - await driver.clickElement('[data-testid="home__activity-tab"]'); - await driver.waitForSelector( - '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)', - { timeout: 10000 }, - ); + + // 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.switchToWindow(dapp); await driver.clickElement('#watchAsset'); await driver.waitUntilXWindowHandles(3); windowHandles = await driver.getAllWindowHandles(); @@ -209,7 +201,7 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.clickElement('[data-testid="home__activity-tab"]'); await driver.waitForSelector( - '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(2)', + '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)', { timeout: 10000 }, ); const sendTransactionListItem = await driver.waitForSelector( @@ -233,39 +225,28 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { dapp: true, fixtures: 'connected-state', ganacheOptions, + smartContract, title: this.test.title, failOnConsoleError: false, }, - async ({ driver }) => { + async ({ driver, contractRegistry }) => { + const contractAddress = await contractRegistry.getContractAddress( + smartContract, + ); 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/'); - await driver.clickElement('#createToken'); - await driver.waitUntilXWindowHandles(3); + await driver.openNewPage( + `http://127.0.0.1:8080/?contract=${contractAddress}`, + ); + let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; - const dapp = await driver.switchToWindowWithTitle( - 'E2E Test Dapp', - windowHandles, - ); - await driver.switchToWindowWithTitle( - 'MetaMask Notification', - windowHandles, - ); - await driver.clickElement({ text: 'Confirm', tag: 'button' }); - await driver.waitUntilXWindowHandles(2); - await driver.switchToWindow(extension); - await driver.clickElement('[data-testid="home__activity-tab"]'); - await driver.waitForSelector( - '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)', - { timeout: 10000 }, - ); // Add token - await driver.switchToWindow(dapp); + await driver.findClickableElement('#deployButton'); await driver.clickElement('#watchAsset'); await driver.waitUntilXWindowHandles(3); windowHandles = await driver.getAllWindowHandles(); @@ -308,7 +289,7 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { await driver.clickElement({ text: 'Confirm', tag: 'button' }); await driver.clickElement('[data-testid="home__activity-tab"]'); await driver.waitForSelector( - '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(2)', + '.transaction-list__completed-transactions .transaction-list-item:nth-of-type(1)', { timeout: 10000 }, ); const sendTransactionListItem = await driver.waitForSelector(