From a2692c34307377a1952d90d75f19c954583ebfa6 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Tue, 14 Jan 2025 14:40:19 +0100 Subject: [PATCH 1/8] test: multichain test dapp e2e tests for password locked extension (wip) --- .../multichain-api/password-locked.spec.ts | 111 ++++++++++++++++++ test/e2e/flask/multichain-api/testHelpers.ts | 13 ++ 2 files changed, 124 insertions(+) create mode 100644 test/e2e/flask/multichain-api/password-locked.spec.ts diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts new file mode 100644 index 000000000000..1de25e75c3c9 --- /dev/null +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -0,0 +1,111 @@ +import { strict as assert } from 'assert'; +import { + ACCOUNT_1, + ACCOUNT_2, + largeDelayMs, + veryLargeDelayMs, + WINDOW_TITLES, + withFixtures, +} from '../../helpers'; +import { Driver } from '../../webdriver/driver'; +import FixtureBuilder from '../../fixture-builder'; +import { + addAccountInWalletAndAuthorize, + DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, + getExpectedSessionScope, + getSessionScopes, + initCreateSessionScopes, + openMultichainDappAndConnectWalletWithExternallyConnectable, + passwordLockMetamaskExtension, + updateNetworkCheckboxes, +} from './testHelpers'; + +describe("A dapp has permission to suggest transactions for a user's MetaMask account and chain permissions for a user's RPC networks, user's extension becomes password locked", function () { + const SCOPE = 'eip155:1337'; + describe('the dapp sends a request through the Multichain API that requires user confirmation on the permitted account', function () { + it.only('should prompts the user to unlock MetaMask before returning an RPC response to the dapp', async function () { + await withFixtures( + { + title: this.test?.fullTitle(), + fixtures: new FixtureBuilder() + .withNetworkControllerTripleGanache() + .withPermissionControllerConnectedToTestDappMultichain() + .build(), + ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, + }, + async ({ + driver, + extensionId, + }: { + driver: Driver; + extensionId: string; + }) => { + await openMultichainDappAndConnectWalletWithExternallyConnectable( + driver, + extensionId, + ); + await passwordLockMetamaskExtension(driver); + await driver.switchToWindowWithTitle( + WINDOW_TITLES.MultichainTestDApp, + ); + + await driver.clickElement({ + text: 'wallet_createSession', + tag: 'span', + }); + await driver.delay(30_000); + // await driver.delay(100_000); + // await driver.waitUntilXWindowHandles(4, 100000, 150000); + // await driver.waitUntilXWindowHandles(4, 100000, 1500000); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + // TODO: After focus switches to Dialog, assert window is there and defined ? + // TODO: Problem: No window found by background script with title: MetaMask Dialog" always thrown before we see the actual popup extension password prompt window show + }, + ); + }); + }); + + describe('the dapp sends a request through the Multichain API that does NOT require user confirmation', function () { + it('should accept and handle the RPC request & response back to the dapp', async function () { + await withFixtures( + { + title: this.test?.fullTitle(), + fixtures: new FixtureBuilder() + .withNetworkControllerTripleGanache() + .withPermissionControllerConnectedToTestDappMultichain() + .build(), + ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, + }, + async ({ + driver, + extensionId, + }: { + driver: Driver; + extensionId: string; + }) => { + await openMultichainDappAndConnectWalletWithExternallyConnectable( + driver, + extensionId, + ); + await passwordLockMetamaskExtension(driver); + + await driver.switchToWindowWithTitle( + WINDOW_TITLES.MultichainTestDApp, + ); + + const parsedResult = await getSessionScopes(driver); + const sessionScope = parsedResult.sessionScopes[SCOPE]; + const expectedSessionScope = getExpectedSessionScope(SCOPE, [ + ACCOUNT_1, + ]); + + assert.deepStrictEqual( + sessionScope, + expectedSessionScope, + `Should receive result that specifies expected session scopes for ${SCOPE}`, + ); + }, + ); + }); + }); +}); diff --git a/test/e2e/flask/multichain-api/testHelpers.ts b/test/e2e/flask/multichain-api/testHelpers.ts index 76c261caccc0..0c0697107f9b 100644 --- a/test/e2e/flask/multichain-api/testHelpers.ts +++ b/test/e2e/flask/multichain-api/testHelpers.ts @@ -197,6 +197,19 @@ export const updateNetworkCheckboxes = async ( await driver.clickElement({ text: 'Update', tag: 'button' }); }; +/** + * Password locks user's metamask extension. + * + * @param driver - E2E test driver {@link Driver}, wrapping the Selenium WebDriver. + */ +export const passwordLockMetamaskExtension = async ( + driver: Driver, +): Promise => { + await driver.switchToWindowWithTitle(WINDOW_TITLES.ExtensionInFullScreenView); + await driver.clickElementSafe('[data-testid="account-options-menu-button"]'); + await driver.clickElementSafe('[data-testid="global-menu-lock"]'); +}; + /** * Sometimes we need to escape colon character when using {@link Driver.findElement}, otherwise selenium will treat this as an invalid selector. * From 70799998e0df67857806ed80c61966eeb7961199 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Tue, 14 Jan 2025 19:50:43 +0100 Subject: [PATCH 2/8] refactor: minor method rename --- test/e2e/fixture-builder.js | 4 ++-- test/e2e/flask/multichain-api/password-locked.spec.ts | 4 ++-- test/e2e/flask/multichain-api/wallet_createSession.spec.ts | 2 +- test/e2e/flask/multichain-api/wallet_notify.spec.ts | 2 +- test/e2e/run-api-specs-multichain.ts | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/e2e/fixture-builder.js b/test/e2e/fixture-builder.js index a621e3acff61..45d09b574490 100644 --- a/test/e2e/fixture-builder.js +++ b/test/e2e/fixture-builder.js @@ -504,7 +504,7 @@ class FixtureBuilder { }); } - withPermissionControllerConnectedToTestDappMultichain({ + withPermissionControllerConnectedToMultichainTestDapp({ account = '', useLocalhostHostname = false, } = {}) { @@ -551,7 +551,7 @@ class FixtureBuilder { }); } - withPermissionControllerConnectedToTestDappMultichainWithTwoAccounts({ + withPermissionControllerConnectedToMultichainTestDappWithTwoAccounts({ scopes = ['eip155:1337'], }) { const optionalScopes = scopes diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index 1de25e75c3c9..33edd3077143 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -29,7 +29,7 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac title: this.test?.fullTitle(), fixtures: new FixtureBuilder() .withNetworkControllerTripleGanache() - .withPermissionControllerConnectedToTestDappMultichain() + .withPermissionControllerConnectedToMultichainTestDapp() .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, @@ -72,7 +72,7 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac title: this.test?.fullTitle(), fixtures: new FixtureBuilder() .withNetworkControllerTripleGanache() - .withPermissionControllerConnectedToTestDappMultichain() + .withPermissionControllerConnectedToMultichainTestDapp() .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, diff --git a/test/e2e/flask/multichain-api/wallet_createSession.spec.ts b/test/e2e/flask/multichain-api/wallet_createSession.spec.ts index 790931e962ab..8ac76b61a4ef 100644 --- a/test/e2e/flask/multichain-api/wallet_createSession.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_createSession.spec.ts @@ -400,7 +400,7 @@ describe('Multichain API', function () { title: this.test?.fullTitle(), fixtures: new FixtureBuilder() .withNetworkControllerTripleGanache() - .withPermissionControllerConnectedToTestDappMultichainWithTwoAccounts( + .withPermissionControllerConnectedToMultichainTestDappWithTwoAccounts( { scopes: OLD_SCOPES, }, diff --git a/test/e2e/flask/multichain-api/wallet_notify.spec.ts b/test/e2e/flask/multichain-api/wallet_notify.spec.ts index d640c0f1ff54..65b43c7bc2aa 100644 --- a/test/e2e/flask/multichain-api/wallet_notify.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_notify.spec.ts @@ -13,7 +13,7 @@ describe('Calling `eth_subscribe` on a particular network event', function () { { title: this.test?.fullTitle(), fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDappMultichain() + .withPermissionControllerConnectedToMultichainTestDapp() .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, diff --git a/test/e2e/run-api-specs-multichain.ts b/test/e2e/run-api-specs-multichain.ts index 39a73069e398..155c62e16274 100644 --- a/test/e2e/run-api-specs-multichain.ts +++ b/test/e2e/run-api-specs-multichain.ts @@ -289,7 +289,7 @@ async function main() { { dapp: true, fixtures: new FixtureBuilder() - .withPermissionControllerConnectedToTestDappMultichain() + .withPermissionControllerConnectedToMultichainTestDapp() .build(), disableGanache: true, title: 'api-specs-multichain coverage (wallet_invokeMethod)', From 566c7abd658780bce6925573804810edc4e65b4a Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Tue, 14 Jan 2025 20:03:07 +0100 Subject: [PATCH 3/8] refactor: adjust test cases --- .../multichain-api/password-locked.spec.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index 33edd3077143..a27321454479 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -1,29 +1,23 @@ import { strict as assert } from 'assert'; import { ACCOUNT_1, - ACCOUNT_2, - largeDelayMs, - veryLargeDelayMs, WINDOW_TITLES, withFixtures, } from '../../helpers'; import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { - addAccountInWalletAndAuthorize, DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, getExpectedSessionScope, getSessionScopes, - initCreateSessionScopes, openMultichainDappAndConnectWalletWithExternallyConnectable, passwordLockMetamaskExtension, - updateNetworkCheckboxes, } from './testHelpers'; describe("A dapp has permission to suggest transactions for a user's MetaMask account and chain permissions for a user's RPC networks, user's extension becomes password locked", function () { const SCOPE = 'eip155:1337'; describe('the dapp sends a request through the Multichain API that requires user confirmation on the permitted account', function () { - it.only('should prompts the user to unlock MetaMask before returning an RPC response to the dapp', async function () { + it('should prompts the user to unlock MetaMask before returning an RPC response to the dapp', async function () { await withFixtures( { title: this.test?.fullTitle(), @@ -53,13 +47,17 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac text: 'wallet_createSession', tag: 'span', }); - await driver.delay(30_000); - // await driver.delay(100_000); - // await driver.waitUntilXWindowHandles(4, 100000, 150000); - // await driver.waitUntilXWindowHandles(4, 100000, 1500000); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - // TODO: After focus switches to Dialog, assert window is there and defined ? - // TODO: Problem: No window found by background script with title: MetaMask Dialog" always thrown before we see the actual popup extension password prompt window show + + const unlockExtensionPageWebElement = await driver.findElement( + '[data-testid="unlock-page"]', + ); + + assert.ok( + unlockExtensionPageWebElement, + 'Should prompt user to unlock Metamask Extension', + ); }, ); }); From 1520e2530c6c39fdc86397a28161d33331dc43af Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Tue, 14 Jan 2025 20:49:27 +0100 Subject: [PATCH 4/8] chore: format --- test/e2e/flask/multichain-api/password-locked.spec.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index a27321454479..d5e6b1e24d53 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -1,9 +1,5 @@ import { strict as assert } from 'assert'; -import { - ACCOUNT_1, - WINDOW_TITLES, - withFixtures, -} from '../../helpers'; +import { ACCOUNT_1, WINDOW_TITLES, withFixtures } from '../../helpers'; import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { From f9c07f76854cf349b00cc628da4ea17fd1466ac3 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 16 Jan 2025 11:44:51 +0100 Subject: [PATCH 5/8] refactor: code review changes --- .../multichain-api/password-locked.spec.ts | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index d5e6b1e24d53..0b21a7b39cc8 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -4,14 +4,14 @@ import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, + escapeColon, getExpectedSessionScope, getSessionScopes, openMultichainDappAndConnectWalletWithExternallyConnectable, passwordLockMetamaskExtension, } from './testHelpers'; -describe("A dapp has permission to suggest transactions for a user's MetaMask account and chain permissions for a user's RPC networks, user's extension becomes password locked", function () { - const SCOPE = 'eip155:1337'; +describe("A dapp is connected with account and chain permissions previously granted via `wallet_createSession`, user's extension becomes password locked", function () { describe('the dapp sends a request through the Multichain API that requires user confirmation on the permitted account', function () { it('should prompts the user to unlock MetaMask before returning an RPC response to the dapp', async function () { await withFixtures( @@ -39,10 +39,12 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac WINDOW_TITLES.MultichainTestDApp, ); - await driver.clickElement({ - text: 'wallet_createSession', - tag: 'span', - }); + await driver.clickElementSafe( + '[data-testid="wallet:eip155-wallet_addEthereumChain-option"]', + ); + await driver.clickElement( + '[data-testid="invoke-method-wallet:eip155-btn"]', + ); await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); @@ -59,8 +61,10 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac }); }); - describe('the dapp sends a request through the Multichain API that does NOT require user confirmation', function () { - it('should accept and handle the RPC request & response back to the dapp', async function () { + describe('the dapp sends requests through the Multichain API that do NOT require user confirmation', function () { + const SCOPE = 'eip155:1337'; + const CHAIN_ID = '0x539'; + it('should handle the requests without prompting the user to unlock the wallet', async function () { await withFixtures( { title: this.test?.fullTitle(), @@ -93,11 +97,28 @@ describe("A dapp has permission to suggest transactions for a user's MetaMask ac ACCOUNT_1, ]); + await driver.clickElementSafe( + `[data-testid="${SCOPE}-eth_chainId-option"]`, + ); + await driver.clickElementSafe( + `[data-testid="invoke-method-${SCOPE}-btn"]`, + ); + const chainIdResultWebElement = await driver.findElement( + `#invoke-method-${escapeColon(SCOPE)}-eth_chainId-result-0`, + ); + const chainId = await chainIdResultWebElement.getText(); + assert.deepStrictEqual( sessionScope, expectedSessionScope, `Should receive result that specifies expected session scopes for ${SCOPE}`, ); + + assert.deepStrictEqual( + chainId, + `"${CHAIN_ID}"`, + 'Should get expected result from calling eth_chainId', + ); }, ); }); From 271a4a601adb71c1fcf5626287189d9860fe62dd Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Thu, 16 Jan 2025 17:09:30 +0100 Subject: [PATCH 6/8] refactor: address code review improvements --- test/e2e/flask/multichain-api/connect.spec.ts | 10 +-- .../multichain-api/password-locked.spec.ts | 32 +++++++-- test/e2e/flask/multichain-api/testHelpers.ts | 2 + .../wallet_createSession.spec.ts | 66 +++---------------- .../multichain-api/wallet_getSession.spec.ts | 18 +---- .../wallet_invokeMethod.spec.ts | 26 ++------ .../multichain-api/wallet_notify.spec.ts | 10 +-- .../wallet_revokeSession.spec.ts | 18 +---- 8 files changed, 51 insertions(+), 131 deletions(-) diff --git a/test/e2e/flask/multichain-api/connect.spec.ts b/test/e2e/flask/multichain-api/connect.spec.ts index 835df1e32098..16ab380e913c 100644 --- a/test/e2e/flask/multichain-api/connect.spec.ts +++ b/test/e2e/flask/multichain-api/connect.spec.ts @@ -8,9 +8,9 @@ import { WINDOW_TITLES, withFixtures, } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; +import type { FixtureCallbackArgs } from './testHelpers'; describe('Multichain API', function () { it('should connect the wallet to the multichain test dapp via `externally_connectable` and successfully create a session with the requested chains', async function () { @@ -30,13 +30,7 @@ describe('Multichain API', function () { fixtures: new FixtureBuilder().withPopularNetworks().build(), title: this.test?.fullTitle(), }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await unlockWallet(driver); await openDapp(driver, undefined, DAPP_URL); diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index 0b21a7b39cc8..3fefcd943286 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -5,6 +5,7 @@ import FixtureBuilder from '../../fixture-builder'; import { DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, escapeColon, + type FixtureCallbackArgs, getExpectedSessionScope, getSessionScopes, openMultichainDappAndConnectWalletWithExternallyConnectable, @@ -26,10 +27,7 @@ describe("A dapp is connected with account and chain permissions previously gran async ({ driver, extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -39,6 +37,28 @@ describe("A dapp is connected with account and chain permissions previously gran WINDOW_TITLES.MultichainTestDApp, ); + await driver.clickElementSafe( + '[data-testid="eip155:1337-eth_sendTransaction-option"]', + ); + await driver.clickElement( + '[data-testid="invoke-method-eip155:1337-btn"]', + ); + + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + + const unlockExtensionPageWebElement0 = await driver.findElement( + '[data-testid="unlock-page"]', + ); + + assert.ok( + unlockExtensionPageWebElement0, + 'Should prompt user to unlock Metamask Extension', + ); + + await driver.switchToWindowWithTitle( + WINDOW_TITLES.MultichainTestDApp, + ); + await driver.clickElementSafe( '[data-testid="wallet:eip155-wallet_addEthereumChain-option"]', ); @@ -48,12 +68,12 @@ describe("A dapp is connected with account and chain permissions previously gran await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); - const unlockExtensionPageWebElement = await driver.findElement( + const unlockExtensionPageWebElement1 = await driver.findElement( '[data-testid="unlock-page"]', ); assert.ok( - unlockExtensionPageWebElement, + unlockExtensionPageWebElement1, 'Should prompt user to unlock Metamask Extension', ); }, diff --git a/test/e2e/flask/multichain-api/testHelpers.ts b/test/e2e/flask/multichain-api/testHelpers.ts index 0c0697107f9b..1128a48fa0cf 100644 --- a/test/e2e/flask/multichain-api/testHelpers.ts +++ b/test/e2e/flask/multichain-api/testHelpers.ts @@ -16,6 +16,8 @@ import { } from '../../helpers'; import { Driver } from '../../webdriver/driver'; +export type FixtureCallbackArgs = { driver: Driver; extensionId: string }; + /** * Default options for setting up Multichain E2E test environment */ diff --git a/test/e2e/flask/multichain-api/wallet_createSession.spec.ts b/test/e2e/flask/multichain-api/wallet_createSession.spec.ts index 8ac76b61a4ef..33a282d73759 100644 --- a/test/e2e/flask/multichain-api/wallet_createSession.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_createSession.spec.ts @@ -8,7 +8,6 @@ import { ACCOUNT_1, ACCOUNT_2, } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { initCreateSessionScopes, @@ -18,6 +17,7 @@ import { getExpectedSessionScope, addAccountInWalletAndAuthorize, updateNetworkCheckboxes, + type FixtureCallbackArgs, } from './testHelpers'; describe('Multichain API', function () { @@ -31,13 +31,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { const scopesToIgnore = ['eip155:1338', 'eip155:1000']; await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, @@ -77,13 +71,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { const REQUEST_SCOPE = 'eip155:1337'; /** * check {@link FixtureBuilder.withTrezorAccount} for second injected account address. @@ -136,13 +124,7 @@ describe('Multichain API', function () { fixtures: new FixtureBuilder().withPopularNetworks().build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { const requestScopesToNetworkMap = { 'eip155:1': 'Ethereum Mainnet', 'eip155:59141': 'Linea Sepolia', @@ -204,13 +186,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -259,13 +235,7 @@ describe('Multichain API', function () { fixtures: new FixtureBuilder().build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -304,13 +274,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -346,13 +310,7 @@ describe('Multichain API', function () { fixtures: new FixtureBuilder().build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -409,13 +367,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, diff --git a/test/e2e/flask/multichain-api/wallet_getSession.spec.ts b/test/e2e/flask/multichain-api/wallet_getSession.spec.ts index c4c1da5f7a53..065829eb48be 100644 --- a/test/e2e/flask/multichain-api/wallet_getSession.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_getSession.spec.ts @@ -1,6 +1,5 @@ import { strict as assert } from 'assert'; import { withFixtures } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { DEFAULT_FIXTURE_ACCOUNT } from '../../constants'; import { @@ -8,6 +7,7 @@ import { getExpectedSessionScope, getSessionScopes, openMultichainDappAndConnectWalletWithExternallyConnectable, + type FixtureCallbackArgs, } from './testHelpers'; describe('Multichain API', function () { @@ -19,13 +19,7 @@ describe('Multichain API', function () { fixtures: new FixtureBuilder().withPopularNetworks().build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -53,13 +47,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { /** * check {@link FixtureBuilder.withPermissionControllerConnectedToTestDapp} for default scopes returned */ diff --git a/test/e2e/flask/multichain-api/wallet_invokeMethod.spec.ts b/test/e2e/flask/multichain-api/wallet_invokeMethod.spec.ts index 9d8e19753221..172f029ac463 100644 --- a/test/e2e/flask/multichain-api/wallet_invokeMethod.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_invokeMethod.spec.ts @@ -7,7 +7,6 @@ import { WINDOW_TITLES, withFixtures, } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { DEFAULT_GANACHE_ETH_BALANCE_DEC } from '../../constants'; import { @@ -16,6 +15,7 @@ import { openMultichainDappAndConnectWalletWithExternallyConnectable, addAccountInWalletAndAuthorize, escapeColon, + type FixtureCallbackArgs, } from './testHelpers'; describe('Multichain API', function () { @@ -36,13 +36,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -105,13 +99,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -176,13 +164,7 @@ describe('Multichain API', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, diff --git a/test/e2e/flask/multichain-api/wallet_notify.spec.ts b/test/e2e/flask/multichain-api/wallet_notify.spec.ts index 65b43c7bc2aa..e0d8e699d916 100644 --- a/test/e2e/flask/multichain-api/wallet_notify.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_notify.spec.ts @@ -1,9 +1,9 @@ import { strict as assert } from 'assert'; import { withFixtures } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, + type FixtureCallbackArgs, openMultichainDappAndConnectWalletWithExternallyConnectable, } from './testHelpers'; @@ -17,13 +17,7 @@ describe('Calling `eth_subscribe` on a particular network event', function () { .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, diff --git a/test/e2e/flask/multichain-api/wallet_revokeSession.spec.ts b/test/e2e/flask/multichain-api/wallet_revokeSession.spec.ts index 1793f0e30f83..dcef54de2cd2 100644 --- a/test/e2e/flask/multichain-api/wallet_revokeSession.spec.ts +++ b/test/e2e/flask/multichain-api/wallet_revokeSession.spec.ts @@ -7,7 +7,6 @@ import { WINDOW_TITLES, withFixtures, } from '../../helpers'; -import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { initCreateSessionScopes, @@ -15,6 +14,7 @@ import { openMultichainDappAndConnectWalletWithExternallyConnectable, addAccountInWalletAndAuthorize, getSessionScopes, + type FixtureCallbackArgs, } from './testHelpers'; describe('Initializing a session w/ several scopes and accounts, then calling `wallet_revokeSession`', function () { @@ -29,13 +29,7 @@ describe('Initializing a session w/ several scopes and accounts, then calling `w .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -82,13 +76,7 @@ describe('Initializing a session w/ several scopes and accounts, then calling `w .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: { - driver: Driver; - extensionId: string; - }) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, From ee19aa6db68178acea6e1cbc748b71b2aa857419 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Fri, 17 Jan 2025 11:04:07 +0100 Subject: [PATCH 7/8] test: extra assertions after unlock extension --- .../multichain-api/password-locked.spec.ts | 53 +++++++++++++++++-- 1 file changed, 48 insertions(+), 5 deletions(-) diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index 3fefcd943286..2b75ba17c214 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -1,5 +1,10 @@ import { strict as assert } from 'assert'; -import { ACCOUNT_1, WINDOW_TITLES, withFixtures } from '../../helpers'; +import { + ACCOUNT_1, + WALLET_PASSWORD, + WINDOW_TITLES, + withFixtures, +} from '../../helpers'; import { Driver } from '../../webdriver/driver'; import FixtureBuilder from '../../fixture-builder'; import { @@ -24,10 +29,7 @@ describe("A dapp is connected with account and chain permissions previously gran .build(), ...DEFAULT_MULTICHAIN_TEST_DAPP_FIXTURE_OPTIONS, }, - async ({ - driver, - extensionId, - }: FixtureCallbackArgs) => { + async ({ driver, extensionId }: FixtureCallbackArgs) => { await openMultichainDappAndConnectWalletWithExternallyConnectable( driver, extensionId, @@ -55,6 +57,31 @@ describe("A dapp is connected with account and chain permissions previously gran 'Should prompt user to unlock Metamask Extension', ); + /** + * We unlock metamask extension to assert a transfer request is being made + */ + await driver.fill('[data-testid="unlock-password"]', WALLET_PASSWORD); + await driver.clickElementSafe('[data-testid="unlock-submit"]'); + + const transferRequestWebElement = await driver.findElement({ + text: 'Transfer request', + type: 'h3', + }); + + assert.ok( + transferRequestWebElement, + 'Should be attempting to make via wallet extension transfer', + ); + + await driver.clickElementSafe( + '[data-testid="confirm-footer-cancel-button"]', + ); + + /** + * We lock extension again to repeat action and assertion for `wallet_addEthereumChain` + */ + await passwordLockMetamaskExtension(driver); + await driver.switchToWindowWithTitle( WINDOW_TITLES.MultichainTestDApp, ); @@ -76,6 +103,22 @@ describe("A dapp is connected with account and chain permissions previously gran unlockExtensionPageWebElement1, 'Should prompt user to unlock Metamask Extension', ); + + /** + * We unlock metamask extension to assert a request for adding chain is being made + */ + await driver.fill('[data-testid="unlock-password"]', WALLET_PASSWORD); + await driver.clickElementSafe('[data-testid="unlock-submit"]'); + + const addChainWebElement = await driver.findElement({ + text: 'Add Gnosis', + type: 'h3', + }); + + assert.ok( + addChainWebElement, + 'Should be attempting to add Gnosis Chain', + ); }, ); }); From 8adc7127e4aa1819b0cf39097ea25d576c52fef9 Mon Sep 17 00:00:00 2001 From: ffmcgee Date: Fri, 17 Jan 2025 16:43:36 +0100 Subject: [PATCH 8/8] refactor: minor test description adjustment --- test/e2e/flask/multichain-api/password-locked.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/flask/multichain-api/password-locked.spec.ts b/test/e2e/flask/multichain-api/password-locked.spec.ts index 2b75ba17c214..578c2d567913 100644 --- a/test/e2e/flask/multichain-api/password-locked.spec.ts +++ b/test/e2e/flask/multichain-api/password-locked.spec.ts @@ -19,7 +19,7 @@ import { describe("A dapp is connected with account and chain permissions previously granted via `wallet_createSession`, user's extension becomes password locked", function () { describe('the dapp sends a request through the Multichain API that requires user confirmation on the permitted account', function () { - it('should prompts the user to unlock MetaMask before returning an RPC response to the dapp', async function () { + it('should prompts the user to unlock MetaMask before showing the request confirmation', async function () { await withFixtures( { title: this.test?.fullTitle(),