From 745f381f108d7549a398a342c7d2def7dcef4e4c Mon Sep 17 00:00:00 2001 From: "r3kt.eth" Date: Mon, 21 Aug 2023 00:44:36 +0200 Subject: [PATCH 01/19] add foundry support Signed-off-by: r3kt.eth --- commands/foundry.js | 169 ++++++++++++++++++++++++++++++++++++++++++++ plugins/index.js | 7 ++ support/commands.js | 22 ++++++ support/index.d.ts | 39 +++++++++- 4 files changed, 234 insertions(+), 3 deletions(-) create mode 100644 commands/foundry.js diff --git a/commands/foundry.js b/commands/foundry.js new file mode 100644 index 000000000..e16fec667 --- /dev/null +++ b/commands/foundry.js @@ -0,0 +1,169 @@ +const { findNetwork } = require('../helpers'); + +const log = require('debug')('synpress:foundry'); + +module.exports = { + async forkChains(options) { + await module.exports.installFoundry(options.foundryCommit); + + if (typeof options === 'object') { + const chains = await module.exports.runAnvil(options.chainsToFork); + + let viemClients = {}; + for (const [chain, options] of Object.entries(chains)) { + log(`Setting up ${chain}`); + viemClients.chain = await module.exports.setupViem( + options.anvilClientDetails.anvilChainType, + ); + } + + return { + chains, + viemClients, + }; + } else if (typeof options === 'string') { + if (isNaN(options)) { + // todo: add support for: + // (multiple) network IDs + // (single) network name + // (multiple) network names + } else { + // todo: add support for: + // (single) network ID + } + } + }, + async setupViem(anvilChainType) { + try { + const { + createTestClient, + createPublicClient, + createWalletClient, + http, + } = require('viem'); + + const testClient = createTestClient({ + chain: anvilChainType, + mode: 'anvil', + transport: http(), + }); + + const publicClient = createPublicClient({ + chain: anvilChainType, + transport: http(), + }); + + const walletClient = createWalletClient({ + chain: anvilChainType, + transport: http(), + }); + + return { testClient, publicClient, walletClient }; + } catch (error) { + throw new Error('There was an error while trying to setup Viem.', error); + } + }, + async runAnvil(chains) { + const { ethers } = require('ethers'); + const anvilClient = await import('@viem/anvil'); + try { + const pool = anvilClient.createPool(); + + for (const [index, [chain, options]] of Object.entries( + Object.entries(chains), + )) { + // use fork url if provided, if not then find it in presets + const forkUrl = + options.forkUrl || (await findNetwork(chain)).rpcUrls.public.http[0]; + + const poolOptions = { + ...options, + forkUrl, + }; + + // remove nativeCurrency because its not supported by anvil + if (poolOptions.nativeCurrency) { + delete poolOptions.nativeCurrency; + } + + const anvilInstance = await pool.start(index, poolOptions); + + const anvilUrl = `${anvilInstance.host}:${anvilInstance.port}`; + const provider = new ethers.JsonRpcProvider(`http://${anvilUrl}`); + const { chainId, name } = await provider.getNetwork(); + chains[chain].anvilClientDetails = { + anvilPool: pool, + anvilPoolId: Number(index), + provider, + anvilInstance, + anvilUrl: `http://${anvilUrl}`, + anvilChainId: Number(chainId), + anvilChainName: name, + anvilChainType: { + id: Number(chainId), + name: name, + network: name, + nativeCurrency: options.nativeCurrency + ? options.nativeCurrency + : { + decimals: 18, + name: 'Anvil', + symbol: 'ANV', + }, + rpcUrls: { + default: { + http: [`http://${anvilUrl}`], + webSocket: [`ws://${anvilUrl}`], + }, + public: { + http: [`http://${anvilUrl}`], + webSocket: [`ws://${anvilUrl}`], + }, + }, + }, + }; + } + return chains; + } catch (error) { + throw new Error('There was an error while trying to run anvil.', error); + } + }, + async stopAnvil(anvilInstance) { + try { + await anvilInstance.stop(); + console.log(anvilInstance.status); // idle + } catch (error) { + throw new Error('There was an error while trying to stop anvil.', error); + } + }, + async stopAnvilPoolId(anvilPool, anvilPoolId) { + try { + await anvilPool.stop(anvilPoolId); + } catch (error) { + throw new Error( + `There was an error while trying to stop anvil pool with id ${anvilPoolId}`, + error, + ); + } + }, + async stopAnvilPool(anvilPool) { + try { + await anvilPool.empty(); + } catch (error) { + throw new Error( + `There was an error while trying to stop anvil pool`, + error, + ); + } + }, + async installFoundry(commit = '200b3f48a1fccdd93d579233df740f8727da5bcd') { + const foundryClient = require('@foundry-rs/easy-foundryup'); + try { + await foundryClient.getAnvilCommand(); + } catch (error) { + await foundryClient.run(true, { + commit, + }); + } + }, +}; diff --git a/plugins/index.js b/plugins/index.js index 107c1ff8b..874515539 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -2,6 +2,7 @@ const helpers = require('../helpers'); const playwright = require('../commands/playwright'); const metamask = require('../commands/metamask'); const etherscan = require('../commands/etherscan'); +const foundry = require('../commands/foundry'); /** * @type {Cypress.PluginConfig} @@ -50,6 +51,12 @@ module.exports = (on, config) => { console.warn('\u001B[33m', 'WARNING:', message, '\u001B[0m'); return true; }, + // foundry commands + forkChains: foundry.forkChains, + installFoundry: foundry.installFoundry, + runAnvil: foundry.runAnvil, + stopAnvil: foundry.stopAnvil, + setupViem: foundry.setupViem, // playwright commands initPlaywright: playwright.init, clearPlaywright: playwright.clear, diff --git a/support/commands.js b/support/commands.js index f36285490..bc6755be9 100644 --- a/support/commands.js +++ b/support/commands.js @@ -1,6 +1,28 @@ import '@testing-library/cypress/add-commands'; import 'cypress-wait-until'; +// foundry commands + +Cypress.Commands.add('forkChains', options => { + return cy.task('forkChains', options); +}); + +Cypress.Commands.add('installFoundry', commit => { + return cy.task('installFoundry', commit); +}); + +Cypress.Commands.add('runAnvil', options => { + return cy.task('runAnvil', options); +}); + +Cypress.Commands.add('stopAnvil', anvilInstance => { + return cy.task('stopAnvil', anvilInstance); +}); + +Cypress.Commands.add('setupViem', anvilChainType => { + return cy.task('setupViem', anvilChainType); +}); + // playwright commands Cypress.Commands.add('initPlaywright', () => { diff --git a/support/index.d.ts b/support/index.d.ts index 531cb59d2..cfd49dc40 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -1,5 +1,38 @@ declare namespace Cypress { interface Chainable { + // foundry commands + /** + * Setup Anvil pool and Viem clients + * @example + * cy.forkChains() + */ + forkChains(): Chainable; + /** + * Install Foundry + * @example + * cy.installFoundry() + */ + installFoundry(commit?: string): Chainable; + /** + * Run Anvil instance + * @example + * cy.runAnvil() + */ + runAnvil(forkUrl: string, forkBlockNumber?: number): Chainable; + /** + * Stop Anvil instance + * @example + * cy.stopAnvil() + */ + stopAnvil(anvilInstance): Chainable; + /** + * Setup Viem.sh + * @example + * cy.setupViem() + */ + setupViem(anvilChainType): Chainable; + + // playwright commands /** * Connect playwright with Cypress instance * @example @@ -60,7 +93,7 @@ declare namespace Cypress { * If preset for your custom chain is not available, you can add custom network by yourself. * @example * cy.addMetamaskNetwork('optimism') // works only if chain is available as preset - * cy.addMetamaskNetwork({name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://https://optimistic.etherscan.io', isTestnet: false}) + * cy.addMetamaskNetwork({name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://optimistic.etherscan.io', isTestnet: false}) * cy.addMetamaskNetwork({id: 10, name: 'optimism', nativeCurrency: { symbol: 'OP' }, rpcUrls: { default: { http: ['https://mainnet.optimism.io'] } }, testnet: false }) */ addMetamaskNetwork( @@ -384,9 +417,9 @@ declare namespace Cypress { * @example * cy.setupMetamask() // will use defaults * cy.setupMetamask('secret, words, ...', 'optimism', 'password for metamask') // works only if chain is available as preset - * cy.setupMetamask('secret, words, ...', {name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://https://optimistic.etherscan.io', isTestnet: false}, 'password for metamask') + * cy.setupMetamask('secret, words, ...', {name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://optimistic.etherscan.io', isTestnet: false}, 'password for metamask') * cy.setupMetamask('private_key', 'goerli', 'password for metamask') - * cy.setupMetamask('private_key', {name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://https://optimistic.etherscan.io', isTestnet: false}, 'password for metamask') + * cy.setupMetamask('private_key', {name: 'optimism', rpcUrl: 'https://mainnet.optimism.io', chainId: 10, symbol: 'oETH', blockExplorer: 'https://optimistic.etherscan.io', isTestnet: false}, 'password for metamask') */ setupMetamask( secretWordsOrPrivateKey?: string, From 5bc9a0e4ba835e5242ae979ce2094f703f16d4e2 Mon Sep 17 00:00:00 2001 From: "r3kt.eth" Date: Mon, 21 Aug 2023 00:58:11 +0200 Subject: [PATCH 02/19] stopAnvilPool Signed-off-by: r3kt.eth --- plugins/index.js | 1 + support/commands.js | 4 ++++ support/index.d.ts | 8 +++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plugins/index.js b/plugins/index.js index 874515539..c7c394966 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -56,6 +56,7 @@ module.exports = (on, config) => { installFoundry: foundry.installFoundry, runAnvil: foundry.runAnvil, stopAnvil: foundry.stopAnvil, + stopAnvilPool: foundry.stopAnvilPool, setupViem: foundry.setupViem, // playwright commands initPlaywright: playwright.init, diff --git a/support/commands.js b/support/commands.js index bc6755be9..8d6f62491 100644 --- a/support/commands.js +++ b/support/commands.js @@ -19,6 +19,10 @@ Cypress.Commands.add('stopAnvil', anvilInstance => { return cy.task('stopAnvil', anvilInstance); }); +Cypress.Commands.add('stopAnvilPool', anvilPool => { + return cy.task('stopAnvilPool', anvilPool); +}); + Cypress.Commands.add('setupViem', anvilChainType => { return cy.task('setupViem', anvilChainType); }); diff --git a/support/index.d.ts b/support/index.d.ts index cfd49dc40..47f76309c 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -22,9 +22,15 @@ declare namespace Cypress { /** * Stop Anvil instance * @example - * cy.stopAnvil() + * cy.stopAnvil(anvilInstance) */ stopAnvil(anvilInstance): Chainable; + /** + * Stop Anvil pool + * @example + * cy.stopAnvilPool(anvilPool) + */ + stopAnvilPool(anvilPool): Chainable; /** * Setup Viem.sh * @example From bb58e37f49f11b8b6b6a519b3136431b2983e17c Mon Sep 17 00:00:00 2001 From: "r3kt.eth" Date: Mon, 21 Aug 2023 17:36:30 +0200 Subject: [PATCH 03/19] finish working on foundry int Signed-off-by: r3kt.eth --- commands/foundry.js | 23 +++++++- commands/synpress.js | 3 ++ tests/e2e/specs/foundry-spec.js | 93 +++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/e2e/specs/foundry-spec.js diff --git a/commands/foundry.js b/commands/foundry.js index e16fec667..139ae9d3e 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -2,7 +2,16 @@ const { findNetwork } = require('../helpers'); const log = require('debug')('synpress:foundry'); +let activeChains; + module.exports = { + async resetState() { + log('Resetting state of foundry'); + activeChains = undefined; + }, + async getActiveChains() { + return activeChains; + }, async forkChains(options) { await module.exports.installFoundry(options.foundryCommit); @@ -123,6 +132,7 @@ module.exports = { }, }; } + activeChains = chains; return chains; } catch (error) { throw new Error('There was an error while trying to run anvil.', error); @@ -131,7 +141,7 @@ module.exports = { async stopAnvil(anvilInstance) { try { await anvilInstance.stop(); - console.log(anvilInstance.status); // idle + return true; } catch (error) { throw new Error('There was an error while trying to stop anvil.', error); } @@ -148,7 +158,14 @@ module.exports = { }, async stopAnvilPool(anvilPool) { try { - await anvilPool.empty(); + if (Object.values(activeChains)[0]) { + await Object.values( + activeChains, + )[0].anvilClientDetails.anvilPool.empty(); + } else { + await anvilPool.empty(); + } + return true; } catch (error) { throw new Error( `There was an error while trying to stop anvil pool`, @@ -160,10 +177,12 @@ module.exports = { const foundryClient = require('@foundry-rs/easy-foundryup'); try { await foundryClient.getAnvilCommand(); + return true; } catch (error) { await foundryClient.run(true, { commit, }); + return true; } }, }; diff --git a/commands/synpress.js b/commands/synpress.js index f42b25b5b..49b08b091 100644 --- a/commands/synpress.js +++ b/commands/synpress.js @@ -2,6 +2,7 @@ const log = require('debug')('synpress:synpress'); const playwright = require('./playwright'); const metamask = require('./metamask'); const helpers = require('../helpers'); +const foundry = require('./foundry'); module.exports = { async resetState() { @@ -9,5 +10,7 @@ module.exports = { await playwright.resetState(); await metamask.resetState(); await helpers.resetState(); + await foundry.resetState(); + return true; }, }; diff --git a/tests/e2e/specs/foundry-spec.js b/tests/e2e/specs/foundry-spec.js new file mode 100644 index 000000000..8cd3b93a5 --- /dev/null +++ b/tests/e2e/specs/foundry-spec.js @@ -0,0 +1,93 @@ +/* eslint-disable ui-testing/missing-assertion-in-test */ +describe('Foundry', () => { + context('Anvil commands', () => { + before(() => { + cy.setupMetamask(); + }); + + it(`forkChains should setup a pool with fork of optimism chain with specified block number (108516344)`, () => { + cy.forkChains({ + chainsToFork: { + optimism: { + forkUrl: 'https://rpc.ankr.com/optimism', + forkBlockNumber: 108516344, + host: '0.0.0.0', + nativeCurrency: { + decimals: 18, + name: 'Optimism Ether', + symbol: 'oETH', + }, + }, + }, + }).then(data => { + const chains = Object.keys(data.chains); + for (const chain of chains) { + const chainData = data.chains[chain]; + const { anvilChainType } = chainData.anvilClientDetails; + const networkName = `${anvilChainType.name}-108516344`; + const rpcUrl = anvilChainType.rpcUrls.default.http[0]; + const chainId = anvilChainType.id; + const symbol = anvilChainType.nativeCurrency.symbol; + cy.addMetamaskNetwork({ + networkName, + rpcUrl, + chainId, + symbol, + isTestnet: true, + }); + } + }); + + // anvil will be killed automatically with nodejs process, so it's not mandatory to kill it manually + cy.stopAnvilPool(); + }); + + it(`forkChains should setup a pool of forks with ethereum mainnet (without forkUrl) and optimism mainnet (without forkBlockNumber)`, () => { + cy.forkChains({ + chainsToFork: { + mainnet: { + // if forkUrl is undefined, it will use @viem/chains defaults + forkUrl: undefined, + forkBlockNumber: undefined, + host: '0.0.0.0', + nativeCurrency: { + decimals: 18, + name: 'Ether', + symbol: 'ETH', + }, + }, + optimism: { + forkUrl: 'https://rpc.ankr.com/optimism', + forkBlockNumber: undefined, + host: '0.0.0.0', + nativeCurrency: { + decimals: 18, + name: 'Optimism Ether', + symbol: 'oETH', + }, + }, + }, + }).then(data => { + const chains = Object.keys(data.chains); + for (const chain of chains) { + const chainData = data.chains[chain]; + const { anvilChainType } = chainData.anvilClientDetails; + const networkName = anvilChainType.name; + const rpcUrl = anvilChainType.rpcUrls.default.http[0]; + const chainId = anvilChainType.id; + const symbol = anvilChainType.nativeCurrency.symbol; + cy.addMetamaskNetwork({ + networkName, + rpcUrl, + chainId, + symbol, + isTestnet: true, + }); + } + }); + + // anvil will be killed automatically with nodejs process, so it's not mandatory to kill it manually + cy.stopAnvilPool(); + }); + }); +}); From cf16f491791d62cc928bfbe252090e06a4abb765 Mon Sep 17 00:00:00 2001 From: "r3kt.eth" Date: Mon, 21 Aug 2023 18:13:29 +0200 Subject: [PATCH 04/19] add viem clients Signed-off-by: r3kt.eth --- commands/foundry.js | 24 +++++++++------------ plugins/index.js | 2 +- support/commands.js | 4 ++-- support/index.d.ts | 52 ++++++++++++++++++++++++++++++++++----------- 4 files changed, 53 insertions(+), 29 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index 139ae9d3e..68678325b 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -16,20 +16,11 @@ module.exports = { await module.exports.installFoundry(options.foundryCommit); if (typeof options === 'object') { - const chains = await module.exports.runAnvil(options.chainsToFork); - - let viemClients = {}; - for (const [chain, options] of Object.entries(chains)) { - log(`Setting up ${chain}`); - viemClients.chain = await module.exports.setupViem( - options.anvilClientDetails.anvilChainType, - ); - } + const chains = await module.exports.runAnvilWithViem( + options.chainsToFork, + ); - return { - chains, - viemClients, - }; + return { chains }; } else if (typeof options === 'string') { if (isNaN(options)) { // todo: add support for: @@ -72,7 +63,7 @@ module.exports = { throw new Error('There was an error while trying to setup Viem.', error); } }, - async runAnvil(chains) { + async runAnvilWithViem(chains) { const { ethers } = require('ethers'); const anvilClient = await import('@viem/anvil'); try { @@ -131,7 +122,12 @@ module.exports = { }, }, }; + + chains[chain].viemClients = await module.exports.setupViem( + chains[chain].anvilClientDetails.anvilChainType, + ); } + activeChains = chains; return chains; } catch (error) { diff --git a/plugins/index.js b/plugins/index.js index c7c394966..7933258d5 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -54,7 +54,7 @@ module.exports = (on, config) => { // foundry commands forkChains: foundry.forkChains, installFoundry: foundry.installFoundry, - runAnvil: foundry.runAnvil, + runAnvilWithViem: foundry.runAnvilWithViem, stopAnvil: foundry.stopAnvil, stopAnvilPool: foundry.stopAnvilPool, setupViem: foundry.setupViem, diff --git a/support/commands.js b/support/commands.js index 8d6f62491..15694e6d5 100644 --- a/support/commands.js +++ b/support/commands.js @@ -11,8 +11,8 @@ Cypress.Commands.add('installFoundry', commit => { return cy.task('installFoundry', commit); }); -Cypress.Commands.add('runAnvil', options => { - return cy.task('runAnvil', options); +Cypress.Commands.add('runAnvilWithViem', options => { + return cy.task('runAnvilWithViem', options); }); Cypress.Commands.add('stopAnvil', anvilInstance => { diff --git a/support/index.d.ts b/support/index.d.ts index 47f76309c..8e375993f 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -2,23 +2,50 @@ declare namespace Cypress { interface Chainable { // foundry commands /** - * Setup Anvil pool and Viem clients - * @example - * cy.forkChains() - */ - forkChains(): Chainable; + * Setup Foundry, run Anvil fork pool and expose Viem clients + * @example + * cy.forkChains({chainsToFork: {optimism: {forkUrl: undefined, forkBlockNumber: undefined, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } } }); + * cy.forkChains({chainsToFork: {optimism: {forkUrl: 'https://rpc.ankr.com/optimism', forkBlockNumber: 123123123, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } } }); + */ + forkChains(options: { + chainsToFork: { + [chain: string]: { + forkUrl?: string; + forkBlockNumber?: number; + host: string; + nativeCurrency: { + decimals: number; + name: string; + symbol: string; + }; + }; + }; + }): Chainable; /** - * Install Foundry + * Install Foundry and Anvil (if not installed already) * @example * cy.installFoundry() + * cy.installFoundry('200b3f48a1fccdd93d579233df740f8727da5bcd') */ installFoundry(commit?: string): Chainable; /** - * Run Anvil instance + * Run Anvil fork with attached Viem clients * @example - * cy.runAnvil() + * cy.runAnvilWithViem({optimism: {forkUrl: undefined, forkBlockNumber: undefined, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } }) + * cy.runAnvilWithViem({optimism: {forkUrl: 'https://rpc.ankr.com/optimism', forkBlockNumber: 123123123, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } }) */ - runAnvil(forkUrl: string, forkBlockNumber?: number): Chainable; + runAnvilWithViem(options: { + [chain: string]: { + forkUrl?: string; + forkBlockNumber?: number; + host: string; + nativeCurrency: { + decimals: number; + name: string; + symbol: string; + }; + }; + }): Chainable; /** * Stop Anvil instance * @example @@ -28,13 +55,14 @@ declare namespace Cypress { /** * Stop Anvil pool * @example + * cy.stopAnvilPool() * cy.stopAnvilPool(anvilPool) */ - stopAnvilPool(anvilPool): Chainable; + stopAnvilPool(anvilPool?): Chainable; /** - * Setup Viem.sh + * Setup Viem.sh client for specified chain * @example - * cy.setupViem() + * cy.setupViem(chains[chain].anvilClientDetails.anvilChainType) // returned from runAnvilWithViem() or forkChains() */ setupViem(anvilChainType): Chainable; From ff68cfccafb5adfaee025266d3a596250849c732 Mon Sep 17 00:00:00 2001 From: "r3kt.eth" Date: Mon, 21 Aug 2023 18:22:25 +0200 Subject: [PATCH 05/19] rename tests Signed-off-by: r3kt.eth --- tests/e2e/specs/{metamask-spec.js => 1-metamask-spec.js} | 0 tests/e2e/specs/{playwright-spec.js => 2-playwright-spec.js} | 0 tests/e2e/specs/{foundry-spec.js => 3-foundry-spec.js} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename tests/e2e/specs/{metamask-spec.js => 1-metamask-spec.js} (100%) rename tests/e2e/specs/{playwright-spec.js => 2-playwright-spec.js} (100%) rename tests/e2e/specs/{foundry-spec.js => 3-foundry-spec.js} (100%) diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/1-metamask-spec.js similarity index 100% rename from tests/e2e/specs/metamask-spec.js rename to tests/e2e/specs/1-metamask-spec.js diff --git a/tests/e2e/specs/playwright-spec.js b/tests/e2e/specs/2-playwright-spec.js similarity index 100% rename from tests/e2e/specs/playwright-spec.js rename to tests/e2e/specs/2-playwright-spec.js diff --git a/tests/e2e/specs/foundry-spec.js b/tests/e2e/specs/3-foundry-spec.js similarity index 100% rename from tests/e2e/specs/foundry-spec.js rename to tests/e2e/specs/3-foundry-spec.js From da9df172d25ccf63ee98181c60d83b3a9e8c7343 Mon Sep 17 00:00:00 2001 From: duckception Date: Mon, 11 Sep 2023 23:35:13 +0200 Subject: [PATCH 06/19] test --- commands/foundry.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index 68678325b..20577c5a2 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -13,7 +13,7 @@ module.exports = { return activeChains; }, async forkChains(options) { - await module.exports.installFoundry(options.foundryCommit); + // await module.exports.installFoundry(options.foundryCommit); if (typeof options === 'object') { const chains = await module.exports.runAnvilWithViem( @@ -170,15 +170,16 @@ module.exports = { } }, async installFoundry(commit = '200b3f48a1fccdd93d579233df740f8727da5bcd') { - const foundryClient = require('@foundry-rs/easy-foundryup'); - try { - await foundryClient.getAnvilCommand(); - return true; - } catch (error) { - await foundryClient.run(true, { - commit, - }); - return true; - } + // const foundryClient = require('@foundry-rs/easy-foundryup'); + // try { + // await foundryClient.getAnvilCommand(); + // return true; + // } catch (error) { + // await foundryClient.run(true, { + // commit, + // }); + // return true; + // } + throw new Error("INSTALL FOUNDRY CALL") }, }; From 62c2eda0bc198330213f818a38574bef55a3a946 Mon Sep 17 00:00:00 2001 From: duckception Date: Mon, 11 Sep 2023 23:43:44 +0200 Subject: [PATCH 07/19] ignore lint --- commands/foundry.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/commands/foundry.js b/commands/foundry.js index 20577c5a2..0218eee8d 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -169,6 +169,7 @@ module.exports = { ); } }, + // eslint-disable-next-line no-unused-vars async installFoundry(commit = '200b3f48a1fccdd93d579233df740f8727da5bcd') { // const foundryClient = require('@foundry-rs/easy-foundryup'); // try { @@ -180,6 +181,6 @@ module.exports = { // }); // return true; // } - throw new Error("INSTALL FOUNDRY CALL") + throw new Error('INSTALL FOUNDRY CALL'); }, }; From 49546fd05eb8f5737eae36071da92a4f3fc9c6a6 Mon Sep 17 00:00:00 2001 From: duckception Date: Mon, 11 Sep 2023 23:58:52 +0200 Subject: [PATCH 08/19] move things around --- commands/foundry.js | 5 +- tests/e2e/specs/1-metamask-spec.js | 112 ++++++++++++++--------------- tests/e2e/specs/3-foundry-spec.js | 8 ++- 3 files changed, 66 insertions(+), 59 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index 0218eee8d..b405a1449 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -64,9 +64,10 @@ module.exports = { } }, async runAnvilWithViem(chains) { - const { ethers } = require('ethers'); - const anvilClient = await import('@viem/anvil'); try { + const { ethers } = require('ethers'); + const anvilClient = await import('@viem/anvil'); + const pool = anvilClient.createPool(); for (const [index, [chain, options]] of Object.entries( diff --git a/tests/e2e/specs/1-metamask-spec.js b/tests/e2e/specs/1-metamask-spec.js index 3b00ae2a2..c2a69a2e4 100644 --- a/tests/e2e/specs/1-metamask-spec.js +++ b/tests/e2e/specs/1-metamask-spec.js @@ -47,14 +47,14 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it(`getCurrentNetwork should return network by default`, () => { + it.skip(`getCurrentNetwork should return network by default`, () => { cy.getCurrentNetwork().then(network => { expect(network.name).to.match(/sepolia/i); expect(network.id).to.be.equal(11155111); expect(network.testnet).to.be.true; }); }); - it(`addMetamaskNetwork should add custom network`, () => { + it.skip(`addMetamaskNetwork should add custom network`, () => { if (Cypress.env('USE_ANVIL')) { cy.addMetamaskNetwork({ networkName: 'anvil', @@ -80,7 +80,7 @@ describe('Metamask', () => { cy.get('#chainId').contains('0xa'); } }); - it(`getCurrentNetwork should return valid network after adding a new network`, () => { + it.skip(`getCurrentNetwork should return valid network after adding a new network`, () => { cy.getCurrentNetwork().then(network => { if (Cypress.env('USE_ANVIL')) { expect(network.name).to.be.equal('anvil'); @@ -93,26 +93,26 @@ describe('Metamask', () => { } }); }); - it(`changeMetamaskNetwork should change network using pre-defined network`, () => { + it.skip(`changeMetamaskNetwork should change network using pre-defined network`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.true; }); cy.get('#network').contains('0x1'); cy.get('#chainId').contains('0x1'); }); - it(`getCurrentNetwork should return valid network after changing a network`, () => { + it.skip(`getCurrentNetwork should return valid network after changing a network`, () => { cy.getCurrentNetwork().then(network => { console.log(network); expect(network.name).to.match(/ethereum/i); expect(network.id).to.be.equal(1); }); }); - it(`changeMetamaskNetwork should discard changing network if it is current one`, () => { + it.skip(`changeMetamaskNetwork should discard changing network if it is current one`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.false; }); }); - it(`changeMetamaskNetwork should change network using custom network name`, () => { + it.skip(`changeMetamaskNetwork should change network using custom network name`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil').then(networkChanged => { expect(networkChanged).to.be.true; @@ -128,7 +128,7 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('sepolia'); } }); - it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { + it.skip(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { cy.get('#deployNFTsButton').click(); cy.confirmMetamaskTransaction(); cy.get('#mintButton').click(); @@ -138,13 +138,13 @@ describe('Metamask', () => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { + it.skip(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { cy.get('#setApprovalForAllButton').click(); cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { expect(confirmed).to.be.true; }); }); - it(`importMetamaskAccount should import new account using private key`, () => { + it.skip(`importMetamaskAccount should import new account using private key`, () => { cy.importMetamaskAccount( '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6', ).then(imported => { @@ -156,81 +156,81 @@ describe('Metamask', () => { '0xa0ee7a142d267c1f36714e4a8f75612f20a79720', ); }); - it(`createMetamaskAccount should create new account with default name`, () => { + it.skip(`createMetamaskAccount should create new account with default name`, () => { cy.createMetamaskAccount().then(created => { expect(created).to.be.true; }); }); - it(`createMetamaskAccount should create new account with custom name`, () => { + it.skip(`createMetamaskAccount should create new account with custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.true; }); }); - it(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { + it.skip(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it(`renameMetamaskAccount should rename metamask account`, () => { + it.skip(`renameMetamaskAccount should rename metamask account`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.true; }); }); - it(`switchMetamaskAccount should switch to another account using order number`, () => { + it.skip(`switchMetamaskAccount should switch to another account using order number`, () => { cy.switchMetamaskAccount(2).then(switched => { expect(switched).to.be.true; }); }); - it(`renameMetamaskAccount should not fail when account with this name already exists`, () => { + it.skip(`renameMetamaskAccount should not fail when account with this name already exists`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { + it.skip(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', ); }); }); - it(`switchMetamaskAccount should switch to another account using account name`, () => { + it.skip(`switchMetamaskAccount should switch to another account using account name`, () => { cy.switchMetamaskAccount('account 1').then(switched => { expect(switched).to.be.true; }); }); - it(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { + it.skip(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', ); }); }); - it(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { + it.skip(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { cy.activateCustomNonceInMetamask().then(activated => { expect(activated).to.be.true; }); }); // todo: add tests for advanced settings - it(`resetMetamaskAccount should reset current account`, () => { + it.skip(`resetMetamaskAccount should reset current account`, () => { cy.resetMetamaskAccount().then(resetted => { expect(resetted).to.be.true; }); }); - it(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { + it.skip(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromDapp().then(disconnected => { expect(disconnected).to.be.true; }); }); - it(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { + it.skip(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromAllDapps().then(disconnected => { expect(disconnected).to.be.true; }); }); - it(`confirmMetamaskSignatureRequest should confirm signature request`, () => { + it.skip(`confirmMetamaskSignatureRequest should confirm signature request`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.get('#personalSign').click(); @@ -242,7 +242,7 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { + it.skip(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.confirmMetamaskDataSignatureRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -250,7 +250,7 @@ describe('Metamask', () => { cy.get('#signTypedDataV4Verify').click(); cy.get('#signTypedDataV4VerifyResult').contains('0x'); }); - it(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { + it.skip(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.rejectMetamaskEncryptionPublicKeyRequest().then(rejected => { expect(rejected).to.be.true; @@ -259,7 +259,7 @@ describe('Metamask', () => { 'Error: MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.', ); }); - it(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { + it.skip(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.confirmMetamaskEncryptionPublicKeyRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -268,7 +268,7 @@ describe('Metamask', () => { 'mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=', ); }); - it(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { + it.skip(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { cy.get('#encryptMessageInput').type('test message'); cy.get('#encryptButton').click(); cy.get('#ciphertextDisplay').contains('0x7'); @@ -278,7 +278,7 @@ describe('Metamask', () => { }); cy.get('#cleartextDisplay').contains('test message'); }); - it(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { + it.skip(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { cy.get('#decryptButton').click(); cy.rejectMetamaskDecryptionRequest().then(rejected => { expect(rejected).to.be.true; @@ -287,14 +287,14 @@ describe('Metamask', () => { 'Error: MetaMask Decryption: User denied message decryption.', ); }); - it(`rejectMetamaskSignatureRequest should reject signature request`, () => { + it.skip(`rejectMetamaskSignatureRequest should reject signature request`, () => { cy.get('#personalSign').click(); cy.rejectMetamaskSignatureRequest().then(rejected => { expect(rejected).to.be.true; }); cy.get('#personalSign').contains('User denied message signature'); }); - it(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { + it.skip(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.rejectMetamaskDataSignatureRequest().then(rejected => { expect(rejected).to.be.true; @@ -303,7 +303,7 @@ describe('Metamask', () => { 'User denied message signature', ); }); - it(`rejectMetamaskTransaction should reject transaction`, () => { + it.skip(`rejectMetamaskTransaction should reject transaction`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil'); cy.importMetamaskAccount( @@ -323,7 +323,7 @@ describe('Metamask', () => { }); cy.contains('#tokenAddress', 'Creation Failed', { timeout: 60000 }); }); - it(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -332,7 +332,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -341,7 +341,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#amountInput').type('0x38D7EA4C68000'); // 0.001 ETH @@ -350,7 +350,7 @@ describe('Metamask', () => { expect(txData.recipientPublicAddress).to.be.equal('Account 1'); }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -359,7 +359,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction('low').then(txData => { expect(txData.confirmed).to.be.true; @@ -377,7 +377,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -387,7 +387,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { + it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -396,7 +396,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { + it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -405,7 +405,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { + it.skip(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.confirmed).to.be.true; @@ -423,25 +423,25 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`openMetamaskTransactionDetails should open transaction details popup`, () => { + it.skip(`openMetamaskTransactionDetails should open transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0).then( opened => expect(opened).to.be.true, ); }); - it(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { + it.skip(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { + it.skip(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(14); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { + it.skip(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { cy.get('#createToken').click(); cy.confirmMetamaskTransaction().then(txData => { // todo: enable after confirmmetamasktx is fixed for multicall func @@ -456,26 +456,26 @@ describe('Metamask', () => { .invoke('text') .then(text => cy.log('Token hash: ' + text)); }); - it(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { + it.skip(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`rejectMetamaskAddToken should cancel importing a token`, () => { + it.skip(`rejectMetamaskAddToken should cancel importing a token`, () => { cy.get('#watchAsset').click(); cy.rejectMetamaskAddToken().then(rejected => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskAddToken should confirm importing a token`, () => { + it.skip(`confirmMetamaskAddToken should confirm importing a token`, () => { cy.get('#watchAsset').click(); cy.confirmMetamaskAddToken().then(confirmed => { expect(confirmed).to.be.true; }); }); - it(`importMetamaskToken should import token to metamask`, () => { + it.skip(`importMetamaskToken should import token to metamask`, () => { const USDCContractAddressOnSepolia = '0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f'; cy.importMetamaskToken(USDCContractAddressOnSepolia).then(tokenData => { @@ -487,7 +487,7 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it(`importMetamaskToken should import token to metamask using advanced token settings`, () => { + it.skip(`importMetamaskToken should import token to metamask using advanced token settings`, () => { const tDAIContractAddressOnSepolia = '0x53844F9577C2334e541Aec7Df7174ECe5dF1fCf0'; cy.importMetamaskToken({ @@ -502,36 +502,36 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { + it.skip(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { cy.get('#approveTokens').click(); cy.rejectMetamaskPermissionToSpend().then(rejected => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { + it.skip(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { cy.get('#approveTokens').click(); cy.confirmMetamaskPermissionToSpend().then(approved => { expect(approved).to.be.true; }); }); - it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { + it.skip(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it(`allowMetamaskToAddNetwork should approve permission to add network`, () => { + it.skip(`allowMetamaskToAddNetwork should approve permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.allowMetamaskToAddNetwork().then(approved => { expect(approved).to.be.true; }); }); - it(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { + it.skip(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { cy.rejectMetamaskToSwitchNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { + it.skip(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { cy.get('#switchEthereumChain').click(); cy.allowMetamaskToSwitchNetwork().then(approved => { expect(approved).to.be.true; diff --git a/tests/e2e/specs/3-foundry-spec.js b/tests/e2e/specs/3-foundry-spec.js index 8cd3b93a5..29f38581a 100644 --- a/tests/e2e/specs/3-foundry-spec.js +++ b/tests/e2e/specs/3-foundry-spec.js @@ -2,7 +2,13 @@ describe('Foundry', () => { context('Anvil commands', () => { before(() => { - cy.setupMetamask(); + cy.setupMetamask( + 'test test test test test test test test test test test junk', + 'sepolia', + 'Tester@1234', + ).then(setupFinished => { + expect(setupFinished).to.be.true; + }); }); it(`forkChains should setup a pool with fork of optimism chain with specified block number (108516344)`, () => { From d316977bef171a082f00dd39bdb07f591c52e025 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 00:10:44 +0200 Subject: [PATCH 09/19] add try catch --- commands/foundry.js | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index b405a1449..37e00f019 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -13,24 +13,29 @@ module.exports = { return activeChains; }, async forkChains(options) { - // await module.exports.installFoundry(options.foundryCommit); + log('starting to fork chains'); + try { + // await module.exports.installFoundry(options.foundryCommit); - if (typeof options === 'object') { - const chains = await module.exports.runAnvilWithViem( - options.chainsToFork, - ); + if (typeof options === 'object') { + const chains = await module.exports.runAnvilWithViem( + options.chainsToFork, + ); - return { chains }; - } else if (typeof options === 'string') { - if (isNaN(options)) { - // todo: add support for: - // (multiple) network IDs - // (single) network name - // (multiple) network names - } else { - // todo: add support for: - // (single) network ID + return { chains }; + } else if (typeof options === 'string') { + if (isNaN(options)) { + // todo: add support for: + // (multiple) network IDs + // (single) network name + // (multiple) network names + } else { + // todo: add support for: + // (single) network ID + } } + } catch (e) { + throw new Error('Error while forking chains', e); } }, async setupViem(anvilChainType) { From fc6a18c10dfbe5c086ab875dbc827ae7a1fa593b Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 00:32:10 +0200 Subject: [PATCH 10/19] which anvil --- commands/foundry.js | 8 +++++++- package.json | 3 ++- pnpm-lock.yaml | 16 ++++++++++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index 37e00f019..e03ec6ff4 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -1,4 +1,5 @@ const { findNetwork } = require('../helpers'); +const which = require('which') const log = require('debug')('synpress:foundry'); @@ -13,7 +14,12 @@ module.exports = { return activeChains; }, async forkChains(options) { - log('starting to fork chains'); + try { + await which('anvil'); + } catch (e) { + throw new Error('No anvil :) Reason:', e); + } + try { // await module.exports.installFoundry(options.foundryCommit); diff --git a/package.json b/package.json index df0ac85d9..d8d3df708 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,8 @@ "node-fetch": "^2.6.1", "underscore": "^1.13.6", "viem": "^1.6.0", - "wait-on": "^7.0.1" + "wait-on": "^7.0.1", + "which": "^4.0.0" }, "devDependencies": { "@metamask/test-dapp": "^7.0.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b9bfa0f14..a5abf123b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -107,6 +107,9 @@ dependencies: wait-on: specifier: ^7.0.1 version: 7.0.1(debug@4.3.4) + which: + specifier: ^4.0.0 + version: 4.0.0 devDependencies: '@metamask/test-dapp': @@ -6602,6 +6605,11 @@ packages: /isexe@2.0.0: resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==} + /isexe@3.1.1: + resolution: {integrity: sha512-LpB/54B+/2J5hqQ7imZHfdU31OlgQqx7ZicVlkm9kzg9/w8GKLEcFfJl/t7DCEDueOyBAD6zCCwTO6Fzs0NoEQ==} + engines: {node: '>=16'} + dev: false + /isobject@3.0.1: resolution: {integrity: sha512-WhB9zCku7EGTj/HQQRz5aUQEUeoQZH2bWcltRErOpymJ4boYE6wL9Tbr23krRPSZ+C5zqNSrSw+Cc7sZZ4b7vg==} engines: {node: '>=0.10.0'} @@ -10478,6 +10486,14 @@ packages: isexe: 2.0.0 dev: true + /which@4.0.0: + resolution: {integrity: sha512-GlaYyEb07DPxYCKhKzplCWBJtvxZcZMrL+4UkrTSJHHPyZU4mYYTv3qaOe77H7EODLSSopAUFAc6W8U4yqvscg==} + engines: {node: ^16.13.0 || >=18.0.0} + hasBin: true + dependencies: + isexe: 3.1.1 + dev: false + /wide-align@1.1.5: resolution: {integrity: sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==} dependencies: From e5dd29f5e5f76e017b59535e00f94843dbca5a0d Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 00:48:18 +0200 Subject: [PATCH 11/19] refactor --- commands/foundry.js | 66 ++++++++++++++++++--------------------------- plugins/index.js | 3 --- support/commands.js | 12 --------- support/index.d.ts | 31 --------------------- 4 files changed, 26 insertions(+), 86 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index e03ec6ff4..9b44c9eab 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -1,5 +1,5 @@ const { findNetwork } = require('../helpers'); -const which = require('which') +const which = require('which'); const log = require('debug')('synpress:foundry'); @@ -14,34 +14,24 @@ module.exports = { return activeChains; }, async forkChains(options) { - try { - await which('anvil'); - } catch (e) { - throw new Error('No anvil :) Reason:', e); - } + await validateIfAnvilIsInstalledOrThrow(); - try { - // await module.exports.installFoundry(options.foundryCommit); - - if (typeof options === 'object') { - const chains = await module.exports.runAnvilWithViem( - options.chainsToFork, - ); + if (typeof options === 'object') { + const chains = await module.exports.runAnvilWithViem( + options.chainsToFork, + ); - return { chains }; - } else if (typeof options === 'string') { - if (isNaN(options)) { - // todo: add support for: - // (multiple) network IDs - // (single) network name - // (multiple) network names - } else { - // todo: add support for: - // (single) network ID - } + return { chains }; + } else if (typeof options === 'string') { + if (isNaN(options)) { + // todo: add support for: + // (multiple) network IDs + // (single) network name + // (multiple) network names + } else { + // todo: add support for: + // (single) network ID } - } catch (e) { - throw new Error('Error while forking chains', e); } }, async setupViem(anvilChainType) { @@ -181,18 +171,14 @@ module.exports = { ); } }, - // eslint-disable-next-line no-unused-vars - async installFoundry(commit = '200b3f48a1fccdd93d579233df740f8727da5bcd') { - // const foundryClient = require('@foundry-rs/easy-foundryup'); - // try { - // await foundryClient.getAnvilCommand(); - // return true; - // } catch (error) { - // await foundryClient.run(true, { - // commit, - // }); - // return true; - // } - throw new Error('INSTALL FOUNDRY CALL'); - }, }; + +async function validateIfAnvilIsInstalledOrThrow() { + try { + await which('anvil'); + } catch (e) { + throw new Error( + 'Anvil not detected!. Forking is possible thanks to Anvil, a local testnet node shipped with Foundry. To install the Foundry toolchain please refer here: https://book.getfoundry.sh/getting-started/installation', + ); + } +} diff --git a/plugins/index.js b/plugins/index.js index f8e386ea6..33bcaae5b 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -53,11 +53,8 @@ module.exports = (on, config) => { }, // foundry commands forkChains: foundry.forkChains, - installFoundry: foundry.installFoundry, - runAnvilWithViem: foundry.runAnvilWithViem, stopAnvil: foundry.stopAnvil, stopAnvilPool: foundry.stopAnvilPool, - setupViem: foundry.setupViem, // playwright commands initPlaywright: playwright.init, clearPlaywright: playwright.clear, diff --git a/support/commands.js b/support/commands.js index b787ad067..6ec56aa5d 100644 --- a/support/commands.js +++ b/support/commands.js @@ -7,14 +7,6 @@ Cypress.Commands.add('forkChains', options => { return cy.task('forkChains', options); }); -Cypress.Commands.add('installFoundry', commit => { - return cy.task('installFoundry', commit); -}); - -Cypress.Commands.add('runAnvilWithViem', options => { - return cy.task('runAnvilWithViem', options); -}); - Cypress.Commands.add('stopAnvil', anvilInstance => { return cy.task('stopAnvil', anvilInstance); }); @@ -23,10 +15,6 @@ Cypress.Commands.add('stopAnvilPool', anvilPool => { return cy.task('stopAnvilPool', anvilPool); }); -Cypress.Commands.add('setupViem', anvilChainType => { - return cy.task('setupViem', anvilChainType); -}); - // playwright commands Cypress.Commands.add('initPlaywright', () => { diff --git a/support/index.d.ts b/support/index.d.ts index 8a2d1cc9a..54ea0c533 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -21,31 +21,6 @@ declare namespace Cypress { }; }; }): Chainable; - /** - * Install Foundry and Anvil (if not installed already) - * @example - * cy.installFoundry() - * cy.installFoundry('200b3f48a1fccdd93d579233df740f8727da5bcd') - */ - installFoundry(commit?: string): Chainable; - /** - * Run Anvil fork with attached Viem clients - * @example - * cy.runAnvilWithViem({optimism: {forkUrl: undefined, forkBlockNumber: undefined, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } }) - * cy.runAnvilWithViem({optimism: {forkUrl: 'https://rpc.ankr.com/optimism', forkBlockNumber: 123123123, host: '0.0.0.0', nativeCurrency: {decimals: 18, name: 'Optimism Ether', symbol: 'oETH'} } }) - */ - runAnvilWithViem(options: { - [chain: string]: { - forkUrl?: string; - forkBlockNumber?: number; - host: string; - nativeCurrency: { - decimals: number; - name: string; - symbol: string; - }; - }; - }): Chainable; /** * Stop Anvil instance * @example @@ -59,12 +34,6 @@ declare namespace Cypress { * cy.stopAnvilPool(anvilPool) */ stopAnvilPool(anvilPool?): Chainable; - /** - * Setup Viem.sh client for specified chain - * @example - * cy.setupViem(chains[chain].anvilClientDetails.anvilChainType) // returned from runAnvilWithViem() or forkChains() - */ - setupViem(anvilChainType): Chainable; // playwright commands /** From 852857402edef8d576c752dd2851af203ab6b011 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 00:58:02 +0200 Subject: [PATCH 12/19] Unskip tests --- tests/e2e/specs/1-metamask-spec.js | 112 ++++++++++++++--------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/tests/e2e/specs/1-metamask-spec.js b/tests/e2e/specs/1-metamask-spec.js index c2a69a2e4..3b00ae2a2 100644 --- a/tests/e2e/specs/1-metamask-spec.js +++ b/tests/e2e/specs/1-metamask-spec.js @@ -47,14 +47,14 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it.skip(`getCurrentNetwork should return network by default`, () => { + it(`getCurrentNetwork should return network by default`, () => { cy.getCurrentNetwork().then(network => { expect(network.name).to.match(/sepolia/i); expect(network.id).to.be.equal(11155111); expect(network.testnet).to.be.true; }); }); - it.skip(`addMetamaskNetwork should add custom network`, () => { + it(`addMetamaskNetwork should add custom network`, () => { if (Cypress.env('USE_ANVIL')) { cy.addMetamaskNetwork({ networkName: 'anvil', @@ -80,7 +80,7 @@ describe('Metamask', () => { cy.get('#chainId').contains('0xa'); } }); - it.skip(`getCurrentNetwork should return valid network after adding a new network`, () => { + it(`getCurrentNetwork should return valid network after adding a new network`, () => { cy.getCurrentNetwork().then(network => { if (Cypress.env('USE_ANVIL')) { expect(network.name).to.be.equal('anvil'); @@ -93,26 +93,26 @@ describe('Metamask', () => { } }); }); - it.skip(`changeMetamaskNetwork should change network using pre-defined network`, () => { + it(`changeMetamaskNetwork should change network using pre-defined network`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.true; }); cy.get('#network').contains('0x1'); cy.get('#chainId').contains('0x1'); }); - it.skip(`getCurrentNetwork should return valid network after changing a network`, () => { + it(`getCurrentNetwork should return valid network after changing a network`, () => { cy.getCurrentNetwork().then(network => { console.log(network); expect(network.name).to.match(/ethereum/i); expect(network.id).to.be.equal(1); }); }); - it.skip(`changeMetamaskNetwork should discard changing network if it is current one`, () => { + it(`changeMetamaskNetwork should discard changing network if it is current one`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.false; }); }); - it.skip(`changeMetamaskNetwork should change network using custom network name`, () => { + it(`changeMetamaskNetwork should change network using custom network name`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil').then(networkChanged => { expect(networkChanged).to.be.true; @@ -128,7 +128,7 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('sepolia'); } }); - it.skip(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { + it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { cy.get('#deployNFTsButton').click(); cy.confirmMetamaskTransaction(); cy.get('#mintButton').click(); @@ -138,13 +138,13 @@ describe('Metamask', () => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { + it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { cy.get('#setApprovalForAllButton').click(); cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { expect(confirmed).to.be.true; }); }); - it.skip(`importMetamaskAccount should import new account using private key`, () => { + it(`importMetamaskAccount should import new account using private key`, () => { cy.importMetamaskAccount( '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6', ).then(imported => { @@ -156,81 +156,81 @@ describe('Metamask', () => { '0xa0ee7a142d267c1f36714e4a8f75612f20a79720', ); }); - it.skip(`createMetamaskAccount should create new account with default name`, () => { + it(`createMetamaskAccount should create new account with default name`, () => { cy.createMetamaskAccount().then(created => { expect(created).to.be.true; }); }); - it.skip(`createMetamaskAccount should create new account with custom name`, () => { + it(`createMetamaskAccount should create new account with custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.true; }); }); - it.skip(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { + it(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it.skip(`renameMetamaskAccount should rename metamask account`, () => { + it(`renameMetamaskAccount should rename metamask account`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.true; }); }); - it.skip(`switchMetamaskAccount should switch to another account using order number`, () => { + it(`switchMetamaskAccount should switch to another account using order number`, () => { cy.switchMetamaskAccount(2).then(switched => { expect(switched).to.be.true; }); }); - it.skip(`renameMetamaskAccount should not fail when account with this name already exists`, () => { + it(`renameMetamaskAccount should not fail when account with this name already exists`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it.skip(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { + it(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', ); }); }); - it.skip(`switchMetamaskAccount should switch to another account using account name`, () => { + it(`switchMetamaskAccount should switch to another account using account name`, () => { cy.switchMetamaskAccount('account 1').then(switched => { expect(switched).to.be.true; }); }); - it.skip(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { + it(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', ); }); }); - it.skip(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { + it(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { cy.activateCustomNonceInMetamask().then(activated => { expect(activated).to.be.true; }); }); // todo: add tests for advanced settings - it.skip(`resetMetamaskAccount should reset current account`, () => { + it(`resetMetamaskAccount should reset current account`, () => { cy.resetMetamaskAccount().then(resetted => { expect(resetted).to.be.true; }); }); - it.skip(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { + it(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromDapp().then(disconnected => { expect(disconnected).to.be.true; }); }); - it.skip(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { + it(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromAllDapps().then(disconnected => { expect(disconnected).to.be.true; }); }); - it.skip(`confirmMetamaskSignatureRequest should confirm signature request`, () => { + it(`confirmMetamaskSignatureRequest should confirm signature request`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.get('#personalSign').click(); @@ -242,7 +242,7 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it.skip(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { + it(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.confirmMetamaskDataSignatureRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -250,7 +250,7 @@ describe('Metamask', () => { cy.get('#signTypedDataV4Verify').click(); cy.get('#signTypedDataV4VerifyResult').contains('0x'); }); - it.skip(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { + it(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.rejectMetamaskEncryptionPublicKeyRequest().then(rejected => { expect(rejected).to.be.true; @@ -259,7 +259,7 @@ describe('Metamask', () => { 'Error: MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.', ); }); - it.skip(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { + it(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.confirmMetamaskEncryptionPublicKeyRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -268,7 +268,7 @@ describe('Metamask', () => { 'mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=', ); }); - it.skip(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { + it(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { cy.get('#encryptMessageInput').type('test message'); cy.get('#encryptButton').click(); cy.get('#ciphertextDisplay').contains('0x7'); @@ -278,7 +278,7 @@ describe('Metamask', () => { }); cy.get('#cleartextDisplay').contains('test message'); }); - it.skip(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { + it(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { cy.get('#decryptButton').click(); cy.rejectMetamaskDecryptionRequest().then(rejected => { expect(rejected).to.be.true; @@ -287,14 +287,14 @@ describe('Metamask', () => { 'Error: MetaMask Decryption: User denied message decryption.', ); }); - it.skip(`rejectMetamaskSignatureRequest should reject signature request`, () => { + it(`rejectMetamaskSignatureRequest should reject signature request`, () => { cy.get('#personalSign').click(); cy.rejectMetamaskSignatureRequest().then(rejected => { expect(rejected).to.be.true; }); cy.get('#personalSign').contains('User denied message signature'); }); - it.skip(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { + it(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.rejectMetamaskDataSignatureRequest().then(rejected => { expect(rejected).to.be.true; @@ -303,7 +303,7 @@ describe('Metamask', () => { 'User denied message signature', ); }); - it.skip(`rejectMetamaskTransaction should reject transaction`, () => { + it(`rejectMetamaskTransaction should reject transaction`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil'); cy.importMetamaskAccount( @@ -323,7 +323,7 @@ describe('Metamask', () => { }); cy.contains('#tokenAddress', 'Creation Failed', { timeout: 60000 }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { + it(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -332,7 +332,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { + it(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -341,7 +341,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { + it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#amountInput').type('0x38D7EA4C68000'); // 0.001 ETH @@ -350,7 +350,7 @@ describe('Metamask', () => { expect(txData.recipientPublicAddress).to.be.equal('Account 1'); }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -359,7 +359,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction('low').then(txData => { expect(txData.confirmed).to.be.true; @@ -377,7 +377,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -387,7 +387,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { + it(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -396,7 +396,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { + it(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -405,7 +405,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { + it(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.confirmed).to.be.true; @@ -423,25 +423,25 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`openMetamaskTransactionDetails should open transaction details popup`, () => { + it(`openMetamaskTransactionDetails should open transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0).then( opened => expect(opened).to.be.true, ); }); - it.skip(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { + it(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { + it(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(14); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { + it(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { cy.get('#createToken').click(); cy.confirmMetamaskTransaction().then(txData => { // todo: enable after confirmmetamasktx is fixed for multicall func @@ -456,26 +456,26 @@ describe('Metamask', () => { .invoke('text') .then(text => cy.log('Token hash: ' + text)); }); - it.skip(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { + it(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`rejectMetamaskAddToken should cancel importing a token`, () => { + it(`rejectMetamaskAddToken should cancel importing a token`, () => { cy.get('#watchAsset').click(); cy.rejectMetamaskAddToken().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskAddToken should confirm importing a token`, () => { + it(`confirmMetamaskAddToken should confirm importing a token`, () => { cy.get('#watchAsset').click(); cy.confirmMetamaskAddToken().then(confirmed => { expect(confirmed).to.be.true; }); }); - it.skip(`importMetamaskToken should import token to metamask`, () => { + it(`importMetamaskToken should import token to metamask`, () => { const USDCContractAddressOnSepolia = '0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f'; cy.importMetamaskToken(USDCContractAddressOnSepolia).then(tokenData => { @@ -487,7 +487,7 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it.skip(`importMetamaskToken should import token to metamask using advanced token settings`, () => { + it(`importMetamaskToken should import token to metamask using advanced token settings`, () => { const tDAIContractAddressOnSepolia = '0x53844F9577C2334e541Aec7Df7174ECe5dF1fCf0'; cy.importMetamaskToken({ @@ -502,36 +502,36 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it.skip(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { + it(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { cy.get('#approveTokens').click(); cy.rejectMetamaskPermissionToSpend().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { + it(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { cy.get('#approveTokens').click(); cy.confirmMetamaskPermissionToSpend().then(approved => { expect(approved).to.be.true; }); }); - it.skip(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { + it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToAddNetwork should approve permission to add network`, () => { + it(`allowMetamaskToAddNetwork should approve permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.allowMetamaskToAddNetwork().then(approved => { expect(approved).to.be.true; }); }); - it.skip(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { + it(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { cy.rejectMetamaskToSwitchNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { + it(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { cy.get('#switchEthereumChain').click(); cy.allowMetamaskToSwitchNetwork().then(approved => { expect(approved).to.be.true; From 6de7729aee097b44941d48177dac39e8067e18d9 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 01:11:52 +0200 Subject: [PATCH 13/19] Wrap errors --- commands/foundry.js | 11 ++- tests/e2e/specs/1-metamask-spec.js | 112 ++++++++++++++--------------- 2 files changed, 66 insertions(+), 57 deletions(-) diff --git a/commands/foundry.js b/commands/foundry.js index 9b44c9eab..d112a18a4 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -32,6 +32,8 @@ module.exports = { // todo: add support for: // (single) network ID } + + throw new Error('Not implemented'); } }, async setupViem(anvilChainType) { @@ -173,11 +175,18 @@ module.exports = { }, }; +class AnvilNotInstalledError extends Error { + constructor(message) { + super(message); + this.name = 'AnvilNotInstalledError'; + } +} + async function validateIfAnvilIsInstalledOrThrow() { try { await which('anvil'); } catch (e) { - throw new Error( + throw new AnvilNotInstalledError( 'Anvil not detected!. Forking is possible thanks to Anvil, a local testnet node shipped with Foundry. To install the Foundry toolchain please refer here: https://book.getfoundry.sh/getting-started/installation', ); } diff --git a/tests/e2e/specs/1-metamask-spec.js b/tests/e2e/specs/1-metamask-spec.js index 3b00ae2a2..c2a69a2e4 100644 --- a/tests/e2e/specs/1-metamask-spec.js +++ b/tests/e2e/specs/1-metamask-spec.js @@ -47,14 +47,14 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it(`getCurrentNetwork should return network by default`, () => { + it.skip(`getCurrentNetwork should return network by default`, () => { cy.getCurrentNetwork().then(network => { expect(network.name).to.match(/sepolia/i); expect(network.id).to.be.equal(11155111); expect(network.testnet).to.be.true; }); }); - it(`addMetamaskNetwork should add custom network`, () => { + it.skip(`addMetamaskNetwork should add custom network`, () => { if (Cypress.env('USE_ANVIL')) { cy.addMetamaskNetwork({ networkName: 'anvil', @@ -80,7 +80,7 @@ describe('Metamask', () => { cy.get('#chainId').contains('0xa'); } }); - it(`getCurrentNetwork should return valid network after adding a new network`, () => { + it.skip(`getCurrentNetwork should return valid network after adding a new network`, () => { cy.getCurrentNetwork().then(network => { if (Cypress.env('USE_ANVIL')) { expect(network.name).to.be.equal('anvil'); @@ -93,26 +93,26 @@ describe('Metamask', () => { } }); }); - it(`changeMetamaskNetwork should change network using pre-defined network`, () => { + it.skip(`changeMetamaskNetwork should change network using pre-defined network`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.true; }); cy.get('#network').contains('0x1'); cy.get('#chainId').contains('0x1'); }); - it(`getCurrentNetwork should return valid network after changing a network`, () => { + it.skip(`getCurrentNetwork should return valid network after changing a network`, () => { cy.getCurrentNetwork().then(network => { console.log(network); expect(network.name).to.match(/ethereum/i); expect(network.id).to.be.equal(1); }); }); - it(`changeMetamaskNetwork should discard changing network if it is current one`, () => { + it.skip(`changeMetamaskNetwork should discard changing network if it is current one`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.false; }); }); - it(`changeMetamaskNetwork should change network using custom network name`, () => { + it.skip(`changeMetamaskNetwork should change network using custom network name`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil').then(networkChanged => { expect(networkChanged).to.be.true; @@ -128,7 +128,7 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('sepolia'); } }); - it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { + it.skip(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { cy.get('#deployNFTsButton').click(); cy.confirmMetamaskTransaction(); cy.get('#mintButton').click(); @@ -138,13 +138,13 @@ describe('Metamask', () => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { + it.skip(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { cy.get('#setApprovalForAllButton').click(); cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { expect(confirmed).to.be.true; }); }); - it(`importMetamaskAccount should import new account using private key`, () => { + it.skip(`importMetamaskAccount should import new account using private key`, () => { cy.importMetamaskAccount( '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6', ).then(imported => { @@ -156,81 +156,81 @@ describe('Metamask', () => { '0xa0ee7a142d267c1f36714e4a8f75612f20a79720', ); }); - it(`createMetamaskAccount should create new account with default name`, () => { + it.skip(`createMetamaskAccount should create new account with default name`, () => { cy.createMetamaskAccount().then(created => { expect(created).to.be.true; }); }); - it(`createMetamaskAccount should create new account with custom name`, () => { + it.skip(`createMetamaskAccount should create new account with custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.true; }); }); - it(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { + it.skip(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it(`renameMetamaskAccount should rename metamask account`, () => { + it.skip(`renameMetamaskAccount should rename metamask account`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.true; }); }); - it(`switchMetamaskAccount should switch to another account using order number`, () => { + it.skip(`switchMetamaskAccount should switch to another account using order number`, () => { cy.switchMetamaskAccount(2).then(switched => { expect(switched).to.be.true; }); }); - it(`renameMetamaskAccount should not fail when account with this name already exists`, () => { + it.skip(`renameMetamaskAccount should not fail when account with this name already exists`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { + it.skip(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', ); }); }); - it(`switchMetamaskAccount should switch to another account using account name`, () => { + it.skip(`switchMetamaskAccount should switch to another account using account name`, () => { cy.switchMetamaskAccount('account 1').then(switched => { expect(switched).to.be.true; }); }); - it(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { + it.skip(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', ); }); }); - it(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { + it.skip(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { cy.activateCustomNonceInMetamask().then(activated => { expect(activated).to.be.true; }); }); // todo: add tests for advanced settings - it(`resetMetamaskAccount should reset current account`, () => { + it.skip(`resetMetamaskAccount should reset current account`, () => { cy.resetMetamaskAccount().then(resetted => { expect(resetted).to.be.true; }); }); - it(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { + it.skip(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromDapp().then(disconnected => { expect(disconnected).to.be.true; }); }); - it(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { + it.skip(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromAllDapps().then(disconnected => { expect(disconnected).to.be.true; }); }); - it(`confirmMetamaskSignatureRequest should confirm signature request`, () => { + it.skip(`confirmMetamaskSignatureRequest should confirm signature request`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.get('#personalSign').click(); @@ -242,7 +242,7 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { + it.skip(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.confirmMetamaskDataSignatureRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -250,7 +250,7 @@ describe('Metamask', () => { cy.get('#signTypedDataV4Verify').click(); cy.get('#signTypedDataV4VerifyResult').contains('0x'); }); - it(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { + it.skip(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.rejectMetamaskEncryptionPublicKeyRequest().then(rejected => { expect(rejected).to.be.true; @@ -259,7 +259,7 @@ describe('Metamask', () => { 'Error: MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.', ); }); - it(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { + it.skip(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.confirmMetamaskEncryptionPublicKeyRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -268,7 +268,7 @@ describe('Metamask', () => { 'mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=', ); }); - it(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { + it.skip(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { cy.get('#encryptMessageInput').type('test message'); cy.get('#encryptButton').click(); cy.get('#ciphertextDisplay').contains('0x7'); @@ -278,7 +278,7 @@ describe('Metamask', () => { }); cy.get('#cleartextDisplay').contains('test message'); }); - it(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { + it.skip(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { cy.get('#decryptButton').click(); cy.rejectMetamaskDecryptionRequest().then(rejected => { expect(rejected).to.be.true; @@ -287,14 +287,14 @@ describe('Metamask', () => { 'Error: MetaMask Decryption: User denied message decryption.', ); }); - it(`rejectMetamaskSignatureRequest should reject signature request`, () => { + it.skip(`rejectMetamaskSignatureRequest should reject signature request`, () => { cy.get('#personalSign').click(); cy.rejectMetamaskSignatureRequest().then(rejected => { expect(rejected).to.be.true; }); cy.get('#personalSign').contains('User denied message signature'); }); - it(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { + it.skip(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.rejectMetamaskDataSignatureRequest().then(rejected => { expect(rejected).to.be.true; @@ -303,7 +303,7 @@ describe('Metamask', () => { 'User denied message signature', ); }); - it(`rejectMetamaskTransaction should reject transaction`, () => { + it.skip(`rejectMetamaskTransaction should reject transaction`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil'); cy.importMetamaskAccount( @@ -323,7 +323,7 @@ describe('Metamask', () => { }); cy.contains('#tokenAddress', 'Creation Failed', { timeout: 60000 }); }); - it(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -332,7 +332,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -341,7 +341,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { + it.skip(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#amountInput').type('0x38D7EA4C68000'); // 0.001 ETH @@ -350,7 +350,7 @@ describe('Metamask', () => { expect(txData.recipientPublicAddress).to.be.equal('Account 1'); }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -359,7 +359,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction('low').then(txData => { expect(txData.confirmed).to.be.true; @@ -377,7 +377,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { + it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -387,7 +387,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { + it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -396,7 +396,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { + it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -405,7 +405,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { + it.skip(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.confirmed).to.be.true; @@ -423,25 +423,25 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it(`openMetamaskTransactionDetails should open transaction details popup`, () => { + it.skip(`openMetamaskTransactionDetails should open transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0).then( opened => expect(opened).to.be.true, ); }); - it(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { + it.skip(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { + it.skip(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(14); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { + it.skip(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { cy.get('#createToken').click(); cy.confirmMetamaskTransaction().then(txData => { // todo: enable after confirmmetamasktx is fixed for multicall func @@ -456,26 +456,26 @@ describe('Metamask', () => { .invoke('text') .then(text => cy.log('Token hash: ' + text)); }); - it(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { + it.skip(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it(`rejectMetamaskAddToken should cancel importing a token`, () => { + it.skip(`rejectMetamaskAddToken should cancel importing a token`, () => { cy.get('#watchAsset').click(); cy.rejectMetamaskAddToken().then(rejected => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskAddToken should confirm importing a token`, () => { + it.skip(`confirmMetamaskAddToken should confirm importing a token`, () => { cy.get('#watchAsset').click(); cy.confirmMetamaskAddToken().then(confirmed => { expect(confirmed).to.be.true; }); }); - it(`importMetamaskToken should import token to metamask`, () => { + it.skip(`importMetamaskToken should import token to metamask`, () => { const USDCContractAddressOnSepolia = '0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f'; cy.importMetamaskToken(USDCContractAddressOnSepolia).then(tokenData => { @@ -487,7 +487,7 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it(`importMetamaskToken should import token to metamask using advanced token settings`, () => { + it.skip(`importMetamaskToken should import token to metamask using advanced token settings`, () => { const tDAIContractAddressOnSepolia = '0x53844F9577C2334e541Aec7Df7174ECe5dF1fCf0'; cy.importMetamaskToken({ @@ -502,36 +502,36 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { + it.skip(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { cy.get('#approveTokens').click(); cy.rejectMetamaskPermissionToSpend().then(rejected => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { + it.skip(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { cy.get('#approveTokens').click(); cy.confirmMetamaskPermissionToSpend().then(approved => { expect(approved).to.be.true; }); }); - it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { + it.skip(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it(`allowMetamaskToAddNetwork should approve permission to add network`, () => { + it.skip(`allowMetamaskToAddNetwork should approve permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.allowMetamaskToAddNetwork().then(approved => { expect(approved).to.be.true; }); }); - it(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { + it.skip(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { cy.rejectMetamaskToSwitchNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { + it.skip(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { cy.get('#switchEthereumChain').click(); cy.allowMetamaskToSwitchNetwork().then(approved => { expect(approved).to.be.true; From 0f62a11248a2d6eae3697c0e9d24372868f165a7 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 02:06:48 +0200 Subject: [PATCH 14/19] expose getActiveChains --- support/commands.js | 4 ++++ support/index.d.ts | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/support/commands.js b/support/commands.js index 6ec56aa5d..0d28963ea 100644 --- a/support/commands.js +++ b/support/commands.js @@ -7,6 +7,10 @@ Cypress.Commands.add('forkChains', options => { return cy.task('forkChains', options); }); +Cypress.Commands.add('getActiveChains', options => { + return cy.task('getActiveChains', options); +}); + Cypress.Commands.add('stopAnvil', anvilInstance => { return cy.task('stopAnvil', anvilInstance); }); diff --git a/support/index.d.ts b/support/index.d.ts index 54ea0c533..3697360e0 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -21,6 +21,12 @@ declare namespace Cypress { }; }; }): Chainable; + /** + * Returns active forked chains + * @example + * cy.getActiveChains(); + */ + getActiveChains(): Chainable; /** * Stop Anvil instance * @example From 53052ab8fc2b6b206b539884b93dc26fe44ab611 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 02:10:07 +0200 Subject: [PATCH 15/19] download foundry --- Dockerfile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index fc501b82d..97d644de7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,14 @@ COPY pnpm-lock.yaml ./ FROM base as test +ENV PATH "$PATH:/root/.foundry/bin" + +RUN curl -L https://foundry.paradigm.xyz | bash && \ + foundryup && \ + forge --version && \ + anvil --version && \ + cast --version + RUN pnpm install --frozen-lockfile --prefer-offline COPY . . From e6e2eb1b3e01ff86524fa3a333899a875a026d58 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 02:11:30 +0200 Subject: [PATCH 16/19] reorder dockerfile --- Dockerfile | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index 97d644de7..b45873a59 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,8 @@ # syntax=docker/dockerfile:1 FROM --platform=linux/amd64 synthetixio/docker-e2e:18.16-ubuntu as base -RUN mkdir /app -WORKDIR /app - RUN apt update && apt install -y nginx -COPY nginx.conf /etc/nginx/sites-available/default - -COPY package.json ./ -COPY pnpm-lock.yaml ./ - -FROM base as test - ENV PATH "$PATH:/root/.foundry/bin" RUN curl -L https://foundry.paradigm.xyz | bash && \ @@ -21,6 +11,16 @@ RUN curl -L https://foundry.paradigm.xyz | bash && \ anvil --version && \ cast --version +RUN mkdir /app +WORKDIR /app + +COPY nginx.conf /etc/nginx/sites-available/default + +COPY package.json ./ +COPY pnpm-lock.yaml ./ + +FROM base as test + RUN pnpm install --frozen-lockfile --prefer-offline COPY . . From f3f630fdf52ecd33538042a70f8821791b6525c3 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 02:20:17 +0200 Subject: [PATCH 17/19] unskip tests --- tests/e2e/specs/1-metamask-spec.js | 112 ++++++++++++++--------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/tests/e2e/specs/1-metamask-spec.js b/tests/e2e/specs/1-metamask-spec.js index c2a69a2e4..3b00ae2a2 100644 --- a/tests/e2e/specs/1-metamask-spec.js +++ b/tests/e2e/specs/1-metamask-spec.js @@ -47,14 +47,14 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it.skip(`getCurrentNetwork should return network by default`, () => { + it(`getCurrentNetwork should return network by default`, () => { cy.getCurrentNetwork().then(network => { expect(network.name).to.match(/sepolia/i); expect(network.id).to.be.equal(11155111); expect(network.testnet).to.be.true; }); }); - it.skip(`addMetamaskNetwork should add custom network`, () => { + it(`addMetamaskNetwork should add custom network`, () => { if (Cypress.env('USE_ANVIL')) { cy.addMetamaskNetwork({ networkName: 'anvil', @@ -80,7 +80,7 @@ describe('Metamask', () => { cy.get('#chainId').contains('0xa'); } }); - it.skip(`getCurrentNetwork should return valid network after adding a new network`, () => { + it(`getCurrentNetwork should return valid network after adding a new network`, () => { cy.getCurrentNetwork().then(network => { if (Cypress.env('USE_ANVIL')) { expect(network.name).to.be.equal('anvil'); @@ -93,26 +93,26 @@ describe('Metamask', () => { } }); }); - it.skip(`changeMetamaskNetwork should change network using pre-defined network`, () => { + it(`changeMetamaskNetwork should change network using pre-defined network`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.true; }); cy.get('#network').contains('0x1'); cy.get('#chainId').contains('0x1'); }); - it.skip(`getCurrentNetwork should return valid network after changing a network`, () => { + it(`getCurrentNetwork should return valid network after changing a network`, () => { cy.getCurrentNetwork().then(network => { console.log(network); expect(network.name).to.match(/ethereum/i); expect(network.id).to.be.equal(1); }); }); - it.skip(`changeMetamaskNetwork should discard changing network if it is current one`, () => { + it(`changeMetamaskNetwork should discard changing network if it is current one`, () => { cy.changeMetamaskNetwork('ethereum').then(networkChanged => { expect(networkChanged).to.be.false; }); }); - it.skip(`changeMetamaskNetwork should change network using custom network name`, () => { + it(`changeMetamaskNetwork should change network using custom network name`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil').then(networkChanged => { expect(networkChanged).to.be.true; @@ -128,7 +128,7 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('sepolia'); } }); - it.skip(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { + it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { cy.get('#deployNFTsButton').click(); cy.confirmMetamaskTransaction(); cy.get('#mintButton').click(); @@ -138,13 +138,13 @@ describe('Metamask', () => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { + it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { cy.get('#setApprovalForAllButton').click(); cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { expect(confirmed).to.be.true; }); }); - it.skip(`importMetamaskAccount should import new account using private key`, () => { + it(`importMetamaskAccount should import new account using private key`, () => { cy.importMetamaskAccount( '0x2a871d0798f97d79848a013d4936a73bf4cc922c825d33c1cf7073dff6d409c6', ).then(imported => { @@ -156,81 +156,81 @@ describe('Metamask', () => { '0xa0ee7a142d267c1f36714e4a8f75612f20a79720', ); }); - it.skip(`createMetamaskAccount should create new account with default name`, () => { + it(`createMetamaskAccount should create new account with default name`, () => { cy.createMetamaskAccount().then(created => { expect(created).to.be.true; }); }); - it.skip(`createMetamaskAccount should create new account with custom name`, () => { + it(`createMetamaskAccount should create new account with custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.true; }); }); - it.skip(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { + it(`createMetamaskAccount should not fail when creating new account with already existing custom name`, () => { cy.createMetamaskAccount('custom-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it.skip(`renameMetamaskAccount should rename metamask account`, () => { + it(`renameMetamaskAccount should rename metamask account`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.true; }); }); - it.skip(`switchMetamaskAccount should switch to another account using order number`, () => { + it(`switchMetamaskAccount should switch to another account using order number`, () => { cy.switchMetamaskAccount(2).then(switched => { expect(switched).to.be.true; }); }); - it.skip(`renameMetamaskAccount should not fail when account with this name already exists`, () => { + it(`renameMetamaskAccount should not fail when account with this name already exists`, () => { cy.renameMetamaskAccount('custom-fancy-wallet').then(created => { expect(created).to.be.equal('This account name already exists'); }); }); - it.skip(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { + it(`getMetamaskWalletAddress should return wallet address of current metamask account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0x70997970C51812dc3A010C7d01b50e0d17dc79C8', ); }); }); - it.skip(`switchMetamaskAccount should switch to another account using account name`, () => { + it(`switchMetamaskAccount should switch to another account using account name`, () => { cy.switchMetamaskAccount('account 1').then(switched => { expect(switched).to.be.true; }); }); - it.skip(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { + it(`getMetamaskWalletAddress should return valid wallet address of metamask account after changing an account`, () => { cy.getMetamaskWalletAddress().then(address => { expect(address).to.be.equal( '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266', ); }); }); - it.skip(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { + it(`activateCustomNonceInMetamask should activate custom nonce input field for transactions`, () => { cy.activateCustomNonceInMetamask().then(activated => { expect(activated).to.be.true; }); }); // todo: add tests for advanced settings - it.skip(`resetMetamaskAccount should reset current account`, () => { + it(`resetMetamaskAccount should reset current account`, () => { cy.resetMetamaskAccount().then(resetted => { expect(resetted).to.be.true; }); }); - it.skip(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { + it(`disconnectMetamaskWalletFromDapp should disconnect current account from current dapp (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromDapp().then(disconnected => { expect(disconnected).to.be.true; }); }); - it.skip(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { + it(`disconnectMetamaskWalletFromAllDapps should disconnect current account from all dapps (when already connected)`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.disconnectMetamaskWalletFromAllDapps().then(disconnected => { expect(disconnected).to.be.true; }); }); - it.skip(`confirmMetamaskSignatureRequest should confirm signature request`, () => { + it(`confirmMetamaskSignatureRequest should confirm signature request`, () => { cy.get('#requestPermissions').click(); cy.acceptMetamaskAccess(); cy.get('#personalSign').click(); @@ -242,7 +242,7 @@ describe('Metamask', () => { '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', ); }); - it.skip(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { + it(`confirmMetamaskSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.confirmMetamaskDataSignatureRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -250,7 +250,7 @@ describe('Metamask', () => { cy.get('#signTypedDataV4Verify').click(); cy.get('#signTypedDataV4VerifyResult').contains('0x'); }); - it.skip(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { + it(`rejectMetamaskEncryptionPublicKeyRequest should reject public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.rejectMetamaskEncryptionPublicKeyRequest().then(rejected => { expect(rejected).to.be.true; @@ -259,7 +259,7 @@ describe('Metamask', () => { 'Error: MetaMask EncryptionPublicKey: User denied message EncryptionPublicKey.', ); }); - it.skip(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { + it(`confirmMetamaskEncryptionPublicKeyRequest should confirm public encryption key request`, () => { cy.get('#getEncryptionKeyButton').click(); cy.confirmMetamaskEncryptionPublicKeyRequest().then(confirmed => { expect(confirmed).to.be.true; @@ -268,7 +268,7 @@ describe('Metamask', () => { 'mtrHp1WHZM9rxF2Ilot9Hie5XmQcKCf7oDQ1DpGkTSI=', ); }); - it.skip(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { + it(`confirmMetamaskDecryptionRequest should confirm request to decrypt message with private key`, () => { cy.get('#encryptMessageInput').type('test message'); cy.get('#encryptButton').click(); cy.get('#ciphertextDisplay').contains('0x7'); @@ -278,7 +278,7 @@ describe('Metamask', () => { }); cy.get('#cleartextDisplay').contains('test message'); }); - it.skip(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { + it(`rejectMetamaskDecryptionRequest should reject request to decrypt message with private key`, () => { cy.get('#decryptButton').click(); cy.rejectMetamaskDecryptionRequest().then(rejected => { expect(rejected).to.be.true; @@ -287,14 +287,14 @@ describe('Metamask', () => { 'Error: MetaMask Decryption: User denied message decryption.', ); }); - it.skip(`rejectMetamaskSignatureRequest should reject signature request`, () => { + it(`rejectMetamaskSignatureRequest should reject signature request`, () => { cy.get('#personalSign').click(); cy.rejectMetamaskSignatureRequest().then(rejected => { expect(rejected).to.be.true; }); cy.get('#personalSign').contains('User denied message signature'); }); - it.skip(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { + it(`rejectMetamaskDataSignatureRequest should confirm data signature request`, () => { cy.get('#signTypedDataV4').click(); cy.rejectMetamaskDataSignatureRequest().then(rejected => { expect(rejected).to.be.true; @@ -303,7 +303,7 @@ describe('Metamask', () => { 'User denied message signature', ); }); - it.skip(`rejectMetamaskTransaction should reject transaction`, () => { + it(`rejectMetamaskTransaction should reject transaction`, () => { if (Cypress.env('USE_ANVIL')) { cy.changeMetamaskNetwork('anvil'); cy.importMetamaskAccount( @@ -323,7 +323,7 @@ describe('Metamask', () => { }); cy.contains('#tokenAddress', 'Creation Failed', { timeout: 60000 }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { + it(`confirmMetamaskTransaction should confirm legacy transaction using default settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -332,7 +332,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { + it(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -341,7 +341,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { + it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#amountInput').type('0x38D7EA4C68000'); // 0.001 ETH @@ -350,7 +350,7 @@ describe('Metamask', () => { expect(txData.recipientPublicAddress).to.be.equal('Account 1'); }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using default settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -359,7 +359,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using pre-defined (low, market, aggressive, site) gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction('low').then(txData => { expect(txData.confirmed).to.be.true; @@ -377,7 +377,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { + it(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction({ gasLimit: 210000, @@ -387,7 +387,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { + it(`confirmMetamaskTransactionAndWaitForMining should confirm legacy transaction and wait for it to be mined`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -396,7 +396,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { + it(`confirmMetamaskTransactionAndWaitForMining should confirm eip-1559 transaction and wait for it to be mined`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.recipientPublicAddress).to.be.not.empty; @@ -405,7 +405,7 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { + it(`chaining confirmMetamaskTransactionAndWaitForMining should work as expected`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransactionAndWaitForMining().then(txData => { expect(txData.confirmed).to.be.true; @@ -423,25 +423,25 @@ describe('Metamask', () => { expect(txData.confirmed).to.be.true; }); }); - it.skip(`openMetamaskTransactionDetails should open transaction details popup`, () => { + it(`openMetamaskTransactionDetails should open transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0).then( opened => expect(opened).to.be.true, ); }); - it.skip(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { + it(`closeMetamaskTransactionDetailsPopup should close transaction details popup`, () => { cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { + it(`openMetamaskTransactionDetails should click "View more" button enough times to open correct transaction details popup`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(14); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { + it(`confirmMetamaskTransaction should confirm transaction for token creation (contract deployment) and check tx data`, () => { cy.get('#createToken').click(); cy.confirmMetamaskTransaction().then(txData => { // todo: enable after confirmmetamasktx is fixed for multicall func @@ -456,26 +456,26 @@ describe('Metamask', () => { .invoke('text') .then(text => cy.log('Token hash: ' + text)); }); - it.skip(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { + it(`openMetamaskTransactionDetails should open correct transaction details popup when there is a pending tx`, () => { // Cannot be tested further with Cypress 😔 cy.openMetamaskTransactionDetails(0); cy.closeMetamaskTransactionDetailsPopup().then( closed => expect(closed).to.be.true, ); }); - it.skip(`rejectMetamaskAddToken should cancel importing a token`, () => { + it(`rejectMetamaskAddToken should cancel importing a token`, () => { cy.get('#watchAsset').click(); cy.rejectMetamaskAddToken().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskAddToken should confirm importing a token`, () => { + it(`confirmMetamaskAddToken should confirm importing a token`, () => { cy.get('#watchAsset').click(); cy.confirmMetamaskAddToken().then(confirmed => { expect(confirmed).to.be.true; }); }); - it.skip(`importMetamaskToken should import token to metamask`, () => { + it(`importMetamaskToken should import token to metamask`, () => { const USDCContractAddressOnSepolia = '0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f'; cy.importMetamaskToken(USDCContractAddressOnSepolia).then(tokenData => { @@ -487,7 +487,7 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it.skip(`importMetamaskToken should import token to metamask using advanced token settings`, () => { + it(`importMetamaskToken should import token to metamask using advanced token settings`, () => { const tDAIContractAddressOnSepolia = '0x53844F9577C2334e541Aec7Df7174ECe5dF1fCf0'; cy.importMetamaskToken({ @@ -502,36 +502,36 @@ describe('Metamask', () => { expect(tokenData.imported).to.be.true; }); }); - it.skip(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { + it(`rejectMetamaskPermissionToSpend should reject permission to spend token`, () => { cy.get('#approveTokens').click(); cy.rejectMetamaskPermissionToSpend().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { + it(`confirmMetamaskPermissionToSpend should approve permission to spend token`, () => { cy.get('#approveTokens').click(); cy.confirmMetamaskPermissionToSpend().then(approved => { expect(approved).to.be.true; }); }); - it.skip(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { + it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToAddNetwork should approve permission to add network`, () => { + it(`allowMetamaskToAddNetwork should approve permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.allowMetamaskToAddNetwork().then(approved => { expect(approved).to.be.true; }); }); - it.skip(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { + it(`rejectMetamaskToSwitchNetwork should reject permission to switch network`, () => { cy.rejectMetamaskToSwitchNetwork().then(rejected => { expect(rejected).to.be.true; }); }); - it.skip(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { + it(`allowMetamaskToSwitchNetwork should approve permission to switch network`, () => { cy.get('#switchEthereumChain').click(); cy.allowMetamaskToSwitchNetwork().then(approved => { expect(approved).to.be.true; From 668caba925b8029397b1670790e3da4047a2f727 Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 02:57:01 +0200 Subject: [PATCH 18/19] install foundry on CI --- .github/workflows/e2e_cypress-action.yml | 3 +++ .github/workflows/e2e_debug.yml | 3 +++ .github/workflows/e2e_headful.yml | 3 +++ 3 files changed, 9 insertions(+) diff --git a/.github/workflows/e2e_cypress-action.yml b/.github/workflows/e2e_cypress-action.yml index ea06af5b9..bfb1f9315 100644 --- a/.github/workflows/e2e_cypress-action.yml +++ b/.github/workflows/e2e_cypress-action.yml @@ -52,6 +52,9 @@ jobs: ${{ runner.os }}-pnpm-v1- continue-on-error: true + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Install dependencies run: pnpm install --frozen-lockfile --prefer-offline diff --git a/.github/workflows/e2e_debug.yml b/.github/workflows/e2e_debug.yml index bf87fe882..8651cd92c 100644 --- a/.github/workflows/e2e_debug.yml +++ b/.github/workflows/e2e_debug.yml @@ -52,6 +52,9 @@ jobs: ${{ runner.os }}-pnpm-v1- continue-on-error: true + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Install dependencies run: pnpm install --frozen-lockfile --prefer-offline diff --git a/.github/workflows/e2e_headful.yml b/.github/workflows/e2e_headful.yml index b46a78be3..a1da7bebc 100644 --- a/.github/workflows/e2e_headful.yml +++ b/.github/workflows/e2e_headful.yml @@ -55,6 +55,9 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile --prefer-offline + - name: Install Foundry + uses: foundry-rs/foundry-toolchain@v1 + - name: Install linux deps run: | sudo apt-get install --no-install-recommends -y \ From fe60bc896db3d0158d398f3c38dc3f5059dc472a Mon Sep 17 00:00:00 2001 From: duckception Date: Tue, 12 Sep 2023 03:29:50 +0200 Subject: [PATCH 19/19] Fix dot --- commands/foundry.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commands/foundry.js b/commands/foundry.js index d112a18a4..bccd1981e 100644 --- a/commands/foundry.js +++ b/commands/foundry.js @@ -187,7 +187,7 @@ async function validateIfAnvilIsInstalledOrThrow() { await which('anvil'); } catch (e) { throw new AnvilNotInstalledError( - 'Anvil not detected!. Forking is possible thanks to Anvil, a local testnet node shipped with Foundry. To install the Foundry toolchain please refer here: https://book.getfoundry.sh/getting-started/installation', + 'Anvil not detected! Forking is possible thanks to Anvil, a local testnet node shipped with Foundry. To install the Foundry toolchain please refer here: https://book.getfoundry.sh/getting-started/installation', ); } }