diff --git a/wallets/metamask/src/cypress/configureSynpress.ts b/wallets/metamask/src/cypress/configureSynpress.ts index 90744be65..b2df17095 100644 --- a/wallets/metamask/src/cypress/configureSynpress.ts +++ b/wallets/metamask/src/cypress/configureSynpress.ts @@ -1,7 +1,7 @@ import type { BrowserContext, Page } from '@playwright/test' import { expect } from '@playwright/test' import { ensureRdpPort } from '@synthetixio/synpress-core' -import { type CreateAnvilOptions, createPool } from '@viem/anvil' +import { type CreateAnvilOptions, type Pool, createPool } from '@viem/anvil' import { waitFor } from '../playwright/utils/waitFor' import HomePageSelectors from '../selectors/pages/HomePage' import Selectors from '../selectors/pages/HomePage' @@ -19,6 +19,8 @@ let metamaskExtensionId: string let metamaskExtensionPage: Page +let pool: Pool + // TODO: Implement if needed to change the focus between pages // let cypressPage: Page @@ -151,7 +153,7 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr }, async createAnvilNode(options?: CreateAnvilOptions) { - const pool = createPool() + pool = createPool() const nodeId = Array.from(pool.instances()).length const anvil = await pool.start(nodeId, options) @@ -164,6 +166,11 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr return { anvil, rpcUrl, chainId } }, + async emptyAnvilNode() { + await pool.empty() + return true + }, + async connectToAnvil({ rpcUrl, chainId @@ -226,6 +233,22 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr return true }, + async approveNewNetwork() { + const metamask = getPlaywrightMetamask(context, metamaskExtensionPage, metamaskExtensionId) + + await metamask.approveNewNetwork() + + return true + }, + + async approveSwitchNetwork() { + const metamask = getPlaywrightMetamask(context, metamaskExtensionPage, metamaskExtensionId) + + await metamask.approveSwitchNetwork() + + return true + }, + // Others async providePublicEncryptionKey() { @@ -278,6 +301,19 @@ export default function configureSynpress(on: Cypress.PluginEvents, config: Cypr .catch(() => { return false }) + }, + + async confirmTransactionAndWaitForMining() { + const metamask = getPlaywrightMetamask(context, metamaskExtensionPage, metamaskExtensionId) + + return metamask + .confirmTransactionAndWaitForMining() + .then(() => { + return true + }) + .catch(() => { + return false + }) } }) diff --git a/wallets/metamask/src/cypress/support/synpressCommands.ts b/wallets/metamask/src/cypress/support/synpressCommands.ts index a0cf879f7..7dcb3e82f 100644 --- a/wallets/metamask/src/cypress/support/synpressCommands.ts +++ b/wallets/metamask/src/cypress/support/synpressCommands.ts @@ -31,7 +31,10 @@ declare global { chainId: number }> connectToAnvil(): Chainable + emptyAnvilNode(): Chainable addNetwork(network: Network): Chainable + approveNewNetwork(): Chainable + approveSwitchNetwork(): Chainable deployToken(): Chainable addNewToken(): Chainable @@ -40,6 +43,7 @@ declare global { decrypt(): Chainable confirmSignature(): Chainable confirmTransaction(): Chainable + confirmTransactionAndWaitForMining(): Chainable } } } @@ -95,9 +99,18 @@ export default function synpressCommands() { return cy.task('addNetwork', network) }) }) + Cypress.Commands.add('emptyAnvilNode', () => { + return cy.task('emptyAnvilNode') + }) Cypress.Commands.add('addNetwork', (network: Network) => { return cy.task('addNetwork', network) }) + Cypress.Commands.add('approveNewNetwork', () => { + return cy.task('approveNewNetwork') + }) + Cypress.Commands.add('approveSwitchNetwork', () => { + return cy.task('approveSwitchNetwork') + }) // Token @@ -122,4 +135,7 @@ export default function synpressCommands() { Cypress.Commands.add('confirmTransaction', () => { return cy.task('confirmTransaction') }) + Cypress.Commands.add('confirmTransactionAndWaitForMining', () => { + return cy.task('confirmTransactionAndWaitForMining') + }) } diff --git a/wallets/metamask/test/cypress/addNewToken.cy.ts b/wallets/metamask/test/cypress/addNewToken.cy.ts index 9a8803fff..535c4710c 100644 --- a/wallets/metamask/test/cypress/addNewToken.cy.ts +++ b/wallets/metamask/test/cypress/addNewToken.cy.ts @@ -1,6 +1,5 @@ before(() => { cy.getNetwork().then((network) => { - console.log(network) if (network !== 'Anvil') { cy.switchNetwork('Anvil') } diff --git a/wallets/metamask/test/cypress/approveNewNetwork.cy.ts b/wallets/metamask/test/cypress/approveNewNetwork.cy.ts new file mode 100644 index 000000000..dcf46a385 --- /dev/null +++ b/wallets/metamask/test/cypress/approveNewNetwork.cy.ts @@ -0,0 +1,16 @@ +it('should add a new network', () => { + cy.createAnvilNode({ + chainId: 1338, + port: 8546 + }).then(() => { + cy.get('#addEthereumChain').click() + + cy.approveNewNetwork().then(() => { + cy.approveSwitchNetwork().then(() => { + cy.get('#chainId').should('have.text', '0x53a') + + cy.emptyAnvilNode() + }) + }) + }) +}) diff --git a/wallets/metamask/test/cypress/approveSwitchNetwork.cy.ts b/wallets/metamask/test/cypress/approveSwitchNetwork.cy.ts new file mode 100644 index 000000000..ee02a4999 --- /dev/null +++ b/wallets/metamask/test/cypress/approveSwitchNetwork.cy.ts @@ -0,0 +1,16 @@ +it('should switch to the requested network', () => { + cy.createAnvilNode({ + chainId: 1338, + port: 8546 + }).then(() => { + cy.switchNetwork('Ethereum Mainnet').then(() => { + cy.get('#chainId').should('have.text', '0x1') + + cy.get('#switchEthereumChain').click() + + cy.approveSwitchNetwork().then(() => { + cy.get('#chainId').should('have.text', '0x53a') + }) + }) + }) +}) diff --git a/wallets/metamask/test/cypress/batchTransfer.cy.ts b/wallets/metamask/test/cypress/batchTransfer.cy.ts new file mode 100644 index 000000000..b86705344 --- /dev/null +++ b/wallets/metamask/test/cypress/batchTransfer.cy.ts @@ -0,0 +1,19 @@ +before(() => { + cy.get('#deployERC1155Button').click() + + cy.confirmTransaction().then(() => { + cy.wait(5000) + + cy.get('#batchMintButton').click() + + cy.confirmTransactionAndWaitForMining() + }) +}) + +it('should perform batch ERC115 transfer', () => { + cy.get('#batchTransferFromButton').click() + + cy.confirmTransaction().then(() => { + cy.get('#erc1155Status').should('have.text', 'Batch Transfer From completed') + }) +})