From 29efce35c44a8839ba3f57b0bdf39cc292daf84b Mon Sep 17 00:00:00 2001 From: styler <63294765+matstyler@users.noreply.github.com> Date: Mon, 16 Sep 2024 02:09:39 +0200 Subject: [PATCH] feat: confirmTransactionAndWaitForMining using Cypress (#1216) --- wallets/metamask/cypress.config.ts | 5 ++- wallets/metamask/src/cypress/MetaMask.ts | 7 ++++ .../metamask/test/cypress/batchTransfer.cy.ts | 2 ++ .../test/cypress/confirmSignature.cy.ts | 4 --- .../test/cypress/confirmTransaction.cy.ts | 8 ----- .../confirmTransactionAndWaitForMining.cy.ts | 32 +++++++++++++++++++ .../metamask/test/cypress/connectToDapp.cy.ts | 2 +- .../test/cypress/rejectAddNetwork.cy.ts | 17 +++------- 8 files changed, 50 insertions(+), 27 deletions(-) create mode 100644 wallets/metamask/test/cypress/confirmTransactionAndWaitForMining.cy.ts diff --git a/wallets/metamask/cypress.config.ts b/wallets/metamask/cypress.config.ts index fb9e2c15..18b0c5dd 100644 --- a/wallets/metamask/cypress.config.ts +++ b/wallets/metamask/cypress.config.ts @@ -12,5 +12,8 @@ export default defineConfig({ async setupNodeEvents(on, config) { return configureSynpress(on, config) } - } + }, + + defaultCommandTimeout: 12_000, + taskTimeout: 15_000 }) diff --git a/wallets/metamask/src/cypress/MetaMask.ts b/wallets/metamask/src/cypress/MetaMask.ts index 16cded46..5c4cdf85 100644 --- a/wallets/metamask/src/cypress/MetaMask.ts +++ b/wallets/metamask/src/cypress/MetaMask.ts @@ -285,6 +285,13 @@ export default class MetaMask { } async confirmTransactionAndWaitForMining() { + await waitFor( + () => + this.metamaskExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(), + 5_000, + false + ) + return this.metamaskPlaywright .confirmTransactionAndWaitForMining() .then(() => { diff --git a/wallets/metamask/test/cypress/batchTransfer.cy.ts b/wallets/metamask/test/cypress/batchTransfer.cy.ts index b8670534..70fc2da5 100644 --- a/wallets/metamask/test/cypress/batchTransfer.cy.ts +++ b/wallets/metamask/test/cypress/batchTransfer.cy.ts @@ -1,4 +1,6 @@ before(() => { + cy.switchNetwork('Anvil') + cy.get('#deployERC1155Button').click() cy.confirmTransaction().then(() => { diff --git a/wallets/metamask/test/cypress/confirmSignature.cy.ts b/wallets/metamask/test/cypress/confirmSignature.cy.ts index d336ecdc..603c40ea 100644 --- a/wallets/metamask/test/cypress/confirmSignature.cy.ts +++ b/wallets/metamask/test/cypress/confirmSignature.cy.ts @@ -1,7 +1,3 @@ -before(() => { - cy.switchNetwork('Anvil') -}) - it('should confirm `personal_sign`', () => { cy.get('#personalSign').click() diff --git a/wallets/metamask/test/cypress/confirmTransaction.cy.ts b/wallets/metamask/test/cypress/confirmTransaction.cy.ts index 84d693e8..8c42e74c 100644 --- a/wallets/metamask/test/cypress/confirmTransaction.cy.ts +++ b/wallets/metamask/test/cypress/confirmTransaction.cy.ts @@ -15,14 +15,6 @@ const connectDeployAndMintNft = () => { }) } -before(() => { - cy.connectToAnvil().then(() => { - cy.get('#connectButton').click() - - cy.connectToDapp() - }) -}) - describe('with default gas setting', () => { it('should confirm contract deployment', () => { cy.get('#tokenAddresses').should('be.empty') diff --git a/wallets/metamask/test/cypress/confirmTransactionAndWaitForMining.cy.ts b/wallets/metamask/test/cypress/confirmTransactionAndWaitForMining.cy.ts new file mode 100644 index 00000000..b88d9d13 --- /dev/null +++ b/wallets/metamask/test/cypress/confirmTransactionAndWaitForMining.cy.ts @@ -0,0 +1,32 @@ +it('should confirm contract deployment and wait for mining', () => { + cy.get('#tokenAddresses').should('be.empty') + cy.get('#createToken').click() + + cy.confirmTransactionAndWaitForMining().then(() => { + cy.get('#tokenAddresses').should('include', /^0x/) + }) +}) + +it('should confirm legacy transaction and wait for mining', () => { + cy.get('#sendButton').click() + + cy.confirmTransactionAndWaitForMining() +}) + +it('should confirm EIP-1559 transaction and wait for mining', () => { + cy.get('#sendEIP1559Button').click() + + cy.confirmTransactionAndWaitForMining().then(() => { + cy.get('#tokenAddresses').should('include', /^0x/) + }) +}) + +it('should work correctly when calling sequentially', () => { + cy.get('#sendEIP1559Button').click() + cy.confirmTransactionAndWaitForMining().then(() => { + cy.get('#sendEIP1559Button').click() + cy.confirmTransactionAndWaitForMining().then(() => { + cy.get('#tokenAddresses').should('include', /^0x/) + }) + }) +}) diff --git a/wallets/metamask/test/cypress/connectToDapp.cy.ts b/wallets/metamask/test/cypress/connectToDapp.cy.ts index dcc9d60d..54e999e9 100644 --- a/wallets/metamask/test/cypress/connectToDapp.cy.ts +++ b/wallets/metamask/test/cypress/connectToDapp.cy.ts @@ -6,5 +6,5 @@ it('should connect account to the app', () => { cy.get('#connectButton').click() cy.connectToDapp() - cy.get('#accounts').should('contain', '0x') + cy.get('#accounts').should('include', /^0x/) }) diff --git a/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts b/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts index 1e23a418..c2993db9 100644 --- a/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts +++ b/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts @@ -1,18 +1,9 @@ it('should reject new network request', () => { - cy.createAnvilNode({ - chainId: 1338, - port: 8546 - }).then(() => { - cy.get('#addEthereumChain').click() + cy.get('#addEthereumChain').click() - cy.rejectNewNetwork().then(() => { - cy.get('#chainId').should('have.text', '0x1') + cy.rejectNewNetwork().then(() => { + cy.get('#chainId').should('have.text', '0x7a69') - cy.emptyAnvilNode() - }) + cy.emptyAnvilNode() }) }) - -after(() => { - cy.switchNetwork('Ethereum Mainnet') -})