From 395ac34bedfabdf13faf6deadc4dd04b703c7da2 Mon Sep 17 00:00:00 2001 From: Danica Shen Date: Fri, 5 May 2023 14:56:08 +0100 Subject: [PATCH] chore: refactor connect to dapp action in e2e (#19015) * chore: refactor connect to dapp action in e2e * chore: refactor 2nd dapp connection * chore: rename to openDapp --- test/e2e/fixture-builder.js | 7 +++--- test/e2e/helpers.js | 12 ++++++++++ test/e2e/metamask-ui.spec.js | 3 ++- test/e2e/mv3/dapp-interactions.spec.js | 4 ++-- test/e2e/mv3/service-worker-restart.spec.js | 4 ++-- test/e2e/nft/erc1155-interaction.spec.js | 19 +++++++++------ test/e2e/nft/erc721-interaction.spec.js | 10 ++++---- test/e2e/tests/add-custom-network.spec.js | 8 +++---- test/e2e/tests/chain-interactions.spec.js | 6 ++--- test/e2e/tests/contract-interactions.spec.js | 6 ++--- .../tests/custom-token-add-approve.spec.js | 23 +++++-------------- test/e2e/tests/dapp-interactions.spec.js | 18 ++++++++++----- test/e2e/tests/dapp-tx-edit.spec.js | 9 +++----- test/e2e/tests/edit-gas-fee.spec.js | 3 ++- test/e2e/tests/encrypt-decrypt.spec.js | 8 +++---- test/e2e/tests/eth-sign.spec.js | 13 +++++++---- test/e2e/tests/eth-subscribe.spec.js | 11 ++++++--- test/e2e/tests/failing-contract.spec.js | 10 +++----- test/e2e/tests/incremental-security.spec.js | 4 ++-- test/e2e/tests/navigate-transactions.spec.js | 4 ++-- test/e2e/tests/permissions.spec.js | 4 ++-- test/e2e/tests/personal-sign.spec.js | 4 ++-- test/e2e/tests/phishing-detection.spec.js | 10 ++++---- test/e2e/tests/provider-api.spec.js | 6 ++--- test/e2e/tests/security-provider.spec.js | 10 ++++---- test/e2e/tests/send-eth.spec.js | 6 ++--- test/e2e/tests/signature-request.spec.js | 14 ++++++----- test/e2e/tests/signin-with-ethereum.spec.js | 11 ++++++--- test/e2e/tests/switch-custom-network.spec.js | 4 ++-- 29 files changed, 137 insertions(+), 114 deletions(-) diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index d82b2ef45..051d3f02c 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -8,6 +8,7 @@ const { ACTION_QUEUE_METRICS_E2E_TEST, } = require('../../shared/constants/test-flags'); const { SMART_CONTRACTS } = require('./seeder/smart-contracts'); +const { DAPP_URL } = require('./helpers'); function defaultFixture() { return { @@ -594,13 +595,13 @@ class FixtureBuilder { withPermissionControllerConnectedToTestDapp() { return this.withPermissionController({ subjects: { - 'http://127.0.0.1:8080': { - origin: 'http://127.0.0.1:8080', + [DAPP_URL]: { + origin: DAPP_URL, permissions: { eth_accounts: { id: 'ZaqPEWxyhNCJYACFw93jE', parentCapability: 'eth_accounts', - invoker: 'http://127.0.0.1:8080', + invoker: DAPP_URL, caveats: [ { type: 'restrictReturnedAccounts', diff --git a/test/e2e/helpers.js b/test/e2e/helpers.js index bc46e568f..c95a60ce7 100644 --- a/test/e2e/helpers.js +++ b/test/e2e/helpers.js @@ -383,7 +383,18 @@ const testSRPDropdownIterations = async (options, driver, iterations) => { } }; +const DAPP_URL = 'http://127.0.0.1:8080'; +const DAPP_ONE_URL = 'http://127.0.0.1:8081'; + +const openDapp = async (driver, contract = null, dappURL = DAPP_URL) => { + contract + ? await driver.openNewPage(`${dappURL}/?contract=${contract}`) + : await driver.openNewPage(dappURL); +}; + module.exports = { + DAPP_URL, + DAPP_ONE_URL, getWindowHandles, convertToHexValue, tinyDelayMs, @@ -398,4 +409,5 @@ module.exports = { createDownloadFolder, importWrongSRPOnboardingFlow, testSRPDropdownIterations, + openDapp, }; diff --git a/test/e2e/metamask-ui.spec.js b/test/e2e/metamask-ui.spec.js index c2b630c8f..1a03f024b 100644 --- a/test/e2e/metamask-ui.spec.js +++ b/test/e2e/metamask-ui.spec.js @@ -8,6 +8,7 @@ const { regularDelayMs, largeDelayMs, veryLargeDelayMs, + openDapp, } = require('./helpers'); const { buildWebDriver } = require('./webdriver'); const Ganache = require('./ganache'); @@ -177,7 +178,7 @@ describe('MetaMask', function () { let popup; let dapp; it('connects the dapp', async function () { - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.delay(regularDelayMs); await driver.clickElement({ text: 'Connect', tag: 'button' }); diff --git a/test/e2e/mv3/dapp-interactions.spec.js b/test/e2e/mv3/dapp-interactions.spec.js index 294182cc9..71b51f722 100644 --- a/test/e2e/mv3/dapp-interactions.spec.js +++ b/test/e2e/mv3/dapp-interactions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('MV3 - Dapp interactions', function () { @@ -31,7 +31,7 @@ describe('MV3 - Dapp interactions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); // Terminate Service Worker await driver.openNewPage('chrome://inspect/#service-workers/'); diff --git a/test/e2e/mv3/service-worker-restart.spec.js b/test/e2e/mv3/service-worker-restart.spec.js index f33878f88..9a69d0f34 100644 --- a/test/e2e/mv3/service-worker-restart.spec.js +++ b/test/e2e/mv3/service-worker-restart.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const { ACTION_QUEUE_METRICS_E2E_TEST, @@ -142,7 +142,7 @@ describe('MV3 - Service worker restart', function () { await driver.press('#password', driver.Key.ENTER); // initialize a transaction of send from dapp - await driver.openNewPage('http://127.0.0.1:8080'); + await openDapp(driver); await driver.clickElement('#sendButton'); // A popup window is initialized diff --git a/test/e2e/nft/erc1155-interaction.spec.js b/test/e2e/nft/erc1155-interaction.spec.js index 7a5b95961..c4d83d875 100644 --- a/test/e2e/nft/erc1155-interaction.spec.js +++ b/test/e2e/nft/erc1155-interaction.spec.js @@ -1,5 +1,10 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + DAPP_URL, + openDapp, +} = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -34,7 +39,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Open Dapp and wait for deployed contract - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.findClickableElement('#deployButton'); // Mint @@ -91,7 +96,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { 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=${contract}`); + await openDapp(driver, contract); await driver.fill('#batchTransferTokenIds', '1, 2, 3'); await driver.fill('#batchTransferTokenAmounts', '1, 1, 1000000000000'); @@ -150,7 +155,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Create a set approval for all erc1155 token request in test dapp - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.clickElement('#setApprovalForAllERC1155Button'); // Wait for notification popup and check the displayed message @@ -170,7 +175,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { const displayedUrl = await driver.findElement( '.confirm-approve-content h6', ); - assert.equal(await displayedUrl.getText(), 'http://127.0.0.1:8080'); + assert.equal(await displayedUrl.getText(), DAPP_URL); const displayedDescription = await driver.findElement( '.confirm-approve-content__description', ); @@ -239,7 +244,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Create a revoke approval for all erc1155 token request in test dapp - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.clickElement('#revokeERC1155Button'); // Wait for notification popup and check the displayed message @@ -260,7 +265,7 @@ describe('ERC1155 NFTs testdapp interaction', function () { const displayedUrl = await driver.findElement( '.confirm-approve-content h6', ); - assert.equal(await displayedUrl.getText(), 'http://127.0.0.1:8080'); + assert.equal(await displayedUrl.getText(), DAPP_URL); const displayedDescription = await driver.findElement( '.confirm-approve-content__description', ); diff --git a/test/e2e/nft/erc721-interaction.spec.js b/test/e2e/nft/erc721-interaction.spec.js index 2d7d3abe9..d0603225a 100644 --- a/test/e2e/nft/erc721-interaction.spec.js +++ b/test/e2e/nft/erc721-interaction.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -34,7 +34,7 @@ describe('ERC721 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Open Dapp and wait for deployed contract - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.findClickableElement('#deployButton'); // Click Transer @@ -86,7 +86,7 @@ describe('ERC721 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Open Dapp and wait for deployed contract - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.findClickableElement('#deployButton'); // Click Approve @@ -158,7 +158,7 @@ describe('ERC721 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Open Dapp and wait for deployed contract - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.findClickableElement('#deployButton'); // Enable Set approval for all @@ -229,7 +229,7 @@ describe('ERC721 NFTs testdapp interaction', function () { await driver.press('#password', driver.Key.ENTER); // Open Dapp and wait for deployed contract - await driver.openNewPage(`http://127.0.0.1:8080/?contract=${contract}`); + await openDapp(driver, contract); await driver.findClickableElement('#deployButton'); // Disable Set approval for all diff --git a/test/e2e/tests/add-custom-network.spec.js b/test/e2e/tests/add-custom-network.spec.js index 45bdc8e36..d87953bda 100644 --- a/test/e2e/tests/add-custom-network.spec.js +++ b/test/e2e/tests/add-custom-network.spec.js @@ -1,6 +1,6 @@ const { strict: assert } = require('assert'); const FixtureBuilder = require('../fixture-builder'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); describe('Custom network', function () { const chainID = '42161'; @@ -33,7 +33,7 @@ describe('Custom network', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.executeScript(` var params = [{ chainId: "0x1", @@ -111,7 +111,7 @@ describe('Custom network', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.executeScript(` var params = [{ chainId: "0x123", @@ -176,7 +176,7 @@ describe('Custom network', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.executeScript(` var params = [{ chainId: "0x123", diff --git a/test/e2e/tests/chain-interactions.spec.js b/test/e2e/tests/chain-interactions.spec.js index 42feb3913..6597f67c1 100644 --- a/test/e2e/tests/chain-interactions.spec.js +++ b/test/e2e/tests/chain-interactions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Chain Interactions', function () { @@ -29,7 +29,7 @@ describe('Chain Interactions', function () { await driver.press('#password', driver.Key.ENTER); // trigger add chain confirmation - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#addEthereumChain'); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); @@ -81,7 +81,7 @@ describe('Chain Interactions', function () { await driver.press('#password', driver.Key.ENTER); // trigger add chain confirmation - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#addEthereumChain'); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); diff --git a/test/e2e/tests/contract-interactions.spec.js b/test/e2e/tests/contract-interactions.spec.js index dbfcd5259..780b21c5f 100644 --- a/test/e2e/tests/contract-interactions.spec.js +++ b/test/e2e/tests/contract-interactions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -34,9 +34,7 @@ describe('Deploy contract and call contract methods', function () { await driver.press('#password', driver.Key.ENTER); // deploy contract - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); + await openDapp(driver, contractAddress); // wait for deployed contract, calls and confirms a contract method where ETH is sent await driver.findClickableElement('#deployButton'); diff --git a/test/e2e/tests/custom-token-add-approve.spec.js b/test/e2e/tests/custom-token-add-approve.spec.js index c3e73d71e..a02a8c856 100644 --- a/test/e2e/tests/custom-token-add-approve.spec.js +++ b/test/e2e/tests/custom-token-add-approve.spec.js @@ -1,6 +1,6 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); @@ -36,9 +36,7 @@ describe('Create token, approve token and approve token without gas', function ( await driver.press('#password', driver.Key.ENTER); // create token - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); + await openDapp(driver, contractAddress); const windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; @@ -100,9 +98,7 @@ describe('Create token, approve token and approve token without gas', function ( await driver.press('#password', driver.Key.ENTER); // create token - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); + await openDapp(driver, contractAddress); let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; @@ -226,9 +222,7 @@ describe('Create token, approve token and approve token without gas', function ( await driver.press('#password', driver.Key.ENTER); // create token - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); + await openDapp(driver, contractAddress); let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; @@ -372,10 +366,7 @@ describe('Create token, approve token and approve token without gas', function ( await driver.press('#password', driver.Key.ENTER); // create token - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); - + await openDapp(driver, contractAddress); const windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; @@ -458,9 +449,7 @@ describe('Create token, approve token and approve token without gas', function ( 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}`, - ); + await openDapp(driver, contractAddress); const windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; diff --git a/test/e2e/tests/dapp-interactions.spec.js b/test/e2e/tests/dapp-interactions.spec.js index 0c74c663b..bfd0a8e22 100644 --- a/test/e2e/tests/dapp-interactions.spec.js +++ b/test/e2e/tests/dapp-interactions.spec.js @@ -1,5 +1,11 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + DAPP_URL, + DAPP_ONE_URL, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Dapp interactions', function () { @@ -31,7 +37,7 @@ describe('Dapp interactions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); extension = windowHandles[0]; @@ -76,7 +82,7 @@ describe('Dapp interactions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); extension = windowHandles[0]; @@ -86,7 +92,7 @@ describe('Dapp interactions', function () { await driver.clickElement({ text: 'Lock', tag: 'button' }); // Connect to Dapp1 - await driver.openNewPage('http://127.0.0.1:8081/'); + await openDapp(driver, null, DAPP_ONE_URL); await driver.clickElement({ text: 'Connect', tag: 'button' }); await driver.waitUntilXWindowHandles(4); windowHandles = await driver.getAllWindowHandles(); @@ -111,11 +117,11 @@ describe('Dapp interactions', function () { ); await driver.clickElement({ text: 'Connected sites', tag: 'div' }); const connectedDapp1 = await driver.isElementPresent({ - text: 'http://127.0.0.1:8080', + text: DAPP_URL, tag: 'bdi', }); const connectedDapp2 = await driver.isElementPresent({ - text: 'http://127.0.0.1:8081', + text: DAPP_ONE_URL, tag: 'bdi', }); diff --git a/test/e2e/tests/dapp-tx-edit.spec.js b/test/e2e/tests/dapp-tx-edit.spec.js index 3b937f4ea..c57295698 100644 --- a/test/e2e/tests/dapp-tx-edit.spec.js +++ b/test/e2e/tests/dapp-tx-edit.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -34,10 +34,7 @@ describe('Editing confirmations of dapp initiated contract interactions', functi await driver.press('#password', driver.Key.ENTER); // deploy contract - await driver.openNewPage( - `http://127.0.0.1:8080/?contract=${contractAddress}`, - ); - + await openDapp(driver, contractAddress); // wait for deployed contract, calls and confirms a contract method where ETH is sent await driver.findClickableElement('#deployButton'); await driver.clickElement('#depositButton'); @@ -80,7 +77,7 @@ describe('Editing confirmations of dapp initiated contract interactions', functi await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage(`http://127.0.0.1:8080/`); + await openDapp(driver); await driver.clickElement('#sendButton'); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); diff --git a/test/e2e/tests/edit-gas-fee.spec.js b/test/e2e/tests/edit-gas-fee.spec.js index 5ac4bc0ef..b304ba2f6 100644 --- a/test/e2e/tests/edit-gas-fee.spec.js +++ b/test/e2e/tests/edit-gas-fee.spec.js @@ -3,6 +3,7 @@ const { convertToHexValue, getWindowHandles, withFixtures, + openDapp, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -206,7 +207,7 @@ describe('Editing Confirm Transaction', function () { await driver.press('#password', driver.Key.ENTER); // open dapp and connect - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ text: 'Send EIP 1559 Transaction', tag: 'button', diff --git a/test/e2e/tests/encrypt-decrypt.spec.js b/test/e2e/tests/encrypt-decrypt.spec.js index d9216ccd0..a311b7545 100644 --- a/test/e2e/tests/encrypt-decrypt.spec.js +++ b/test/e2e/tests/encrypt-decrypt.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Encrypt Decrypt', function () { @@ -28,7 +28,7 @@ describe('Encrypt Decrypt', function () { 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'); + await openDapp(driver); // ------ Get Encryption key ------ await driver.clickElement('#getEncryptionKeyButton'); @@ -109,7 +109,7 @@ describe('Encrypt Decrypt', function () { 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'); + await openDapp(driver); // ------ Get Encryption key and display ETH ------ await driver.clickElement('#getEncryptionKeyButton'); @@ -153,7 +153,7 @@ describe('Encrypt Decrypt', function () { await driver.press('#password', driver.Key.ENTER); await driver.clickElement('.account-menu__icon'); - await driver.openNewPage('http://127.0.0.1:8080'); + await openDapp(driver); // ------ Get Encryption key and display ETH ------ await driver.clickElement('#getEncryptionKeyButton'); diff --git a/test/e2e/tests/eth-sign.spec.js b/test/e2e/tests/eth-sign.spec.js index 5b0feb3b3..b6868a2aa 100644 --- a/test/e2e/tests/eth-sign.spec.js +++ b/test/e2e/tests/eth-sign.spec.js @@ -1,5 +1,10 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + DAPP_URL, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const ganacheOptions = { @@ -28,7 +33,7 @@ describe('Eth sign', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#ethSign'); await driver.delay(1000); @@ -64,7 +69,7 @@ describe('Eth sign', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#ethSign'); // Wait for Signature request popup @@ -80,7 +85,7 @@ describe('Eth sign', function () { ); const origin = await driver.findElement('.request-signature__origin'); assert.equal(await title.getText(), 'Signature request'); - assert.equal(await origin.getText(), 'http://127.0.0.1:8080'); + assert.equal(await origin.getText(), DAPP_URL); const personalMessageRow = await driver.findElement( '.request-signature__row-value', diff --git a/test/e2e/tests/eth-subscribe.spec.js b/test/e2e/tests/eth-subscribe.spec.js index d77135164..8bfdfd99d 100644 --- a/test/e2e/tests/eth-subscribe.spec.js +++ b/test/e2e/tests/eth-subscribe.spec.js @@ -1,4 +1,9 @@ -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + DAPP_ONE_URL, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('eth_subscribe', function () { @@ -28,7 +33,7 @@ describe('eth_subscribe', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); const setupSubscriptionListener = ` const responseContainer = document.createElement('div'); @@ -63,7 +68,7 @@ describe('eth_subscribe', function () { await driver.findElement('[data-testid="eth-subscribe-response"]'); // Switch to the second dapp - await driver.openNewPage('http://127.0.0.1:8081/'); + await openDapp(driver, null, DAPP_ONE_URL); // Setup the same subscription listener as on the first dapp, but without registering a new subscription await driver.executeScript(setupSubscriptionListener); diff --git a/test/e2e/tests/failing-contract.spec.js b/test/e2e/tests/failing-contract.spec.js index 7f0dd766e..cc25bc3c8 100644 --- a/test/e2e/tests/failing-contract.spec.js +++ b/test/e2e/tests/failing-contract.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); const FixtureBuilder = require('../fixture-builder'); @@ -34,9 +34,7 @@ describe('Failing contract interaction ', function () { 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}`, - ); + await openDapp(driver, contractAddress); let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; @@ -114,9 +112,7 @@ describe('Failing contract interaction on non-EIP1559 network', function () { 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}`, - ); + await openDapp(driver, contractAddress); let windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; // waits for deployed contract and calls failing contract method diff --git a/test/e2e/tests/incremental-security.spec.js b/test/e2e/tests/incremental-security.spec.js index 2213046e3..6c243bd79 100644 --- a/test/e2e/tests/incremental-security.spec.js +++ b/test/e2e/tests/incremental-security.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Incremental Security', function () { @@ -89,7 +89,7 @@ describe('Incremental Security', function () { const extension = windowHandles[0]; // switched to Dapp - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); // sends eth to the current account await driver.fill('#address', publicAddress); diff --git a/test/e2e/tests/navigate-transactions.spec.js b/test/e2e/tests/navigate-transactions.spec.js index 9a0011b34..438ef5028 100644 --- a/test/e2e/tests/navigate-transactions.spec.js +++ b/test/e2e/tests/navigate-transactions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Navigate transactions', function () { @@ -130,7 +130,7 @@ describe('Navigate transactions', function () { ); // add transaction - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ text: 'Send', tag: 'button' }); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); diff --git a/test/e2e/tests/permissions.spec.js b/test/e2e/tests/permissions.spec.js index 3f61a7689..5ea819b64 100644 --- a/test/e2e/tests/permissions.spec.js +++ b/test/e2e/tests/permissions.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Permissions', function () { @@ -27,7 +27,7 @@ describe('Permissions', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ text: 'Connect', tag: 'button', diff --git a/test/e2e/tests/personal-sign.spec.js b/test/e2e/tests/personal-sign.spec.js index 86f798c67..9ecd04f52 100644 --- a/test/e2e/tests/personal-sign.spec.js +++ b/test/e2e/tests/personal-sign.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Personal sign', function () { @@ -29,7 +29,7 @@ describe('Personal sign', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#personalSign'); await driver.waitUntilXWindowHandles(3); diff --git a/test/e2e/tests/phishing-detection.spec.js b/test/e2e/tests/phishing-detection.spec.js index c82645e1f..0775a68a7 100644 --- a/test/e2e/tests/phishing-detection.spec.js +++ b/test/e2e/tests/phishing-detection.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const STALELIST_URL = @@ -107,7 +107,7 @@ describe('Phishing Detection', function () { 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'); + await openDapp(driver); await driver.clickElement({ text: 'continue to the site.', }); @@ -208,7 +208,7 @@ describe('Phishing Detection', function () { 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'); + await openDapp(driver); await driver.clickElement({ text: 'report a detection problem.' }); @@ -236,7 +236,7 @@ describe('Phishing Detection', function () { 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'); + await openDapp(driver); await driver.clickElement({ text: 'report a detection problem.' }); @@ -276,7 +276,7 @@ describe('Phishing Detection', function () { 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'); + await openDapp(driver); await driver.clickElement({ text: 'report a detection problem.' }); diff --git a/test/e2e/tests/provider-api.spec.js b/test/e2e/tests/provider-api.spec.js index 50cac9cef..2321e0157 100644 --- a/test/e2e/tests/provider-api.spec.js +++ b/test/e2e/tests/provider-api.spec.js @@ -1,6 +1,6 @@ const { strict: assert } = require('assert'); const { errorCodes } = require('eth-rpc-errors'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('MetaMask', function () { @@ -31,7 +31,7 @@ describe('MetaMask', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); const networkDiv = await driver.waitForSelector({ css: '#network', text: '1337', @@ -83,7 +83,7 @@ describe('MetaMask', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); for (const unsupportedMethod of ['eth_signTransaction']) { assert.equal( await driver.executeAsyncScript(` diff --git a/test/e2e/tests/security-provider.spec.js b/test/e2e/tests/security-provider.spec.js index df0ff4390..bfbfc443f 100644 --- a/test/e2e/tests/security-provider.spec.js +++ b/test/e2e/tests/security-provider.spec.js @@ -1,5 +1,5 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); const OPENSEA_URL = @@ -94,7 +94,7 @@ describe('Transaction security provider', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); await driver.clickElement('#personalSign'); @@ -134,7 +134,7 @@ describe('Transaction security provider', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); await driver.clickElement('#signTypedData'); @@ -174,7 +174,7 @@ describe('Transaction security provider', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); await driver.clickElement('#siwe'); @@ -214,7 +214,7 @@ describe('Transaction security provider', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); windowHandles = await driver.getAllWindowHandles(); await driver.clickElement('#signTypedDataV4'); diff --git a/test/e2e/tests/send-eth.spec.js b/test/e2e/tests/send-eth.spec.js index 56c9f744c..dd2ae8650 100644 --- a/test/e2e/tests/send-eth.spec.js +++ b/test/e2e/tests/send-eth.spec.js @@ -1,6 +1,6 @@ const { strict: assert } = require('assert'); const { SMART_CONTRACTS } = require('../seeder/smart-contracts'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Send ETH from inside MetaMask using default gas', function () { @@ -232,7 +232,7 @@ describe('Send ETH from dapp using advanced gas controls', function () { await driver.press('#password', driver.Key.ENTER); // initiates a send from the dapp - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ text: 'Send', tag: 'button' }); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); @@ -311,7 +311,7 @@ describe('Send ETH from dapp using advanced gas controls', function () { await driver.press('#password', driver.Key.ENTER); // initiates a transaction from the dapp - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ text: 'Create Token', tag: 'button' }); await driver.waitUntilXWindowHandles(3); const windowHandles = await driver.getAllWindowHandles(); diff --git a/test/e2e/tests/signature-request.spec.js b/test/e2e/tests/signature-request.spec.js index 62ac5cd78..f16bdf4ff 100644 --- a/test/e2e/tests/signature-request.spec.js +++ b/test/e2e/tests/signature-request.spec.js @@ -3,6 +3,8 @@ const { convertToHexValue, withFixtures, regularDelayMs, + openDapp, + DAPP_URL, } = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); @@ -33,7 +35,7 @@ describe('Sign Typed Data V4 Signature Request', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); // creates a sign typed data signature request await driver.clickElement('#signTypedDataV4'); @@ -57,7 +59,7 @@ describe('Sign Typed Data V4 Signature Request', function () { ); assert.equal(await title.getText(), 'Signature request'); - assert.equal(await origin.getText(), 'http://127.0.0.1:8080'); + assert.equal(await origin.getText(), DAPP_URL); verifyContractDetailsButton.click(); await driver.findElement({ text: 'Third-party details', tag: 'h5' }); @@ -114,7 +116,7 @@ describe('Sign Typed Data V3 Signature Request', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); // creates a sign typed data signature request await driver.clickElement('#signTypedDataV3'); @@ -139,7 +141,7 @@ describe('Sign Typed Data V3 Signature Request', function () { ); assert.equal(await title.getText(), 'Signature request'); - assert.equal(await origin.getText(), 'http://127.0.0.1:8080'); + assert.equal(await origin.getText(), DAPP_URL); verifyContractDetailsButton.click(); await driver.findElement({ text: 'Third-party details', tag: 'h5' }); @@ -196,7 +198,7 @@ describe('Sign Typed Data Signature Request', function () { await driver.fill('#password', 'correct horse battery staple'); await driver.press('#password', driver.Key.ENTER); - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); // creates a sign typed data signature request await driver.clickElement('#signTypedData'); @@ -216,7 +218,7 @@ describe('Sign Typed Data Signature Request', function () { '.request-signature__row-value', ); assert.equal(await title.getText(), 'Signature request'); - assert.equal(await origin.getText(), 'http://127.0.0.1:8080'); + assert.equal(await origin.getText(), DAPP_URL); assert.equal(await message[0].getText(), 'Hi, Alice!'); assert.equal(await message[1].getText(), '1337'); diff --git a/test/e2e/tests/signin-with-ethereum.spec.js b/test/e2e/tests/signin-with-ethereum.spec.js index bbef37b6b..43436ae30 100644 --- a/test/e2e/tests/signin-with-ethereum.spec.js +++ b/test/e2e/tests/signin-with-ethereum.spec.js @@ -1,5 +1,10 @@ const { strict: assert } = require('assert'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { + convertToHexValue, + withFixtures, + openDapp, + DAPP_URL, +} = require('../helpers'); const FixtureBuilder = require('../fixture-builder'); describe('Sign in with ethereum', function () { @@ -36,7 +41,7 @@ describe('Sign in with ethereum', function () { await driver.press('#password', driver.Key.ENTER); // Create a signin with ethereum request in test dapp - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement('#siwe'); // Wait for signature request popup and check the message title @@ -51,7 +56,7 @@ describe('Sign in with ethereum', function () { ); const origin = await driver.findElement('.site-origin'); assert.equal(await title.getText(), 'Sign-in request'); - assert.equal(await origin.getText(), 'http://127.0.0.1:8080'); + assert.equal(await origin.getText(), DAPP_URL); const displayedMessageTitle = await driver.findElement( '.permissions-connect-header__subtitle', diff --git a/test/e2e/tests/switch-custom-network.spec.js b/test/e2e/tests/switch-custom-network.spec.js index 9da4eedc1..a670f913f 100644 --- a/test/e2e/tests/switch-custom-network.spec.js +++ b/test/e2e/tests/switch-custom-network.spec.js @@ -1,6 +1,6 @@ const { strict: assert } = require('assert'); const FixtureBuilder = require('../fixture-builder'); -const { convertToHexValue, withFixtures } = require('../helpers'); +const { convertToHexValue, withFixtures, openDapp } = require('../helpers'); describe('Swtich ethereum chain', function () { const ganacheOptions = { @@ -33,7 +33,7 @@ describe('Swtich ethereum chain', function () { const windowHandles = await driver.getAllWindowHandles(); const extension = windowHandles[0]; - await driver.openNewPage('http://127.0.0.1:8080/'); + await openDapp(driver); await driver.clickElement({ tag: 'button',