From 99792cf4177379fa985d6c64ca2479b4755a7ffa Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Thu, 25 Jan 2024 18:22:10 +0100 Subject: [PATCH 1/2] Promote `dev` to `master` (#1085) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove leftover TODOs * Remove text based locators * Add `Known problems with MetaMask` section * Remove Promise wrap from `cy.setupMetamask()` (#927) * Fix localized Chrome's extension id (#928) * Fix localized Chrome's extension id * Improve id handling --------- Co-authored-by: Piotr Frankowski * Lint * Feature/revoke permission to all (#932) * Fix typo in Permission word * Add permission revoking actions * Add tests for permission revoking actions * Regenerate synpress commands file * Add `switchNetwork` option to `acceptAccess` function * Add new release section to README * Use `goerli` for testing (#1082) * Use `goerli` for testing * Trigger tests * Add `shouldWaitForPopupClosure` option to approvals and txs (#1081) --------- Co-authored-by: Peter F Co-authored-by: Piotr Frankowski Co-authored-by: Rafał Majchrzak --- README.md | 15 +++++ commands/metamask.js | 14 +++-- docs/synpress-commands.md | 26 ++++---- support/commands.js | 22 +++++-- support/index.d.ts | 36 ++++++----- tests/e2e/specs/metamask-spec.js | 100 +++++++++++++++++++++---------- 6 files changed, 146 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index e967ec303..832a9bab3 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,21 @@ it directly. Check [usage examples](https://github.com/Synthetixio/synpress/#usage-examples) for more details. +# ♨️ New release + +⚠️ This branch showcases the current stable release of Synpress which will receive **only** critical hotfixes. ⚠️ + +Active development of the upcoming version of Synpress is happening on [this branch](https://github.com/Synthetixio/synpress/tree/new-dawn). +The new release is a full rewrite of Synpress and will feature major breaking changes, and multitude of new features and improvements across the board such as: +- ⭐ Full TypeScript support +- ⭐ Multi-wallet support +- ⭐ Full parallelism support +- ⭐ Test runtime speed **faster** than any other Web3 alternative, and **equal** to native Web2 frameworks + +Curious and want to learn more? 🤓 + +[Read this Twitter thread 🧵](https://twitter.com/0xDuckception/status/1712961542176596054) and do not forget to check out the attached document there! + # Table of content - [](#) diff --git a/commands/metamask.js b/commands/metamask.js index fdad8daad..6f24d067f 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -852,7 +852,10 @@ const metamask = { ); return true; }, - async confirmPermissionToSpend(spendLimit) { + async confirmPermissionToSpend({ + spendLimit, + shouldWaitForPopupClosure = false, + } = {}) { const notificationPage = await playwright.switchToMetamaskNotification(); // experimental mode on if ( @@ -874,7 +877,7 @@ const metamask = { await playwright.waitAndClick( notificationPageElements.allowToSpendButton, notificationPage, - { waitForEvent: 'close' }, + shouldWaitForPopupClosure ? undefined : { waitForEvent: 'close' }, ); return true; }, @@ -963,7 +966,10 @@ const metamask = { ); return true; }, - async confirmTransaction(gasConfig) { + async confirmTransaction({ + gasConfig, + shouldWaitForPopupClosure = false, + } = {}) { let txData = {}; const notificationPage = await playwright.switchToMetamaskNotification(); if (gasConfig) { @@ -1189,7 +1195,7 @@ const metamask = { await playwright.waitAndClick( confirmPageElements.confirmButton, notificationPage, - { waitForEvent: 'close' }, + shouldWaitForPopupClosure ? undefined : { waitForEvent: 'close' }, ); txData.confirmed = true; log('[confirmTransaction] Transaction confirmed!'); diff --git a/docs/synpress-commands.md b/docs/synpress-commands.md index 2ae6bee81..4fe192a18 100644 --- a/docs/synpress-commands.md +++ b/docs/synpress-commands.md @@ -344,7 +344,10 @@ rejectMetamaskAddToken(): Chainable; Confirm metamask permission to spend asset. ```ts -confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable; +confirmMetamaskPermissionToSpend(options: { + spendLimit?: string + shouldWaitForPopupClosure?: boolean +}): Chainable; ``` #### `cy.confirmMetamaskPermissionToApproveAll()` @@ -415,22 +418,23 @@ rejectMetamaskAccess(): Chainable; Confirm metamask transaction (auto-detects eip-1559 and legacy transactions). ```ts -confirmMetamaskTransaction( - gasConfig?: +confirmMetamaskTransaction(options: { + gasConfig: | { - gasLimit?: number; - baseFee?: number; - priorityFee?: number; + gasLimit?: number; + baseFee?: number; + priorityFee?: number; } | { - gasLimit?: number; - gasPrice?: number; - } + gasLimit?: number; + gasPrice?: number; + } | 'low' | 'market' | 'aggressive' - | 'site', -): Chainable; + | 'site', + shouldWaitForPopupClosure?: boolean +}): Chainable; ``` #### `cy.confirmMetamaskTransactionAndWaitForMining()` diff --git a/support/commands.js b/support/commands.js index 282ab8b3e..664571457 100644 --- a/support/commands.js +++ b/support/commands.js @@ -175,8 +175,14 @@ Cypress.Commands.add('rejectMetamaskAddToken', () => { Cypress.Commands.add( 'confirmMetamaskPermissionToSpend', - (spendLimit = '999999999999999999') => { - return cy.task('confirmMetamaskPermissionToSpend', spendLimit); + ({ + spendLimit = '999999999999999999', + shouldWaitForPopupClosure = false, + } = {}) => { + return cy.task('confirmMetamaskPermissionToSpend', { + spendLimit, + shouldWaitForPopupClosure, + }); }, ); @@ -192,9 +198,15 @@ Cypress.Commands.add('rejectMetamaskAccess', () => { return cy.task('rejectMetamaskAccess'); }); -Cypress.Commands.add('confirmMetamaskTransaction', gasConfig => { - return cy.task('confirmMetamaskTransaction', gasConfig); -}); +Cypress.Commands.add( + 'confirmMetamaskTransaction', + ({ gasConfig, shouldWaitForPopupClosure = false } = {}) => { + return cy.task('confirmMetamaskTransaction', { + gasConfig, + shouldWaitForPopupClosure, + }); + }, +); Cypress.Commands.add( 'confirmMetamaskTransactionAndWaitForMining', diff --git a/support/index.d.ts b/support/index.d.ts index 68d42b311..820a9dcae 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -272,9 +272,13 @@ declare namespace Cypress { * Confirm metamask permission to spend asset * @example * cy.confirmMetamaskPermissionToSpend() - * cy.confirmMetamaskPermissionToSpend('999999999') + * cy.confirmMetamaskPermissionToSpend({ spendLimit: '999999999' }) + * cy.confirmMetamaskPermissionToSpend({ spendLimit: '999999999', shouldWaitForPopupClosure: false }) */ - confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable; + confirmMetamaskPermissionToSpend(options: { + spendLimit?: string + shouldWaitForPopupClosure?: boolean + }): Chainable; /** * Confirm metamask permission to access all elements (example: collectibles) * @example @@ -327,26 +331,28 @@ declare namespace Cypress { * Confirm metamask transaction (auto-detects eip-1559 and legacy transactions) * @example * cy.confirmMetamaskTransaction() - * cy.confirmMetamaskTransaction({ gasLimit: 1000000, baseFee: 20, priorityFee: 20 }) // eip-1559 - * cy.confirmMetamaskTransaction({ gasLimit: 1000000, gasPrice: 20 }) // legacy - * cy.confirmMetamaskTransaction('aggressive') // eip-1559 only! => available options: 'low', 'market', 'aggressive', 'site' (site is usually by default) + * cy.confirmMetamaskTransaction({ gasConfig: { gasLimit: 1000000, baseFee: 20, priorityFee: 20 } }) // eip-1559 + * cy.confirmMetamaskTransaction({ gasConfig: { gasLimit: 1000000, gasPrice: 20 } }) // legacy + * cy.confirmMetamaskTransaction({ gasConfig: 'aggressive' }) // eip-1559 only! => available options: 'low', 'market', 'aggressive', 'site' (site is usually by default) + * cy.confirmMetamaskTransaction({ shouldWaitForPopupClosure: false }) */ - confirmMetamaskTransaction( - gasConfig?: + confirmMetamaskTransaction(options: { + gasConfig: | { - gasLimit?: number; - baseFee?: number; - priorityFee?: number; - } + gasLimit?: number; + baseFee?: number; + priorityFee?: number; + } | { - gasLimit?: number; - gasPrice?: number; - } + gasLimit?: number; + gasPrice?: number; + } | 'low' | 'market' | 'aggressive' | 'site', - ): Chainable; + shouldWaitForPopupClosure?: boolean + }): Chainable; /** * Confirm metamask transaction (auto-detects eip-1559 and legacy transactions) and wait for ALL pending transactions to be mined * @example diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index 4cbdcf635..aa45e0f3f 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -5,7 +5,7 @@ describe('Metamask', () => { it(`setupMetamask should finish metamask setup using secret words`, () => { cy.setupMetamask( 'test test test test test test test test test test test junk', - 'sepolia', + 'goerli', 'Tester@1234', ).then(setupFinished => { expect(setupFinished).to.be.true; @@ -33,8 +33,8 @@ describe('Metamask', () => { cy.acceptMetamaskAccess().then(connected => { expect(connected).to.be.true; }); - cy.get('#network').contains('11155111'); - cy.get('#chainId').contains('0xaa36a7'); + cy.get('#network').contains('5'); + cy.get('#chainId').contains('0x5'); cy.get('#accounts').should( 'have.text', '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266', @@ -49,8 +49,8 @@ describe('Metamask', () => { }); 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.name).to.match(/goerli/i); + expect(network.id).to.be.equal(5); expect(network.testnet).to.be.true; }); }); @@ -59,12 +59,12 @@ describe('Metamask', () => { cy.addMetamaskNetwork({ networkName: 'anvil', rpcUrl: 'http://127.0.0.1:8545', - chainId: 11155111, + chainId: 5, symbol: 'aETH', isTestnet: true, }); - cy.get('#network').contains('11155111'); - cy.get('#chainId').contains('0xaa36a7'); + cy.get('#network').contains('5'); + cy.get('#chainId').contains('0x5'); } else { cy.addMetamaskNetwork({ networkName: 'Optimism Network', @@ -84,7 +84,7 @@ describe('Metamask', () => { cy.getCurrentNetwork().then(network => { if (Cypress.env('USE_ANVIL')) { expect(network.name).to.be.equal('anvil'); - expect(network.id).to.be.equal(11155111); + expect(network.id).to.be.equal(5); expect(network.testnet).to.be.true; } else { expect(network.name).to.match(/optimism network/i); @@ -117,15 +117,15 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('anvil').then(networkChanged => { expect(networkChanged).to.be.true; }); - cy.get('#network').contains('0xaa36a7'); - cy.get('#chainId').contains('0xaa36a7'); + cy.get('#network').contains('0x5'); + cy.get('#chainId').contains('0x5'); } else { cy.changeMetamaskNetwork('optimism network').then(networkChanged => { expect(networkChanged).to.be.true; }); cy.get('#network').contains('0xa'); cy.get('#chainId').contains('0xa'); - cy.changeMetamaskNetwork('sepolia'); + cy.changeMetamaskNetwork('goerli'); } }); it(`rejectMetamaskPermissionToApproveAll should reject permission to approve all NFTs upon warning`, () => { @@ -347,12 +347,26 @@ describe('Metamask', () => { it(`confirmMetamaskTransaction should confirm legacy transaction using advanced gas settings`, () => { cy.get('#sendButton').click(); cy.confirmMetamaskTransaction({ - gasLimit: 210000, - gasPrice: 100, + gasConfig: { + gasLimit: 210000, + gasPrice: 100, + }, }).then(txData => { expect(txData.confirmed).to.be.true; }); }); + it(`confirmMetamaskTransaction should work for serial transactions`, () => { + cy.get('#sendEIP1559Button').click(); + cy.get('#sendEIP1559Button').click(); + cy.confirmMetamaskTransaction({ + shouldWaitForPopupClosure: true, + }).then(txData => { + expect(txData.confirmed).to.be.true; + }); + cy.confirmMetamaskTransaction().then(txData => { + expect(txData.confirmed).to.be.true; + }); + }); it(`confirmMetamaskTransaction should confirm legacy ETH transfer to yourself`, () => { cy.get('#fromInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); cy.get('#toInput').type('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266'); @@ -373,28 +387,38 @@ describe('Metamask', () => { }); 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 => { + cy.confirmMetamaskTransaction({ + gasConfig: 'low', + }).then(txData => { expect(txData.confirmed).to.be.true; }); cy.get('#sendEIP1559Button').click(); - cy.confirmMetamaskTransaction('market').then(txData => { + cy.confirmMetamaskTransaction({ + gasConfig: 'market', + }).then(txData => { expect(txData.confirmed).to.be.true; }); cy.get('#sendEIP1559Button').click(); - cy.confirmMetamaskTransaction('aggressive').then(txData => { + cy.confirmMetamaskTransaction({ + gasConfig: 'aggressive', + }).then(txData => { expect(txData.confirmed).to.be.true; }); cy.get('#sendEIP1559Button').click(); - cy.confirmMetamaskTransaction('site').then(txData => { + cy.confirmMetamaskTransaction({ + gasConfig: 'site', + }).then(txData => { expect(txData.confirmed).to.be.true; }); }); it(`confirmMetamaskTransaction should confirm eip-1559 transaction using advanced gas settings`, () => { cy.get('#sendEIP1559Button').click(); cy.confirmMetamaskTransaction({ - gasLimit: 210000, - baseFee: 100, - priorityFee: 10, + gasConfig: { + gasLimit: 210000, + baseFee: 100, + priorityFee: 10, + }, }).then(txData => { expect(txData.confirmed).to.be.true; }); @@ -488,28 +512,28 @@ describe('Metamask', () => { }); }); it(`importMetamaskToken should import token to metamask`, () => { - const USDCContractAddressOnSepolia = - '0xda9d4f9b69ac6C22e444eD9aF0CfC043b7a7f53f'; - cy.importMetamaskToken(USDCContractAddressOnSepolia).then(tokenData => { + const tetherContractAddressOnGoerli = + '0x509Ee0d083DdF8AC028f2a56731412edD63223B9'; + cy.importMetamaskToken(tetherContractAddressOnGoerli).then(tokenData => { expect(tokenData.tokenContractAddress).to.be.equal( - USDCContractAddressOnSepolia, + tetherContractAddressOnGoerli, ); - expect(tokenData.tokenSymbol).to.be.equal('USDC'); + expect(tokenData.tokenSymbol).to.be.equal('USDT'); expect(tokenData.tokenDecimals).to.be.equal('6'); expect(tokenData.imported).to.be.true; }); }); it(`importMetamaskToken should import token to metamask using advanced token settings`, () => { - const tDAIContractAddressOnSepolia = - '0x53844F9577C2334e541Aec7Df7174ECe5dF1fCf0'; + const daiContractAddressOnGoerli = + '0x5233d9FeA273A88c3c8672910042E63850ddF9aa'; cy.importMetamaskToken({ - address: tDAIContractAddressOnSepolia, - symbol: 'IADt', + address: daiContractAddressOnGoerli, + symbol: 'xDAI', }).then(tokenData => { expect(tokenData.tokenContractAddress).to.be.equal( - tDAIContractAddressOnSepolia, + daiContractAddressOnGoerli, ); - expect(tokenData.tokenSymbol).to.be.equal('IADt'); + expect(tokenData.tokenSymbol).to.be.equal('xDAI'); expect(tokenData.tokenDecimals).to.be.equal('18'); expect(tokenData.imported).to.be.true; }); @@ -526,6 +550,18 @@ describe('Metamask', () => { expect(approved).to.be.true; }); }); + it(`confirmMetamaskPermissionToSpend should work for serial transactions`, () => { + cy.get('#approveTokens').click(); + cy.get('#approveTokens').click(); + cy.confirmMetamaskPermissionToSpend({ + shouldWaitForPopupClosure: true, + }).then(approved => { + expect(approved).to.be.true; + }); + cy.confirmMetamaskPermissionToSpend().then(approved => { + expect(approved).to.be.true; + }); + }); it(`rejectMetamaskToAddNetwork should reject permission to add network`, () => { cy.get('#addEthereumChain').click(); cy.rejectMetamaskToAddNetwork().then(rejected => { From 6ecd47f62da37ddff3cf8937db681257acb4d810 Mon Sep 17 00:00:00 2001 From: Jakub Date: Thu, 25 Jan 2024 17:22:58 +0000 Subject: [PATCH 2/2] release: v3.7.2-beta.10 Signed-off-by: Jakub --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 69ec585ac..fcb3a8e8d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@synthetixio/synpress", - "version": "3.7.2-beta.9", + "version": "3.7.2-beta.10", "packageManager": "pnpm@8.4.0", "description": "Synpress is e2e testing framework based around Cypress.io & playwright with included MetaMask support. Test your dapps with ease.", "keywords": [