From f94c34d55aa226b43a4de697441594d154e50b03 Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Wed, 18 Oct 2023 23:13:42 +0200 Subject: [PATCH] Promote `dev` to `master` (#939) 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 --------- Co-authored-by: Peter F Co-authored-by: Piotr Frankowski Co-authored-by: Rafał Majchrzak --- README.md | 9 ++ commands/metamask.js | 43 ++++-- commands/playwright.js | 28 ++-- docs/synpress-commands.md | 227 +++++++++++++++++++++---------- plugins/index.js | 7 +- support/commands.js | 16 ++- support/index.d.ts | 34 +++-- support/index.js | 4 +- tests/e2e/specs/metamask-spec.js | 20 ++- 9 files changed, 273 insertions(+), 115 deletions(-) diff --git a/README.md b/README.md index 981f5e026..e967ec303 100644 --- a/README.md +++ b/README.md @@ -441,6 +441,15 @@ Options: -h, --help display help for command ``` +## 👨‍⚕️ Known problems with MetaMask + +If your MetaMask is stuck on the loading screen, check what's happening under the hood in the console. You can find vital information about why it's stuck on this step. + +#### ⭐ Sentry.io HTTP error 499 (Request has been forbidden by antivirus) + +- Kaspersky antivirus sometimes blocks encrypted requests to Sentry.io. You can disable + this feature in Kaspersky advanced settings by toggling on `"Do not scan encrypted connections"`. + ## 📃 Environmental variables | Variable | Description | diff --git a/commands/metamask.js b/commands/metamask.js index 2c217513a..5e6e726e7 100644 --- a/commands/metamask.js +++ b/commands/metamask.js @@ -1221,11 +1221,11 @@ const metamask = { // 120 seconds while (retries < retiresLimit) { - const pendingTxs = await playwright // TODO rename + const pendingTxs = await playwright .metamaskWindow() .getByText('Pending') .count(); - const queuedTxs = await playwright // TODO rename + const queuedTxs = await playwright .metamaskWindow() .getByText('Queued') .count(); @@ -1266,13 +1266,19 @@ const metamask = { .locator( `${mainPageElements.activityTab.completedTransactionsList} > div`, ) - .filter({ hasNotText: 'History' }) - .filter({ hasNotText: 'View more' }) + .filter({ + has: playwright.metamaskWindow().locator('div.list-item__heading'), + }) .all(); while (txIndex >= visibleTxs.length) { try { - await playwright.metamaskWindow().getByText('View more').click(); + await playwright + .metamaskWindow() + .locator( + `${mainPageElements.activityTab.completedTransactionsList} > button`, + ) + .click(); } catch (error) { log('[openTransactionDetails] Clicking "View more" failed!'); throw new Error( @@ -1285,8 +1291,9 @@ const metamask = { .locator( `${mainPageElements.activityTab.completedTransactionsList} > div`, ) - .filter({ hasNotText: 'History' }) - .filter({ hasNotText: 'View more' }) + .filter({ + has: playwright.metamaskWindow().locator('div.list-item__heading'), + }) .all(); } @@ -1341,7 +1348,7 @@ const metamask = { ); return true; }, - async confirmPermisionToApproveAll() { + async confirmPermissionToApproveAll() { const notificationPage = await playwright.switchToMetamaskNotification(); await playwright.waitAndClick( notificationPageElements.allowToSpendButton, @@ -1354,7 +1361,7 @@ const metamask = { ); return true; }, - async rejectPermisionToApproveAll() { + async rejectPermissionToApproveAll() { const notificationPage = await playwright.switchToMetamaskNotification(); await playwright.waitAndClick( notificationPageElements.allowToSpendButton, @@ -1367,6 +1374,24 @@ const metamask = { ); return true; }, + async confirmRevokePermissionToAll() { + const notificationPage = await playwright.switchToMetamaskNotification(); + await playwright.waitAndClick( + notificationPageElements.allowToSpendButton, + notificationPage, + { waitForEvent: 'close' }, + ); + return true; + }, + async rejectRevokePermissionToAll() { + const notificationPage = await playwright.switchToMetamaskNotification(); + await playwright.waitAndClick( + notificationPageElements.rejectToSpendButton, + notificationPage, + { waitForEvent: 'close' }, + ); + return true; + }, async allowToAddNetwork({ waitForEvent } = {}) { const notificationPage = await playwright.switchToMetamaskNotification(); if (waitForEvent) { diff --git a/commands/playwright.js b/commands/playwright.js index a474e8b5f..c71eaf205 100644 --- a/commands/playwright.js +++ b/commands/playwright.js @@ -57,6 +57,11 @@ module.exports = { activeTabName() { return activeTabName; }, + async metamaskExtensionId() { + const metamaskExtensionData = (await module.exports.getExtensionsData()) + .metamask; + return metamaskExtensionData.id; + }, async setExpectInstance(expect) { expectInstance = expect; }, @@ -87,8 +92,7 @@ module.exports = { return true; }, async assignWindows() { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); let pages = await browser.contexts()[0].pages(); for (const page of pages) { @@ -97,21 +101,21 @@ module.exports = { } else if ( page .url() - .includes(`chrome-extension://${metamaskExtensionData.id}/home.html`) + .includes(`chrome-extension://${metamaskExtensionId}/home.html`) ) { metamaskWindow = page; } else if ( page .url() .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, + `chrome-extension://${metamaskExtensionId}/notification.html`, ) ) { metamaskNotificationWindow = page; } else if ( page .url() - .includes(`chrome-extension://${metamaskExtensionData.id}/popup.html`) + .includes(`chrome-extension://${metamaskExtensionId}/popup.html`) ) { metamaskPopupWindow = page; } @@ -161,8 +165,7 @@ module.exports = { return true; }, async switchToMetamaskNotification() { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); let pages = await browser.contexts()[0].pages(); for (const page of pages) { @@ -170,7 +173,7 @@ module.exports = { page .url() .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, + `chrome-extension://${metamaskExtensionId}/notification.html`, ) ) { metamaskNotificationWindow = page; @@ -337,16 +340,13 @@ module.exports = { } }, async waitUntilStable(page) { - const metamaskExtensionData = (await module.exports.getExtensionsData()) - .metamask; + const metamaskExtensionId = await module.exports.metamaskExtensionId(); if ( page && page .url() - .includes( - `chrome-extension://${metamaskExtensionData.id}/notification.html`, - ) + .includes(`chrome-extension://${metamaskExtensionId}/notification.html`) ) { await page.waitForLoadState('load'); await page.waitForLoadState('domcontentloaded'); @@ -477,7 +477,7 @@ module.exports = { const extensionId = ( await extensionData.locator('#extension-id').textContent() - ).replace('ID: ', ''); + ).split(': ')[1]; extensionsData[extensionName] = { version: extensionVersion, diff --git a/docs/synpress-commands.md b/docs/synpress-commands.md index 408d800aa..8a5564c95 100644 --- a/docs/synpress-commands.md +++ b/docs/synpress-commands.md @@ -5,7 +5,7 @@ Connect playwright with Cypress instance. ```ts -initPlaywright(): Chainable; +initPlaywright(): Chainable; ``` #### `cy.assignWindows()` @@ -13,7 +13,7 @@ initPlaywright(): Chainable; Assign currently open tabs with playwright. ```ts -assignWindows(): Chainable; +assignWindows(): Chainable; ``` #### `cy.assignActiveTabName()` @@ -21,7 +21,7 @@ assignWindows(): Chainable; Assigns currently active tab. ```ts -assignActiveTabName(): Chainable; +assignActiveTabName(tabName: string): Chainable; ``` #### `cy.isMetamaskWindowActive()` @@ -29,7 +29,7 @@ assignActiveTabName(): Chainable; Checks if current active tab is metamask. ```ts -isMetamaskWindowActive(): Chainable; +isMetamaskWindowActive(): Chainable; ``` #### `cy.isCypressWindowActive()` @@ -37,7 +37,7 @@ isMetamaskWindowActive(): Chainable; Checks if current active tab is cypress. ```ts -isCypressWindowActive(): Chainable; +isCypressWindowActive(): Chainable; ``` #### `cy.switchToCypressWindow()` @@ -45,7 +45,7 @@ isCypressWindowActive(): Chainable; Switch to Cypress window. ```ts -switchToCypressWindow(): Chainable; +switchToCypressWindow(): Chainable; ``` #### `cy.switchToMetamaskWindow()` @@ -53,7 +53,7 @@ switchToCypressWindow(): Chainable; Switch to metamask window. ```ts -switchToMetamaskWindow(): Chainable; +switchToMetamaskWindow(): Chainable; ``` #### `cy.switchToMetamaskNotification()` @@ -61,7 +61,7 @@ switchToMetamaskWindow(): Chainable; Switch to metamask notification window. ```ts -switchToMetamaskNotification(): Chainable; +switchToMetamaskNotification(): Chainable; ``` #### `cy.getCurrentNetwork()` @@ -77,15 +77,26 @@ getCurrentNetwork(): Chainable; Add network in metamask (and also switch to the newly added network). ```ts -addMetamaskNetwork(network: object): Chainable; +addMetamaskNetwork( + network: + | string + | { + networkName: string; + rpcUrl: string; + chainId: number; + symbol?: string; + blockExplorer?: string; + isTestnet: boolean; + }, +): Chainable; ``` #### `cy.changeMetamaskNetwork()` -Change network in metamask. +Change network in metamask (if network is not present, it will be added). ```ts -changeMetamaskNetwork(network: string): Chainable; +changeMetamaskNetwork(network: string): Chainable; ``` #### `cy.importMetamaskAccount()` @@ -93,7 +104,7 @@ changeMetamaskNetwork(network: string): Chainable; Import new account in metamask using private key. ```ts -importMetamaskAccount(privateKey: string): Chainable; +importMetamaskAccount(privateKey: string): Chainable; ``` #### `cy.createMetamaskAccount()` @@ -101,7 +112,7 @@ importMetamaskAccount(privateKey: string): Chainable; Create new account in metamask. ```ts -createMetamaskAccount(accountName?: string): Chainable; +createMetamaskAccount(accountName?: string): Chainable; ``` #### `cy.renameMetamaskAccount()` @@ -109,7 +120,7 @@ createMetamaskAccount(accountName?: string): Chainable; Rename current account in metamask. ```ts -createMetamaskAccount(newAccountName: string): Chainable; +renameMetamaskAccount(newAccountName: string): Chainable; ``` #### `cy.switchMetamaskAccount()` @@ -119,7 +130,7 @@ Switch metamask account. ```ts switchMetamaskAccount( accountNameOrAccountNumber: string | number, -): Chainable; +): Chainable; ``` #### `cy.getMetamaskWalletAddress()` @@ -127,35 +138,38 @@ switchMetamaskAccount( Get current wallet address of metamask wallet. ```ts -getMetamaskWalletAddress(): Chainable; +getMetamaskWalletAddress(): Chainable; ``` #### `cy.activateAdvancedGasControlInMetamask()` -Activate ability (in metamask settings) to specify custom gas price and limit while doing transactions in metamask. +Activate ability (in metamask settings) to specify custom gas price and limit +while doing transactions in metamask. ```ts activateAdvancedGasControlInMetamask( skipSetup?: boolean, -): Chainable; +): Chainable; ``` #### `cy.activateShowHexDataInMetamask()` -Activate ability (in metamask settings) to show hex data while doing transaction in metamask. +Activate ability (in metamask settings) to show hex data while doing transaction +in metamask. ```ts -activateShowHexDataInMetamask(skipSetup?: boolean): Chainable; +activateShowHexDataInMetamask(skipSetup?: boolean): Chainable; ``` #### `cy.activateTestnetConversionInMetamask()` -Activate ability (in metamask settings) to show fiat conversions on testnets in metamask. +Activate ability (in metamask settings) to show fiat conversions on testnets in +metamask. ```ts activateTestnetConversionInMetamask( skipSetup?: boolean, -): Chainable; +): Chainable; ``` #### `cy.activateShowTestnetNetworksInMetamask()` @@ -165,25 +179,27 @@ Activate ability (in metamask settings) to show testnet networks in metamask. ```ts activateShowTestnetNetworksInMetamask( skipSetup?: boolean, -): Chainable; +): Chainable; ``` #### `cy.activateCustomNonceInMetamask()` -Activate ability (in metamask settings) to specify custom nonce while doing transactions in metamask. +Activate ability (in metamask settings) to specify custom nonce while doing +transactions in metamask. ```ts -activateCustomNonceInMetamask(skipSetup?: boolean): Chainable; +activateCustomNonceInMetamask(skipSetup?: boolean): Chainable; ``` #### `cy.activateDismissBackupReminderInMetamask()` -Activate ability (in metamask settings) to dismiss secret recovery phrase reminder in metamask. +Activate ability (in metamask settings) to dismiss secret recovery phrase +reminder in metamask. ```ts activateDismissBackupReminderInMetamask( skipSetup?: boolean, -): Chainable; +): Chainable; ``` #### `cy.activateEthSignRequestsInMetamask()` @@ -191,7 +207,7 @@ activateDismissBackupReminderInMetamask( Activate eth sign requests in metamask settings. ```ts -activateEthSignRequestsInMetamask(skipSetup?: boolean): Chainable; +activateEthSignRequestsInMetamask(skipSetup?: boolean): Chainable; ``` #### `cy.activateImprovedTokenAllowanceInMetamask()` @@ -201,7 +217,7 @@ Activate improved token allowance in metamask settings (experimental). ```ts activateImprovedTokenAllowanceInMetamask( skipSetup?: boolean, -): Chainable; +): Chainable; ``` #### `cy.resetMetamaskAccount()` @@ -209,7 +225,7 @@ activateImprovedTokenAllowanceInMetamask( Reset metamask account state in settings. ```ts -resetMetamaskAccount(): Chainable; +resetMetamaskAccount(): Chainable; ``` #### `cy.disconnectMetamaskWalletFromDapp()` @@ -217,7 +233,7 @@ resetMetamaskAccount(): Chainable; Disconnects metamask wallet from last connected dapp. ```ts -disconnectMetamaskWalletFromDapp(): Chainable; +disconnectMetamaskWalletFromDapp(): Chainable; ``` #### `cy.disconnectMetamaskWalletFromAllDapps()` @@ -225,7 +241,7 @@ disconnectMetamaskWalletFromDapp(): Chainable; Disconnects metamask wallet from all connected dapps. ```ts -disconnectMetamaskWalletFromAllDapps(): Chainable; +disconnectMetamaskWalletFromAllDapps(): Chainable; ``` #### `cy.confirmMetamaskSignatureRequest()` @@ -233,7 +249,7 @@ disconnectMetamaskWalletFromAllDapps(): Chainable; Confirm metamask permission to sign message. ```ts -confirmMetamaskSignatureRequest(): Chainable; +confirmMetamaskSignatureRequest(): Chainable; ``` #### `cy.confirmMetamaskDataSignatureRequest()` @@ -241,7 +257,7 @@ confirmMetamaskSignatureRequest(): Chainable; Confirm metamask permission to sign Data message. ```ts -confirmMetamaskDataSignatureRequest(): Chainable; +confirmMetamaskDataSignatureRequest(): Chainable; ``` #### `cy.rejectMetamaskSignatureRequest()` @@ -249,7 +265,7 @@ confirmMetamaskDataSignatureRequest(): Chainable; Reject metamask permission to sign message. ```ts -rejectMetamaskSignatureRequest(): Chainable; +rejectMetamaskSignatureRequest(): Chainable; ``` #### `cy.confirmMetamaskEncryptionPublicKeyRequest()` @@ -257,7 +273,7 @@ rejectMetamaskSignatureRequest(): Chainable; Confirm metamask request for public encryption key. ```ts -confirmMetamaskEncryptionPublicKeyRequest(): Chainable; +confirmMetamaskEncryptionPublicKeyRequest(): Chainable; ``` #### `cy.rejectMetamaskEncryptionPublicKeyRequest()` @@ -265,7 +281,7 @@ confirmMetamaskEncryptionPublicKeyRequest(): Chainable; Reject metamask request for public encryption key. ```ts -rejectMetamaskEncryptionPublicKeyRequest(): Chainable; +rejectMetamaskEncryptionPublicKeyRequest(): Chainable; ``` #### `cy.confirmMetamaskDecryptionRequest()` @@ -273,7 +289,7 @@ rejectMetamaskEncryptionPublicKeyRequest(): Chainable; Confirm metamask request to decrypt message with private key. ```ts -confirmMetamaskDecryptionRequest(): Chainable; +confirmMetamaskDecryptionRequest(): Chainable; ``` #### `cy.rejectMetamaskDecryptionRequest()` @@ -281,7 +297,7 @@ confirmMetamaskDecryptionRequest(): Chainable; Reject metamask request to decrypt message with private key. ```ts -rejectMetamaskDecryptionRequest(): Chainable; +rejectMetamaskDecryptionRequest(): Chainable; ``` #### `cy.rejectMetamaskDataSignatureRequest()` @@ -289,7 +305,7 @@ rejectMetamaskDecryptionRequest(): Chainable; Reject metamask permission to sign Data message. ```ts -rejectMetamaskDataSignatureRequest(): Chainable; +rejectMetamaskDataSignatureRequest(): Chainable; ``` #### `cy.importMetamaskToken()` @@ -297,7 +313,14 @@ rejectMetamaskDataSignatureRequest(): Chainable; Add custom token to metamask. ```ts -importMetamaskToken(tokenConfig?: object | string): Chainable; +importMetamaskToken( + tokenConfig?: + | { + address: string; + symbol: string; + } + | string, +): Chainable; ``` #### `cy.confirmMetamaskAddToken()` @@ -305,7 +328,7 @@ importMetamaskToken(tokenConfig?: object | string): Chainable; Confirm metamask request to add token. ```ts -confirmMetamaskAddToken(): Chainable; +confirmMetamaskAddToken(): Chainable; ``` #### `cy.rejectMetamaskAddToken()` @@ -313,7 +336,7 @@ confirmMetamaskAddToken(): Chainable; Reject metamask request to add token. ```ts -rejectMetamaskAddToken(): Chainable; +rejectMetamaskAddToken(): Chainable; ``` #### `cy.confirmMetamaskPermissionToSpend()` @@ -321,23 +344,41 @@ rejectMetamaskAddToken(): Chainable; Confirm metamask permission to spend asset. ```ts -confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable; +confirmMetamaskPermissionToSpend(spendLimit?: string): Chainable; ``` -#### `cy.confirmMetamaskPermisionToApproveAll()` +#### `cy.confirmMetamaskPermissionToApproveAll()` Confirm metamask permission to access all elements (example: collectibles). ```ts -confirmMetamaskPermisionToApproveAll(): Chainable; +confirmMetamaskPermissionToApproveAll(): Chainable; ``` -#### `cy.rejectMetamaskPermisionToApproveAll()` +#### `cy.rejectMetamaskPermissionToApproveAll()` Reject metamask permission to access all elements (example: collectibles). ```ts -rejectMetamaskPermisionToApproveAll(): Chainable; +rejectMetamaskPermissionToApproveAll(): Chainable; +``` + +#### `cy.confirmMetamaskRevokePermissionToAll()` + +Confirm metamask revoking permission to access all elements (example: +collectibles). + +```ts +confirmMetamaskRevokePermissionToAll(): Chainable; +``` + +#### `cy.rejectMetamaskRevokePermissionToAll()` + +Reject metamask revoking permission to access all elements (example: +collectibles). + +```ts +rejectMetamaskRevokePermissionToAll(): Chainable; ``` #### `cy.rejectMetamaskPermissionToSpend()` @@ -345,7 +386,7 @@ rejectMetamaskPermisionToApproveAll(): Chainable; Reject metamask permission to spend asset. ```ts -rejectMetamaskPermissionToSpend(): Chainable; +rejectMetamaskPermissionToSpend(): Chainable; ``` #### `cy.acceptMetamaskAccess()` @@ -357,7 +398,15 @@ acceptMetamaskAccess(options?: { allAccounts?: boolean; confirmSignatureRequest?: boolean; confirmDataSignatureRequest?: boolean; -}): Chainable; +}): Chainable; +``` + +#### `cy.rejectMetamaskAccess()` + +Reject metamask access request. + +```ts +rejectMetamaskAccess(): Chainable; ``` #### `cy.confirmMetamaskTransaction()` @@ -365,15 +414,46 @@ acceptMetamaskAccess(options?: { Confirm metamask transaction (auto-detects eip-1559 and legacy transactions). ```ts -confirmMetamaskTransaction(gasConfig?: object | string): Chainable; +confirmMetamaskTransaction( + gasConfig?: + | { + gasLimit?: number; + baseFee?: number; + priorityFee?: number; + } + | { + gasLimit?: number; + gasPrice?: number; + } + | 'low' + | 'market' + | 'aggressive' + | 'site', +): Chainable; ``` #### `cy.confirmMetamaskTransactionAndWaitForMining()` -Confirm metamask transaction (auto-detects eip-1559 and legacy transactions) and wait for ALL pending transactions to be mined. - -```ts -confirmMetamaskTransactionAndWaitForMining(gasConfig?: object | string): Chainable; +Confirm metamask transaction (auto-detects eip-1559 and legacy transactions) and +wait for ALL pending transactions to be mined. + +```ts +confirmMetamaskTransactionAndWaitForMining( + gasConfig?: + | { + gasLimit?: number; + baseFee?: number; + priorityFee?: number; + } + | { + gasLimit?: number; + gasPrice?: number; + } + | 'low' + | 'market' + | 'aggressive' + | 'site', +): Chainable; ``` #### `cy.rejectMetamaskTransaction()` @@ -381,12 +461,13 @@ confirmMetamaskTransactionAndWaitForMining(gasConfig?: object | string): Chainab Reject metamask transaction. ```ts -rejectMetamaskTransaction(): Chainable; +rejectMetamaskTransaction(): Chainable; ``` #### `cy.openMetamaskTransactionDetails()` -Open metamask transaction details based on the index of the transaction in the list on the activity tab. +Open metamask transaction details based on the index of the transaction in the +list on the activity tab. ```ts openMetamaskTransactionDetails(txIndex: number): Chainable; @@ -394,10 +475,10 @@ openMetamaskTransactionDetails(txIndex: number): Chainable; #### `cy.closeMetamaskTransactionDetailsPopup()` -Close currently open transaction details popup. +Close metamask transaction details popup. ```ts -closeMetamaskTransactionDetailsPopup(): Chainable; +closeMetamaskTransactionDetailsPopup(): Chainable; ``` #### `cy.allowMetamaskToAddNetwork()` @@ -405,7 +486,7 @@ closeMetamaskTransactionDetailsPopup(): Chainable; Allow site to add new network in metamask. ```ts -allowMetamaskToAddNetwork(waitForEvent?: string): Chainable; +allowMetamaskToAddNetwork(waitForEvent?: string): Chainable; ``` #### `cy.rejectMetamaskToAddNetwork()` @@ -413,7 +494,7 @@ allowMetamaskToAddNetwork(waitForEvent?: string): Chainable; Reject site to add new network in metamask. ```ts -rejectMetamaskToAddNetwork(): Chainable; +rejectMetamaskToAddNetwork(): Chainable; ``` #### `cy.allowMetamaskToSwitchNetwork()` @@ -421,7 +502,7 @@ rejectMetamaskToAddNetwork(): Chainable; Allow site to switch network in metamask. ```ts -allowMetamaskToSwitchNetwork(): Chainable; +allowMetamaskToSwitchNetwork(): Chainable; ``` #### `cy.rejectMetamaskToSwitchNetwork()` @@ -429,7 +510,7 @@ allowMetamaskToSwitchNetwork(): Chainable; Reject site to switch network in metamask. ```ts -rejectMetamaskToSwitchNetwork(): Chainable; +rejectMetamaskToSwitchNetwork(): Chainable; ``` #### `cy.allowMetamaskToAddAndSwitchNetwork()` @@ -437,7 +518,7 @@ rejectMetamaskToSwitchNetwork(): Chainable; Allow site to add new network in metamask and switch to it. ```ts -allowMetamaskToAddAndSwitchNetwork(): Chainable; +allowMetamaskToAddAndSwitchNetwork(): Chainable; ``` #### `cy.unlockMetamask()` @@ -445,7 +526,7 @@ allowMetamaskToAddAndSwitchNetwork(): Chainable; Unlock metamask. ```ts -unlockMetamask(password: string): Chainable; +unlockMetamask(password: string): Chainable; ``` #### `cy.fetchMetamaskWalletAddress()` @@ -453,7 +534,7 @@ unlockMetamask(password: string): Chainable; Fetches previous metamask wallet address. ```ts -fetchMetamaskWalletAddress(): Chainable; +fetchMetamaskWalletAddress(): Chainable; ``` #### `cy.setupMetamask()` @@ -463,7 +544,16 @@ Run the flow for metamask setup. ```ts setupMetamask( secretWordsOrPrivateKey?: string, - network?: string | object, + network?: + | string + | { + networkName: string; + rpcUrl: string; + chainId: number; + symbol?: string; + blockExplorer?: string; + isTestnet: boolean; + }, password?: string, enableAdvancedSettings?: boolean, enableExperimentalSettings?: boolean, @@ -483,7 +573,7 @@ etherscanGetTransactionStatus(txid: string): Chainable; Wait until transaction is success using Etherscan API. ```ts -etherscanWaitForTxSuccess(txid: string): Chainable; +etherscanWaitForTxSuccess(txid: string): Chainable; ``` #### `cy.waitForResources()` @@ -514,4 +604,3 @@ isWithinViewport( viewportHeight: number, ): Chainable; ``` - diff --git a/plugins/index.js b/plugins/index.js index 51fe4965b..c41090ed6 100644 --- a/plugins/index.js +++ b/plugins/index.js @@ -103,8 +103,11 @@ module.exports = (on, config) => { rejectMetamaskAddToken: metamask.rejectAddToken, confirmMetamaskPermissionToSpend: metamask.confirmPermissionToSpend, rejectMetamaskPermissionToSpend: metamask.rejectPermissionToSpend, - confirmMetamaskPermisionToApproveAll: metamask.confirmPermisionToApproveAll, - rejectMetamaskPermisionToApproveAll: metamask.rejectPermisionToApproveAll, + confirmMetamaskPermissionToApproveAll: + metamask.confirmPermissionToApproveAll, + rejectMetamaskPermissionToApproveAll: metamask.rejectPermissionToApproveAll, + confirmMetamaskRevokePermissionToAll: metamask.confirmRevokePermissionToAll, + rejectMetamaskRevokePermissionToAll: metamask.rejectRevokePermissionToAll, acceptMetamaskAccess: metamask.acceptAccess, rejectMetamaskAccess: metamask.rejectAccess, confirmMetamaskTransaction: metamask.confirmTransaction, diff --git a/support/commands.js b/support/commands.js index 73869e3fc..282ab8b3e 100644 --- a/support/commands.js +++ b/support/commands.js @@ -215,12 +215,20 @@ Cypress.Commands.add('closeMetamaskTransactionDetailsPopup', () => { return cy.task('closeMetamaskTransactionDetailsPopup'); }); -Cypress.Commands.add('rejectMetamaskPermisionToApproveAll', () => { - return cy.task('rejectMetamaskPermisionToApproveAll'); +Cypress.Commands.add('rejectMetamaskPermissionToApproveAll', () => { + return cy.task('rejectMetamaskPermissionToApproveAll'); }); -Cypress.Commands.add('confirmMetamaskPermisionToApproveAll', () => { - return cy.task('confirmMetamaskPermisionToApproveAll'); +Cypress.Commands.add('confirmMetamaskPermissionToApproveAll', () => { + return cy.task('confirmMetamaskPermissionToApproveAll'); +}); + +Cypress.Commands.add('confirmMetamaskRevokePermissionToAll', () => { + return cy.task('confirmMetamaskRevokePermissionToAll'); +}); + +Cypress.Commands.add('rejectMetamaskRevokePermissionToAll', () => { + return cy.task('rejectMetamaskRevokePermissionToAll'); }); Cypress.Commands.add('allowMetamaskToAddNetwork', waitForEvent => { diff --git a/support/index.d.ts b/support/index.d.ts index 804e32d54..fb5bbb3e1 100644 --- a/support/index.d.ts +++ b/support/index.d.ts @@ -278,15 +278,27 @@ declare namespace Cypress { /** * Confirm metamask permission to access all elements (example: collectibles) * @example - * cy.confirmMetamaskPermisionToApproveAll() + * cy.confirmMetamaskPermissionToApproveAll() */ - confirmMetamaskPermisionToApproveAll(): Chainable; + confirmMetamaskPermissionToApproveAll(): Chainable; /** * Reject metamask permission to access all elements (example: collectibles) * @example - * cy.rejectMetamaskPermisionToApproveAll() + * cy.rejectMetamaskPermissionToApproveAll() */ - rejectMetamaskPermisionToApproveAll(): Chainable; + rejectMetamaskPermissionToApproveAll(): Chainable; + /** + * Confirm metamask revoking permission to access all elements (example: collectibles) + * @example + * cy.confirmMetamaskRevokePermissionToAll() + */ + confirmMetamaskRevokePermissionToAll(): Chainable; + /** + * Reject metamask revoking permission to access all elements (example: collectibles) + * @example + * cy.rejectMetamaskRevokePermissionToAll() + */ + rejectMetamaskRevokePermissionToAll(): Chainable; /** * Reject metamask permission to spend asset * @example @@ -345,14 +357,14 @@ declare namespace Cypress { confirmMetamaskTransactionAndWaitForMining( gasConfig?: | { - gasLimit?: number; - baseFee?: number; - priorityFee?: number; - } + gasLimit?: number; + baseFee?: number; + priorityFee?: number; + } | { - gasLimit?: number; - gasPrice?: number; - } + gasLimit?: number; + gasPrice?: number; + } | 'low' | 'market' | 'aggressive' diff --git a/support/index.js b/support/index.js index db1b561b3..41b6fae42 100644 --- a/support/index.js +++ b/support/index.js @@ -24,8 +24,8 @@ Cypress.on('window:before:load', win => { }); }); -before(async () => { +before(() => { if (!Cypress.env('SKIP_METAMASK_SETUP')) { - await cy.setupMetamask(); + cy.setupMetamask(); } }); diff --git a/tests/e2e/specs/metamask-spec.js b/tests/e2e/specs/metamask-spec.js index 3b00ae2a2..4cbdcf635 100644 --- a/tests/e2e/specs/metamask-spec.js +++ b/tests/e2e/specs/metamask-spec.js @@ -128,19 +128,31 @@ describe('Metamask', () => { cy.changeMetamaskNetwork('sepolia'); } }); - it(`rejectMetamaskPermisionToApproveAll should reject permission to approve all NFTs upon warning`, () => { + it(`rejectMetamaskPermissionToApproveAll should reject permission to approve all NFTs upon warning`, () => { cy.get('#deployNFTsButton').click(); cy.confirmMetamaskTransaction(); cy.get('#mintButton').click(); cy.confirmMetamaskTransaction(); cy.get('#setApprovalForAllButton').click(); - cy.rejectMetamaskPermisionToApproveAll().then(rejected => { + cy.rejectMetamaskPermissionToApproveAll().then(rejected => { expect(rejected).to.be.true; }); }); - it(`confirmMetamaskPermisionToApproveAll should confirm permission to approve all NFTs`, () => { + it(`confirmMetamaskPermissionToApproveAll should confirm permission to approve all NFTs`, () => { cy.get('#setApprovalForAllButton').click(); - cy.confirmMetamaskPermisionToApproveAll().then(confirmed => { + cy.confirmMetamaskPermissionToApproveAll().then(confirmed => { + expect(confirmed).to.be.true; + }); + }); + it(`rejectMetamaskRevokePermissionToAll should reject revoking permission to all NFTs`, () => { + cy.get('#revokeButton').click(); + cy.rejectMetamaskRevokePermissionToAll().then(confirmed => { + expect(confirmed).to.be.true; + }); + }); + it(`confirmMetamaskRevokePermissionToAll should confirm revoking permission to all NFTs`, () => { + cy.get('#revokeButton').click(); + cy.confirmMetamaskRevokePermissionToAll().then(confirmed => { expect(confirmed).to.be.true; }); });