diff --git a/packages/fixtures/package.json b/packages/fixtures/package.json index eb89b28e7..0dd56c4aa 100644 --- a/packages/fixtures/package.json +++ b/packages/fixtures/package.json @@ -28,6 +28,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@viem/anvil": "^0.0.6", "core": "workspace:*", "fs-extra": "^11.1.1", "zod": "^3.22.4" diff --git a/packages/fixtures/src/fixtures/testWithSynpress.ts b/packages/fixtures/src/fixtures/testWithSynpress.ts index 6fd0d85fb..3df78344f 100644 --- a/packages/fixtures/src/fixtures/testWithSynpress.ts +++ b/packages/fixtures/src/fixtures/testWithSynpress.ts @@ -8,6 +8,7 @@ import type { PlaywrightWorkerOptions } from '@playwright/test' import { chromium, test as base } from '@playwright/test' +import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil' import { defineWalletSetup } from 'core' import { createTempContextDir, removeTempContextDir } from 'core' import { CACHE_DIR_NAME, prepareExtension } from 'core' @@ -27,6 +28,7 @@ type PrivateSynpressFixtures = { type PublicSynpressFixtures = { extensionId: string metamaskPage: Page + createAnvilNode: (options?: CreateAnvilOptions) => Promise<{ anvil: Anvil; rpcUrl: string; chainId: number }> } type SynpressFixtures = TestFixtures & PrivateSynpressFixtures & PublicSynpressFixtures @@ -101,6 +103,26 @@ const synpressFixtures = ( }, metamaskPage: async ({ context: _ }, use) => { await use(_metamaskPage) + }, + // TODO: We should be able to use this in a wallet setup. This will be possible when we add a store. + // TODO: ^ Thanks to this we won't have to rely on MetaMask RPC for initial connection, which will increase the speed of the tests. + createAnvilNode: async ({ context: _ }, use) => { + const pool = createPool() + + await use(async (options?: CreateAnvilOptions) => { + const nodeId = Array.from(pool.instances()).length + // const anvil = await pool.start(nodeId, options) + const anvil = await pool.start(nodeId, options) + + const rpcUrl = `http://${anvil.host}:${anvil.port}` + + const DEFAULT_ANVIL_CHAIN_ID = 31337 + const chainId = options?.chainId ?? DEFAULT_ANVIL_CHAIN_ID + + return { anvil, rpcUrl, chainId } + }) + + await pool.empty() } }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5a5b16a35..025ca844d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -128,6 +128,9 @@ importers: '@playwright/test': specifier: 1.40.0 version: 1.40.0 + '@viem/anvil': + specifier: ^0.0.6 + version: 0.0.6 core: specifier: workspace:* version: link:../core @@ -1035,6 +1038,19 @@ packages: '@types/node': 20.8.0 dev: false + /@viem/anvil@0.0.6: + resolution: {integrity: sha512-OjKR/+FVwzuygXYFqP8MBal1SXG8bT2gbZwqqB0XuLw81LNBBvmE/Repm6+5kkBh4IUj0PhYdrqOsnayS14Gtg==} + dependencies: + execa: 7.2.0 + get-port: 6.1.2 + http-proxy: 1.18.1 + ws: 8.13.0 + transitivePeerDependencies: + - bufferutil + - debug + - utf-8-validate + dev: false + /@vitest/coverage-v8@1.0.0-beta.0(vitest@0.34.6): resolution: {integrity: sha512-99UphBlabZql1OLE+fF/S3uOtDSGhfpOFOnhSh+gAqWKi+XhsDBqV1qbZyn/98hNKIiNxzwjV5Yl3WudErDyoQ==} peerDependencies: @@ -1845,6 +1861,10 @@ packages: - utf-8-validate dev: false + /eventemitter3@4.0.7: + resolution: {integrity: sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw==} + dev: false + /eventemitter3@5.0.1: resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} dev: true @@ -1881,7 +1901,6 @@ packages: onetime: 6.0.0 signal-exit: 3.0.7 strip-final-newline: 3.0.0 - dev: true /ext-list@2.2.2: resolution: {integrity: sha512-u+SQgsubraE6zItfVA0tBuCBhfU9ogSRnsvygI7wht9TS510oLkBRXBsqopeUG/GBOIQyKZO9wjTqIu/sf5zFA==} @@ -2091,6 +2110,11 @@ packages: has-symbols: 1.0.3 dev: true + /get-port@6.1.2: + resolution: {integrity: sha512-BrGGraKm2uPqurfGVj/z97/zv8dPleC6x9JBNRTrDNtCkkRF4rPwrQXFgL7+I+q8QSdU4ntLQX2D7KIxSy8nGw==} + engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} + dev: false + /get-stdin@9.0.0: resolution: {integrity: sha512-dVKBjfWisLAicarI2Sf+JuBE/DghV4UzNAVe9yhEJuzeREd3JhOTE9cUaJTeSa77fsbQUK3pcOpJfM59+VKZaA==} engines: {node: '>=12'} @@ -2291,6 +2315,17 @@ packages: resolution: {integrity: sha512-5ai2iksyV8ZXmnZhHH4rWPoxxistEexSi5936zIQ1bnNTW5VnA85B6P/VpXiRM017IgRvb2kKo1a//y+0wSp3w==} dev: false + /http-proxy@1.18.1: + resolution: {integrity: sha512-7mz/721AbnJwIVbnaSv1Cz3Am0ZLT/UBwkC92VlxhXv/k/BBQfM2fXElQNC27BVGr0uwUpplYPQM9LnaBMR5NQ==} + engines: {node: '>=8.0.0'} + dependencies: + eventemitter3: 4.0.7 + follow-redirects: 1.15.3(debug@4.3.4) + requires-port: 1.0.0 + transitivePeerDependencies: + - debug + dev: false + /human-signals@2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} @@ -2298,7 +2333,6 @@ packages: /human-signals@4.3.1: resolution: {integrity: sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==} engines: {node: '>=14.18.0'} - dev: true /husky@8.0.3: resolution: {integrity: sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==} @@ -2456,7 +2490,6 @@ packages: /is-stream@3.0.0: resolution: {integrity: sha512-LnQR4bZ9IADDRSkvpqMGvt/tEJWclzklNgSw48V5EAaAeDd6qGvN8ei6k5p0tvxSR171VmGyHuTiAOfxAbr8kA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} - dev: true /is-typed-array@1.1.12: resolution: {integrity: sha512-Z14TF2JNG8Lss5/HMqt0//T9JeHXttXy5pH/DBU4vi98ozO2btxzq9MwYDZYnKwU8nRsz/+GVFVRDq3DkVuSPg==} @@ -2781,7 +2814,6 @@ packages: /mimic-fn@4.0.0: resolution: {integrity: sha512-vqiC06CuhBTUdZH+RYl8sFrL096vA45Ok5ISO6sE/Mr1jRbGH4Csnhi8f3wKVl7x8mO4Au7Ir9D3Oyv1VYMFJw==} engines: {node: '>=12'} - dev: true /mimic-response@1.0.1: resolution: {integrity: sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==} @@ -2921,7 +2953,6 @@ packages: engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} dependencies: path-key: 4.0.0 - dev: true /object-assign@4.1.1: resolution: {integrity: sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==} @@ -2943,7 +2974,6 @@ packages: engines: {node: '>=12'} dependencies: mimic-fn: 4.0.0 - dev: true /ora@5.4.1: resolution: {integrity: sha512-5b6Y85tPxZZ7QytO+BQzysW31HJku27cRIlkbAXaNx+BdcVi+LlRFmVXzeF6a7JCwJpyw5c4b+YSVImQIrBpuQ==} @@ -3016,7 +3046,6 @@ packages: /path-key@4.0.0: resolution: {integrity: sha512-haREypq7xkM7ErfgIyA0z+Bj4AGKlMSdlQE2jvJo6huWD1EdkKYV+G/T4nq0YEF2vgTT8kqMFKo1uHn950r4SQ==} engines: {node: '>=12'} - dev: true /path-scurry@1.10.1: resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} @@ -3250,6 +3279,10 @@ packages: engines: {node: '>=0.10.0'} dev: true + /requires-port@1.0.0: + resolution: {integrity: sha512-KigOCHcocU3XODJxsu8i/j8T9tzT4adHiecwORRQ0ZZFcp7ahwXuRU1m+yuO90C5ZUyGeGfocHDI14M3L3yDAQ==} + dev: false + /resolve-from@5.0.0: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} @@ -3545,7 +3578,6 @@ packages: /strip-final-newline@3.0.0: resolution: {integrity: sha512-dOESqjYr96iWYylGObzd39EuNTa5VJxyvVAEm5Jnh7KGo75V43Hk1odPQkNDyXNmUR6k+gEiDVXnjB8HJ3crXw==} engines: {node: '>=12'} - dev: true /strip-literal@1.3.0: resolution: {integrity: sha512-PugKzOsyXpArk0yWmUwqOZecSO0GH0bPoctLcqNDH9J04pVW3lflYE0ujElBGTloevcxF5MofAOZ7C5l2b+wLg==} diff --git a/wallets/metamask/playwright.config.ts b/wallets/metamask/playwright.config.ts index 0ee01292d..4fcfbc5de 100644 --- a/wallets/metamask/playwright.config.ts +++ b/wallets/metamask/playwright.config.ts @@ -7,6 +7,10 @@ export default defineConfig({ // Look for test files in the "test/e2e" directory, relative to this configuration file. testDir: './test/e2e', + // We're increasing the timeout to 60 seconds to allow all traces to be recorded. + // Sometimes it threw an error saying that traces were not recorded in the 30 seconds timeout limit. + timeout: 60_000, + // Run all tests in parallel. fullyParallel: true, diff --git a/wallets/metamask/src/fixture-actions/unlockForFixture.ts b/wallets/metamask/src/fixture-actions/unlockForFixture.ts index 47eaeaaa2..3975477b0 100644 --- a/wallets/metamask/src/fixture-actions/unlockForFixture.ts +++ b/wallets/metamask/src/fixture-actions/unlockForFixture.ts @@ -10,6 +10,7 @@ export async function unlockForFixture(page: Page, password: string) { await metamask.unlock() + // TODO: If this function times out -> page.reload() and try again. await waitForSpinnerToVanish(page) await retryIfMetaMaskCrashAfterUnlock(page) diff --git a/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts b/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts index 336b0c14e..c4487f519 100644 --- a/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts +++ b/wallets/metamask/test/e2e/metamask/addNetwork.spec.ts @@ -9,7 +9,7 @@ const test = testWithSynpress(basicSetup, unlockForFixture) const { expect } = test -const network = { +const optimismMainnet = { name: 'OP Mainnet', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, @@ -17,14 +17,24 @@ const network = { blockExplorerUrl: 'https://optimistic.etherscan.io' } -test('should add network and close network added popup', async ({ context, metamaskPage }) => { +test('should add network and close network added popup', async ({ context, metamaskPage, createAnvilNode }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) + const { rpcUrl, chainId } = await createAnvilNode() + + const network = { + name: 'Anvil', + rpcUrl, + chainId, + symbol: 'ETH', + blockExplorerUrl: 'https://etherscan.io/' + } + await metamask.addNetwork(network) const isNetworkAddedPopupVisible = await waitFor( () => metamaskPage.locator(metamask.homePage.selectors.networkAddedPopover.switchToNetworkButton).isVisible(), - 1_000, + 3_000, false ) expect(isNetworkAddedPopupVisible).toBe(false) @@ -32,13 +42,20 @@ test('should add network and close network added popup', async ({ context, metam await expect(metamaskPage.locator(metamask.homePage.selectors.currentNetwork)).toHaveText(network.name) }) -test('should add network without block explorer', async ({ context, metamaskPage }) => { +test('should add network without block explorer', async ({ context, metamaskPage, createAnvilNode }) => { const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) - await metamask.addNetwork({ - ...network, + const { rpcUrl, chainId } = await createAnvilNode() + + const network = { + name: 'Anvil', + rpcUrl, + chainId, + symbol: 'ETH', blockExplorerUrl: undefined - }) + } + + await metamask.addNetwork(network) await expect(metamaskPage.locator(metamask.homePage.selectors.currentNetwork)).toHaveText(network.name) }) @@ -54,7 +71,7 @@ test('should throw if there is an issue with rpc url', async ({ context, metamas const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) const promise = metamask.addNetwork({ - ...network, + ...optimismMainnet, rpcUrl: 'hps://mainnet.optimism.io' // Incorrect. }) @@ -67,7 +84,7 @@ test('should throw if there is an issue with chain id', async ({ context, metama const metamask = new MetaMask(context, metamaskPage, basicSetup.walletPassword) const promise = metamask.addNetwork({ - ...network, + ...optimismMainnet, chainId: 0x42069 // Incorrect. }) diff --git a/wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts b/wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts index 70f286882..af96e4e69 100644 --- a/wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts +++ b/wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts @@ -4,7 +4,12 @@ const test = testWithMetaMask const { expect } = test -test('should add a new network', async ({ page, metamask }) => { +test('should add a new network', async ({ page, metamask, createAnvilNode }) => { + await createAnvilNode({ + chainId: 1338, + port: 8546 + }) + await page.locator('#addEthereumChain').click() await metamask.approveNewNetwork() diff --git a/wallets/metamask/test/e2e/metamask/approvePermission.spec.ts b/wallets/metamask/test/e2e/metamask/approvePermission.spec.ts index c3d0ed790..8c59be591 100644 --- a/wallets/metamask/test/e2e/metamask/approvePermission.spec.ts +++ b/wallets/metamask/test/e2e/metamask/approvePermission.spec.ts @@ -1,14 +1,11 @@ import { testWithMetaMask } from '../testWithMetaMask' const test = testWithMetaMask.extend<{ - switchChainAndDeployToken: () => Promise + deployToken: () => Promise }>({ - switchChainAndDeployToken: async ({ page, metamask }, use) => { + deployToken: async ({ page, metamask, connectToAnvil }, use) => { await use(async () => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() + await connectToAnvil() await expect(page.locator('#tokenAddresses')).toBeEmpty() await page.locator('#createToken').click() @@ -20,31 +17,24 @@ const test = testWithMetaMask.extend<{ const { expect } = test -// These tests rely on the same account, which means they must be run in serial. -test.describe.configure({ mode: 'serial' }) - -test('should approve tokens with the default limit by default', async ({ - page, - metamask, - switchChainAndDeployToken -}) => { - await switchChainAndDeployToken() +test('should approve tokens with the default limit by default', async ({ page, metamask, deployToken }) => { + await deployToken() await page.locator('#approveTokens').click() await metamask.approvePermission() }) -test('should approve tokens with the max limit', async ({ page, metamask, switchChainAndDeployToken }) => { - await switchChainAndDeployToken() +test('should approve tokens with the max limit', async ({ page, metamask, deployToken }) => { + await deployToken() await page.locator('#approveTokens').click() await metamask.approvePermission('max') }) -test('should approve tokens with the custom limit', async ({ page, metamask, switchChainAndDeployToken }) => { - await switchChainAndDeployToken() +test('should approve tokens with the custom limit', async ({ page, metamask, deployToken }) => { + await deployToken() await page.locator('#approveTokens').click() diff --git a/wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts b/wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts index 59119f657..dbaaa93cb 100644 --- a/wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts +++ b/wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts @@ -2,24 +2,24 @@ import { testWithMetaMask } from '../testWithMetaMask' const test = testWithMetaMask -const { expect, describe } = test - -describe('when adding a new network', () => { - test('should switch to the new network', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() - - await expect(page.locator('#chainId')).toHaveText('0x53a') - }) -}) - -test('should switch to the requested network', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.rejectSwitchNetwork() +const { expect } = test + +/// TODO: It's impossible to enable this test and run it in parallel with other tests using MetaMask Test Dapp due to port conflict. +// describe('when adding a new network', () => { +// test('should switch to the new network', async ({ page, metamask }) => { +// await page.locator('#addEthereumChain').click() +// +// await metamask.approveNewNetwork() +// await metamask.approveSwitchNetwork() +// +// await expect(page.locator('#chainId')).toHaveText('0x53a') +// }) +// }) + +test('should switch to the requested network', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() + + await metamask.switchNetwork('Ethereum Mainnet') await expect(page.locator('#chainId')).toHaveText('0x1') diff --git a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts index 2ffc4caa8..1dc335708 100644 --- a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts +++ b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts @@ -4,14 +4,8 @@ const test = testWithMetaMask const { expect } = test -// These tests rely on the same account, which means they must be run in serial. -test.describe.configure({ mode: 'serial' }) - -test('should confirm contract deployment', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test('should confirm contract deployment', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await expect(page.locator('#tokenAddresses')).toBeEmpty() await page.locator('#createToken').click() @@ -21,22 +15,16 @@ test('should confirm contract deployment', async ({ page, metamask }) => { await expect(page.locator('#tokenAddresses')).toContainText(/^0x/) }) -test('should confirm legacy transaction', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test('should confirm legacy transaction', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await page.locator('#sendButton').click() await metamask.confirmTransaction() }) -test('should confirm EIP 1559 transaction', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test('should confirm EIP 1559 transaction', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await page.locator('#sendEIP1559Button').click() diff --git a/wallets/metamask/test/e2e/metamask/confirmTransactionAndWaitForMining.spec.ts b/wallets/metamask/test/e2e/metamask/confirmTransactionAndWaitForMining.spec.ts index 09aeccda9..8f8f90317 100644 --- a/wallets/metamask/test/e2e/metamask/confirmTransactionAndWaitForMining.spec.ts +++ b/wallets/metamask/test/e2e/metamask/confirmTransactionAndWaitForMining.spec.ts @@ -4,16 +4,10 @@ const test = testWithMetaMask const { expect } = test -// These tests rely on the same account, which means they must be run in serial. -test.describe.configure({ mode: 'serial' }) +// ⚠️ Note: These tests are skipped because they are extremely slow. -// ⚠️ Note: These tests are skipped because they are all extremely slow and flaky. - -test.skip('should confirm contract deployment and wait for mining', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test.skip('should confirm contract deployment and wait for mining', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await expect(page.locator('#tokenAddresses')).toBeEmpty() await page.locator('#createToken').click() @@ -23,36 +17,27 @@ test.skip('should confirm contract deployment and wait for mining', async ({ pag await expect(page.locator('#tokenAddresses')).toContainText(/^0x/) }) -test.skip('should confirm legacy transaction and wait for mining', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test.skip('should confirm legacy transaction and wait for mining', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await page.locator('#sendButton').click() await metamask.experimental.confirmTransactionAndWaitForMining() }) -test.skip('should confirm EIP 1559 transaction and wait for mining', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test.skip('should confirm EIP 1559 transaction and wait for mining', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await page.locator('#sendEIP1559Button').click() await metamask.experimental.confirmTransactionAndWaitForMining() }) -test.skip('should work correctly when calling sequentially', async ({ page, metamask }) => { +test.skip('should work correctly when calling sequentially', async ({ page, metamask, connectToAnvil }) => { // This test takes a looooooooong time, so we need to increase the test timeout. test.setTimeout(120_000) - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() + await connectToAnvil() await page.locator('#sendEIP1559Button').click() await metamask.experimental.confirmTransactionAndWaitForMining() diff --git a/wallets/metamask/test/e2e/metamask/rejectPermission.spec.ts b/wallets/metamask/test/e2e/metamask/rejectPermission.spec.ts index 5e27d731e..0aa0fad0f 100644 --- a/wallets/metamask/test/e2e/metamask/rejectPermission.spec.ts +++ b/wallets/metamask/test/e2e/metamask/rejectPermission.spec.ts @@ -4,11 +4,8 @@ const test = testWithMetaMask const { expect } = test -test('should reject approve request', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test('should reject approve request', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await expect(page.locator('#tokenAddresses')).toBeEmpty() await page.locator('#createToken').click() diff --git a/wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts b/wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts index 2887b77cc..5eb1ff5a6 100644 --- a/wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts +++ b/wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts @@ -2,24 +2,24 @@ import { testWithMetaMask } from '../testWithMetaMask' const test = testWithMetaMask -const { expect, describe } = test - -describe('when adding a new network', () => { - test('should reject switch network request', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.rejectSwitchNetwork() - - await expect(page.locator('#chainId')).toHaveText('0x1') - }) -}) - -test('should reject switch network request', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.rejectSwitchNetwork() +const { expect } = test + +/// TODO: It's impossible to enable this test and run it in parallel with other tests using MetaMask Test Dapp due to port conflict. +// describe('when adding a new network', () => { +// test('should reject switch network request', async ({ page, metamask }) => { +// await page.locator('#addEthereumChain').click() +// +// await metamask.approveNewNetwork() +// await metamask.rejectSwitchNetwork() +// +// await expect(page.locator('#chainId')).toHaveText('0x1') +// }) +// }) + +test('should reject switch network request', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() + + await metamask.switchNetwork('Ethereum Mainnet') await expect(page.locator('#chainId')).toHaveText('0x1') diff --git a/wallets/metamask/test/e2e/metamask/rejectTransaction.spec.ts b/wallets/metamask/test/e2e/metamask/rejectTransaction.spec.ts index 54ff290a7..7a889ce11 100644 --- a/wallets/metamask/test/e2e/metamask/rejectTransaction.spec.ts +++ b/wallets/metamask/test/e2e/metamask/rejectTransaction.spec.ts @@ -4,11 +4,8 @@ const test = testWithMetaMask const { expect } = test -test('should reject contract deployment', async ({ page, metamask }) => { - await page.locator('#addEthereumChain').click() - - await metamask.approveNewNetwork() - await metamask.approveSwitchNetwork() +test('should reject contract deployment', async ({ page, metamask, connectToAnvil }) => { + await connectToAnvil() await expect(page.locator('#tokenAddresses')).toBeEmpty() await page.locator('#createToken').click() diff --git a/wallets/metamask/test/e2e/testWithMetaMask.ts b/wallets/metamask/test/e2e/testWithMetaMask.ts index 1de41b745..aad714d2d 100644 --- a/wallets/metamask/test/e2e/testWithMetaMask.ts +++ b/wallets/metamask/test/e2e/testWithMetaMask.ts @@ -3,7 +3,10 @@ import { MetaMask, unlockForFixture } from '../../src' import connectedSetup from './wallet-setup/connected.setup' -export const testWithMetaMask = testWithSynpress(connectedSetup, unlockForFixture).extend<{ metamask: MetaMask }>({ +export const testWithMetaMask = testWithSynpress(connectedSetup, unlockForFixture).extend<{ + metamask: MetaMask + connectToAnvil: () => Promise +}>({ metamask: async ({ context, metamaskPage, extensionId }, use) => { const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId) @@ -13,5 +16,20 @@ export const testWithMetaMask = testWithSynpress(connectedSetup, unlockForFixtur await page.goto('https://metamask.github.io/test-dapp/') await use(page) + }, + connectToAnvil: async ({ metamask, createAnvilNode }, use) => { + await use(async () => { + const { rpcUrl, chainId } = await createAnvilNode({ + chainId: 1338 + }) + + await metamask.addNetwork({ + name: 'Anvil', + rpcUrl, + chainId, + symbol: 'ETH', + blockExplorerUrl: 'https://etherscan.io/' + }) + }) } })