diff --git a/test/e2e/ganache.js b/test/e2e/ganache.js index 107b879ed3cf..4285ea41d5ce 100644 --- a/test/e2e/ganache.js +++ b/test/e2e/ganache.js @@ -23,6 +23,27 @@ class Ganache { return this._server.provider; } + async getAccounts() { + return await this.getProvider().request({ + method: 'eth_accounts', + params: [], + }); + } + + async getBalance() { + const accounts = await this.getAccounts(); + const balanceHex = await this.getProvider().request({ + method: 'eth_getBalance', + params: [accounts[0], 'latest'], + }); + const balanceInt = parseInt(balanceHex, 16) / 10 ** 18; + + const balanceFormatted = + balanceInt % 1 === 0 ? balanceInt : balanceInt.toFixed(4); + + return balanceFormatted; + } + async quit() { if (!this._server) { throw new Error('Server not running yet'); diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index 231fa0b57c99..2569dd4a33ed 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -145,6 +145,8 @@ async function withFixtures(options, testSuite) { driver: driverProxy ?? driver, mockServer, contractRegistry, + ganacheServer, + secondaryGanacheServer, }); } catch (error) { failed = true; diff --git a/test/e2e/tests/contract-interactions.spec.js b/test/e2e/tests/contract-interactions.spec.js index 98b562a2ede9..b13fe9826915 100644 --- a/test/e2e/tests/contract-interactions.spec.js +++ b/test/e2e/tests/contract-interactions.spec.js @@ -25,7 +25,7 @@ describe('Deploy contract and call contract methods', function () { smartContract, title: this.test.title, }, - async ({ driver, contractRegistry }) => { + async ({ driver, contractRegistry, ganacheServer }) => { const contractAddress = await contractRegistry.getContractAddress( smartContract, ); @@ -99,15 +99,15 @@ describe('Deploy contract and call contract methods', function () { // renders the correct ETH balance await driver.switchToWindow(extension); - const balance = await driver.waitForSelector( + const balance = await ganacheServer.getBalance(); + const balanceElement = await driver.waitForSelector( { css: '[data-testid="eth-overview__primary-currency"]', - text: '21.', + text: balance, }, { timeout: 10000 }, ); - const tokenAmount = await balance.getText(); - assert.ok(/^21.*\s*ETH.*$/u.test(tokenAmount)); + assert.equal(`${balance}\nETH`, await balanceElement.getText()); }, ); }); diff --git a/test/e2e/tests/metamask-responsive-ui.spec.js b/test/e2e/tests/metamask-responsive-ui.spec.js index 8dc91e0b40a9..36811bc38660 100644 --- a/test/e2e/tests/metamask-responsive-ui.spec.js +++ b/test/e2e/tests/metamask-responsive-ui.spec.js @@ -84,7 +84,7 @@ describe('MetaMask Responsive UI', function () { title: this.test.title, failOnConsoleError: false, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { await driver.navigate(); // Import Secret Recovery Phrase @@ -104,9 +104,10 @@ 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: '1000 ETH', + text: `${balance} ETH`, }); }, ); diff --git a/test/e2e/tests/navigate-transactions.spec.js b/test/e2e/tests/navigate-transactions.spec.js index 4d413673221a..3e272838d385 100644 --- a/test/e2e/tests/navigate-transactions.spec.js +++ b/test/e2e/tests/navigate-transactions.spec.js @@ -228,7 +228,7 @@ describe('Navigate transactions', 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); @@ -236,10 +236,11 @@ 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 driver.findElement( + const balance = await ganacheServer.getBalance(); + const balanceElement = await driver.findElement( '[data-testid="eth-overview__primary-currency"]', ); - assert.ok(/^25\sETH$/u.test(await balance.getText())); + assert.equal(`${balance}\nETH`, await balanceElement.getText()); }, ); }); diff --git a/test/e2e/tests/onboarding.spec.js b/test/e2e/tests/onboarding.spec.js index 2c4b8e6bbe69..7778989d3c56 100644 --- a/test/e2e/tests/onboarding.spec.js +++ b/test/e2e/tests/onboarding.spec.js @@ -260,7 +260,7 @@ describe('MetaMask onboarding', function () { title: this.test.title, }, - async ({ driver }) => { + async ({ driver, secondaryGanacheServer }) => { await driver.navigate(); await importSRPOnboardingFlow(driver, testSeedPhrase, testPassword); @@ -300,10 +300,11 @@ describe('MetaMask onboarding', function () { ); assert.equal(await networkDisplay.getText(), networkName); - const balance1 = await driver.findElement( + const balance = await secondaryGanacheServer.getBalance(); + const balanceElement = await driver.findElement( '[data-testid="eth-overview__primary-currency"]', ); - assert.ok(/^10\sETH$/u.test(await balance1.getText())); + assert.equal(`${balance}\nETH`, await balanceElement.getText()); }, ); }); diff --git a/test/e2e/tests/permissions.spec.js b/test/e2e/tests/permissions.spec.js index 3ebcbf117e59..3f61a7689e1a 100644 --- a/test/e2e/tests/permissions.spec.js +++ b/test/e2e/tests/permissions.spec.js @@ -13,7 +13,6 @@ describe('Permissions', function () { }, ], }; - const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; await withFixtures( { dapp: true, @@ -21,7 +20,9 @@ describe('Permissions', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); diff --git a/test/e2e/tests/personal-sign.spec.js b/test/e2e/tests/personal-sign.spec.js index 0622595d3e03..1a6d904f2f65 100644 --- a/test/e2e/tests/personal-sign.spec.js +++ b/test/e2e/tests/personal-sign.spec.js @@ -13,7 +13,6 @@ describe('Personal sign', function () { }, ], }; - const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; await withFixtures( { dapp: true, @@ -23,7 +22,9 @@ describe('Personal sign', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); diff --git a/test/e2e/tests/provider-api.spec.js b/test/e2e/tests/provider-api.spec.js index 449f894bd1c4..50cac9cef456 100644 --- a/test/e2e/tests/provider-api.spec.js +++ b/test/e2e/tests/provider-api.spec.js @@ -24,7 +24,9 @@ describe('MetaMask', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); @@ -60,10 +62,7 @@ describe('MetaMask', function () { assert.equal(await switchedNetworkDiv.getText(), '0x1'); assert.equal(await switchedChainIdDiv.getText(), '0x1'); - assert.equal( - await accountsDiv.getText(), - '0x5cfe73b6021e818b776b421b1c4db2474086a7e1', - ); + assert.equal(await accountsDiv.getText(), publicAddress); }, ); }); diff --git a/test/e2e/tests/send-hex-address.spec.js b/test/e2e/tests/send-hex-address.spec.js index 32301d325c6d..3e03dfd3157b 100644 --- a/test/e2e/tests/send-hex-address.spec.js +++ b/test/e2e/tests/send-hex-address.spec.js @@ -129,13 +129,14 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { title: this.test.title, failOnConsoleError: false, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { 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: '24.9977 ETH', + text: `${balanceAfterDeployment} ETH`, }); // Send TST @@ -194,13 +195,14 @@ describe('Send ERC20 to a 40 character hexadecimal address', function () { title: this.test.title, failOnConsoleError: false, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { 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: '24.9977 ETH', + text: `${balanceAfterDeployment} ETH`, }); // Send TST diff --git a/test/e2e/tests/signature-request.spec.js b/test/e2e/tests/signature-request.spec.js index 91a91eaf0f6f..9b508d37b328 100644 --- a/test/e2e/tests/signature-request.spec.js +++ b/test/e2e/tests/signature-request.spec.js @@ -17,7 +17,6 @@ describe('Sign Typed Data V4 Signature Request', function () { }, ], }; - const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; await withFixtures( { dapp: true, @@ -27,7 +26,9 @@ describe('Sign Typed Data V4 Signature Request', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); @@ -97,7 +98,6 @@ describe('Sign Typed Data V3 Signature Request', function () { }, ], }; - const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; await withFixtures( { dapp: true, @@ -107,7 +107,9 @@ describe('Sign Typed Data V3 Signature Request', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); @@ -178,7 +180,6 @@ describe('Sign Typed Data Signature Request', function () { }, ], }; - const publicAddress = '0x5cfe73b6021e818b776b421b1c4db2474086a7e1'; await withFixtures( { dapp: true, @@ -188,7 +189,9 @@ describe('Sign Typed Data Signature Request', function () { ganacheOptions, title: this.test.title, }, - async ({ driver }) => { + async ({ driver, ganacheServer }) => { + const addresses = await ganacheServer.getAccounts(); + const publicAddress = addresses[0]; await driver.navigate(); await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER);