diff --git a/wallets/metamask/cypress.config.ts b/wallets/metamask/cypress.config.ts index fb9e2c158..18b0c5dd6 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 e11dfc377..ed06b3d7b 100644 --- a/wallets/metamask/src/cypress/MetaMask.ts +++ b/wallets/metamask/src/cypress/MetaMask.ts @@ -296,6 +296,13 @@ export default class MetaMask { } async confirmTransactionAndWaitForMining() { + await waitFor( + () => + this.metamaskExtensionPage.locator(TransactionPage.nftApproveAllConfirmationPopup.approveButton).isVisible(), + 5_000, + false + ) + return this.metamaskPlaywright .confirmTransactionAndWaitForMining() .then(() => { @@ -336,6 +343,22 @@ export default class MetaMask { await this.metamaskPlaywright.goBackToHomePage() await expect(this.metamaskExtensionPage.locator(HomePageSelectors.copyAccountAddressButton)).toBeVisible() + } + + // Lock/Unlock + + async lock() { + await this.metamaskPlaywright.lock() + await expect( + this.metamaskExtensionPage.locator(this.metamaskPlaywright.lockPage.selectors.submitButton) + ).toBeVisible() + + return true + } + + async unlock() { + await this.metamaskPlaywright.unlock() + await expect(this.metamaskExtensionPage.locator(this.metamaskPlaywright.homePage.selectors.logo)).toBeVisible() return true } diff --git a/wallets/metamask/src/cypress/configureSynpress.ts b/wallets/metamask/src/cypress/configureSynpress.ts index 51cd93db3..5cdebda02 100644 --- a/wallets/metamask/src/cypress/configureSynpress.ts +++ b/wallets/metamask/src/cypress/configureSynpress.ts @@ -130,6 +130,10 @@ export default function configureSynpress( openTransactionDetails: (txIndex: number) => metamask?.openTransactionDetails(txIndex), closeTransactionDetails: () => metamask?.closeTransactionDetails(), + // Lock/Unlock + lock: () => metamask?.lock(), + unlock: () => metamask?.unlock() + // Others goBackToHomePage: () => metamask?.goBackToHomePage() diff --git a/wallets/metamask/src/cypress/support/synpressCommands.ts b/wallets/metamask/src/cypress/support/synpressCommands.ts index a83791253..24ffbbb7e 100644 --- a/wallets/metamask/src/cypress/support/synpressCommands.ts +++ b/wallets/metamask/src/cypress/support/synpressCommands.ts @@ -61,6 +61,9 @@ declare global { openTransactionDetails(txIndex: number): Chainable closeTransactionDetails(): Chainable + lock(): Chainable + unlock(): Chainable + goBackToHomePage(): Chainable } } @@ -168,6 +171,15 @@ export default function synpressCommands() { Cypress.Commands.add('rejectTokenPermission', () => { return cy.task('rejectTokenPermission') }) + + // Lock/Unlock + + Cypress.Commands.add('lock', () => { + return cy.task('lock') + }) + Cypress.Commands.add('unlock', () => { + return cy.task('unlock') + }) // Others diff --git a/wallets/metamask/test/cypress/batchTransfer.cy.ts b/wallets/metamask/test/cypress/batchTransfer.cy.ts index b86705344..70fc2da53 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 d336ecdc6..603c40ea7 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 84d693e8d..8c42e74cc 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 000000000..b88d9d13f --- /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 dcc9d60de..54e999e96 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/lock.cy.ts b/wallets/metamask/test/cypress/lock.cy.ts new file mode 100644 index 000000000..dbd67aed2 --- /dev/null +++ b/wallets/metamask/test/cypress/lock.cy.ts @@ -0,0 +1,5 @@ +it('should lock & unlock the wallet without any error', () => { + cy.lock().then(() => { + cy.unlock() + }) +}) diff --git a/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts b/wallets/metamask/test/cypress/rejectAddNetwork.cy.ts index 1e23a418d..c2993db90 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') -})