From 953c4254233db43a3165799e9b0a0f287f426fae Mon Sep 17 00:00:00 2001 From: matstyler Date: Tue, 25 Jun 2024 23:53:32 +0200 Subject: [PATCH] feat: MetaMask setup in Cypress part 1 --- .gitignore | 3 + pnpm-lock.yaml | 3 + wallets/metamask/cypress.config.ts | 15 + wallets/metamask/package.json | 8 +- wallets/metamask/src/cypress/MetaMask.ts | 9 + .../metamask/src/cypress/constants/errors.ts | 3 + wallets/metamask/src/cypress/index.ts | 1 + .../metamask/src/cypress/installSynpress.ts | 26 ++ wallets/metamask/src/cypress/support/e2e.ts | 26 ++ .../src/cypress/support/initMetaMask.ts | 64 +++++ .../src/cypress/support/synpressCommands.ts | 77 +++++ .../src/cypress/support/unlockForCypress.ts | 15 + .../prepareExtension.ts | 17 +- .../metamask/src/{ => playwright}/MetaMask.ts | 185 +------------ .../fixture-actions/getExtensionId.ts | 0 .../{ => playwright}/fixture-actions/index.ts | 0 .../fixture-actions/persistLocalStorage.ts | 0 .../fixture-actions/prepareExtension.ts | 0 .../fixture-actions/unlockForFixture.ts | 0 .../fixtures/metaMaskFixtures.ts | 5 +- .../metamask/src/{ => playwright}/index.ts | 0 .../{ => playwright}/pages/CrashPage/page.ts | 0 .../pages/CrashPage/selectors/index.ts | 0 .../pages/HomePage/actions/addNetwork.ts | 0 .../pages/HomePage/actions/addNewAccount.ts | 0 .../HomePage/actions/getAccountAddress.ts | 0 .../actions/importWalletFromPrivateKey.ts | 0 .../pages/HomePage/actions/index.ts | 0 .../pages/HomePage/actions/lock.ts | 0 .../popups/closeNetworkAddedPopover.ts | 0 .../popups/closeNewNetworkInfoPopover.ts | 0 .../HomePage/actions/popups/closePopover.ts | 0 .../popups/closeRecoveryPhraseReminder.ts | 0 .../pages/HomePage/actions/popups/index.ts | 0 .../pages/HomePage/actions/renameAccount.ts | 0 .../pages/HomePage/actions/settings.ts | 0 .../pages/HomePage/actions/switchAccount.ts | 0 .../pages/HomePage/actions/switchNetwork.ts | 0 .../actions/toggleShowTestNetworks.ts | 0 .../HomePage/actions/transactionDetails.ts | 0 .../{ => playwright}/pages/HomePage/page.ts | 0 .../pages/HomePage/selectors/index.ts | 0 .../pages/HomePage/selectors/settings.ts | 0 .../pages/LockPage/actions/index.ts | 0 .../pages/LockPage/actions/unlock.ts | 0 .../{ => playwright}/pages/LockPage/page.ts | 0 .../pages/LockPage/selectors/index.ts | 0 .../actions/approvePermission.ts | 0 .../NotificationPage/actions/connectToDapp.ts | 0 .../NotificationPage/actions/encryption.ts | 0 .../pages/NotificationPage/actions/index.ts | 0 .../pages/NotificationPage/actions/network.ts | 0 .../actions/signSimpleMessage.ts | 0 .../actions/signStructuredMessage.ts | 0 .../pages/NotificationPage/actions/token.ts | 0 .../NotificationPage/actions/transaction.ts | 0 .../pages/NotificationPage/page.ts | 0 .../selectors/actionFooter.ts | 0 .../NotificationPage/selectors/connectPage.ts | 0 .../pages/NotificationPage/selectors/index.ts | 0 .../NotificationPage/selectors/networkPage.ts | 0 .../selectors/permissionPage.ts | 0 .../selectors/signaturePage.ts | 0 .../selectors/transactionPage.ts | 0 .../helpers/confirmSecretRecoveryPhrase.ts | 0 .../actions/helpers/createPassword.ts | 0 .../OnboardingPage/actions/helpers/index.ts | 0 .../OnboardingPage/actions/importWallet.ts | 0 .../pages/OnboardingPage/actions/index.ts | 0 .../pages/OnboardingPage/page.ts | 0 .../OnboardingPage/selectors/analyticsPage.ts | 0 .../selectors/getStartedPage.ts | 0 .../pages/OnboardingPage/selectors/index.ts | 0 .../selectors/pinExtensionPage.ts | 0 .../selectors/secretRecoveryPhrasePage.ts | 0 .../selectors/walletCreationSuccessPage.ts | 0 .../SettingsPage/actions/disableEthSign.ts | 0 .../SettingsPage/actions/enableEthSign.ts | 0 .../pages/SettingsPage/actions/index.ts | 0 .../pages/SettingsPage/page.ts | 0 .../pages/SettingsPage/selectors/index.ts | 0 .../src/{ => playwright}/pages/index.ts | 0 .../src/{ => playwright}/selectors/index.ts | 0 .../selectors/loading/index.ts | 0 .../{ => playwright}/utils/allTextContents.ts | 0 .../utils/clickLocatorIfCondition.ts | 0 .../getNotificationPageAndWaitForLoad.ts | 0 .../utils/selectors/createDataTestSelector.ts | 0 .../src/{ => playwright}/utils/toggle.ts | 0 .../src/{ => playwright}/utils/waitFor.ts | 0 .../utils/waitForSpinnerToVanish.ts | 0 wallets/metamask/src/type/MetaMaskAbstract.ts | 262 ++++++++++++++++++ .../metamask/test/cypress/addNewAccount.cy.ts | 3 + .../test/{ => playwright}/e2e/PPOM.spec.ts | 0 .../{ => playwright}/e2e/addNetwork.spec.ts | 0 .../e2e/addNewAccount.spec.ts | 0 .../{ => playwright}/e2e/addNewToken.spec.ts | 0 .../e2e/approveNewNetwork.spec.ts | 0 .../e2e/approvePermission.spec.ts | 0 .../e2e/approveSwitchNetwork.spec.ts | 0 .../e2e/batchTransfer.spec.ts | 0 .../e2e/closeTransactionDetails.spec.ts | 0 .../e2e/confirmSignature.spec.ts | 0 .../e2e/confirmTransaction.spec.ts | 0 ...confirmTransactionAndWaitForMining.spec.ts | 0 .../e2e/connectToDapp.spec.ts | 0 .../test/{ => playwright}/e2e/encrypt.spec.ts | 0 .../e2e/goBackToHomePage.spec.ts | 0 .../{ => playwright}/e2e/importWallet.spec.ts | 0 .../e2e/importWalletFromPrivateKey.spec.ts | 0 .../test/{ => playwright}/e2e/lock.spec.ts | 0 .../{ => playwright}/e2e/openSettings.spec.ts | 0 .../e2e/openSidebarMenu.spec.ts | 0 .../e2e/openTransactionDetails.spec.ts | 0 .../e2e/rejectAddNetwork.spec.ts | 0 .../e2e/rejectPermission.spec.ts | 0 .../e2e/rejectSignature.spec.ts | 0 .../e2e/rejectSwitchNetwork.spec.ts | 0 .../e2e/rejectTransaction.spec.ts | 0 .../e2e/renameAccount.spec.ts | 0 .../{ => playwright}/e2e/resetAccount.spec.ts | 0 .../e2e/switchAccount.spec.ts | 0 .../e2e/switchNetwork.spec.ts | 0 ...ismissSecretRecoveryPhraseReminder.spec.ts | 0 .../e2e/toggleShowTestNetworks.spec.ts | 0 .../test/{ => playwright}/e2e/unlock.spec.ts | 0 .../test/{ => playwright}/synpress.ts | 2 +- .../wallet-setup/basic.setup.d.ts | 0 .../wallet-setup/basic.setup.d.ts.map | 0 .../wallet-setup/basic.setup.ts | 0 .../wallet-setup/connected.setup.ts | 0 wallets/metamask/tsconfig.json | 12 +- 132 files changed, 542 insertions(+), 194 deletions(-) create mode 100644 wallets/metamask/cypress.config.ts create mode 100644 wallets/metamask/src/cypress/MetaMask.ts create mode 100644 wallets/metamask/src/cypress/constants/errors.ts create mode 100644 wallets/metamask/src/cypress/index.ts create mode 100644 wallets/metamask/src/cypress/installSynpress.ts create mode 100644 wallets/metamask/src/cypress/support/e2e.ts create mode 100644 wallets/metamask/src/cypress/support/initMetaMask.ts create mode 100644 wallets/metamask/src/cypress/support/synpressCommands.ts create mode 100644 wallets/metamask/src/cypress/support/unlockForCypress.ts rename wallets/metamask/src/{fixture-actions => extensionSetup}/prepareExtension.ts (63%) rename wallets/metamask/src/{ => playwright}/MetaMask.ts (60%) rename wallets/metamask/src/{ => playwright}/fixture-actions/getExtensionId.ts (100%) rename wallets/metamask/src/{ => playwright}/fixture-actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/fixture-actions/persistLocalStorage.ts (100%) create mode 100644 wallets/metamask/src/playwright/fixture-actions/prepareExtension.ts rename wallets/metamask/src/{ => playwright}/fixture-actions/unlockForFixture.ts (100%) rename wallets/metamask/src/{ => playwright}/fixtures/metaMaskFixtures.ts (96%) rename wallets/metamask/src/{ => playwright}/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/CrashPage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/CrashPage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/addNetwork.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/addNewAccount.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/getAccountAddress.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/importWalletFromPrivateKey.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/lock.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/popups/closePopover.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/popups/closeRecoveryPhraseReminder.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/popups/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/renameAccount.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/settings.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/switchAccount.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/switchNetwork.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/toggleShowTestNetworks.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/actions/transactionDetails.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/HomePage/selectors/settings.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/LockPage/actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/LockPage/actions/unlock.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/LockPage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/LockPage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/approvePermission.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/connectToDapp.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/encryption.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/network.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/signSimpleMessage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/signStructuredMessage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/token.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/actions/transaction.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/actionFooter.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/connectPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/networkPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/permissionPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/signaturePage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/NotificationPage/selectors/transactionPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/actions/helpers/createPassword.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/actions/helpers/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/actions/importWallet.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/analyticsPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/getStartedPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/pinExtensionPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/secretRecoveryPhrasePage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/OnboardingPage/selectors/walletCreationSuccessPage.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/SettingsPage/actions/disableEthSign.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/SettingsPage/actions/enableEthSign.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/SettingsPage/actions/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/SettingsPage/page.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/SettingsPage/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/pages/index.ts (100%) rename wallets/metamask/src/{ => playwright}/selectors/index.ts (100%) rename wallets/metamask/src/{ => playwright}/selectors/loading/index.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/allTextContents.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/clickLocatorIfCondition.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/getNotificationPageAndWaitForLoad.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/selectors/createDataTestSelector.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/toggle.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/waitFor.ts (100%) rename wallets/metamask/src/{ => playwright}/utils/waitForSpinnerToVanish.ts (100%) create mode 100644 wallets/metamask/src/type/MetaMaskAbstract.ts create mode 100644 wallets/metamask/test/cypress/addNewAccount.cy.ts rename wallets/metamask/test/{ => playwright}/e2e/PPOM.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/addNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/addNewAccount.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/addNewToken.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/approveNewNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/approvePermission.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/approveSwitchNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/batchTransfer.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/closeTransactionDetails.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/confirmSignature.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/confirmTransaction.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/confirmTransactionAndWaitForMining.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/connectToDapp.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/encrypt.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/goBackToHomePage.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/importWallet.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/importWalletFromPrivateKey.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/lock.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/openSettings.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/openSidebarMenu.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/openTransactionDetails.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/rejectAddNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/rejectPermission.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/rejectSignature.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/rejectSwitchNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/rejectTransaction.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/renameAccount.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/resetAccount.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/switchAccount.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/switchNetwork.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/toggleDismissSecretRecoveryPhraseReminder.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/toggleShowTestNetworks.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/e2e/unlock.spec.ts (100%) rename wallets/metamask/test/{ => playwright}/synpress.ts (77%) rename wallets/metamask/test/{ => playwright}/wallet-setup/basic.setup.d.ts (100%) rename wallets/metamask/test/{ => playwright}/wallet-setup/basic.setup.d.ts.map (100%) rename wallets/metamask/test/{ => playwright}/wallet-setup/basic.setup.ts (100%) rename wallets/metamask/test/{ => playwright}/wallet-setup/connected.setup.ts (100%) diff --git a/.gitignore b/.gitignore index 94d16f61e..80f78bd9d 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,9 @@ test-results playwright-report playwright/.cache +### Cypress +cypress/downloads + ### Synpress .cache-synpress diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10d809f51..b2bdf6405 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -304,6 +304,9 @@ importers: '@vitest/coverage-v8': specifier: 1.2.2 version: 1.2.2(vitest@1.2.2) + cypress: + specifier: 13.9.0 + version: 13.9.0 rimraf: specifier: 5.0.5 version: 5.0.5 diff --git a/wallets/metamask/cypress.config.ts b/wallets/metamask/cypress.config.ts new file mode 100644 index 000000000..bee56d649 --- /dev/null +++ b/wallets/metamask/cypress.config.ts @@ -0,0 +1,15 @@ +import { defineConfig } from 'cypress' +import installSynpress from './src/cypress/installSynpress' + +export default defineConfig({ + chromeWebSecurity: false, + e2e: { + baseUrl: 'http://localhost:9999', + specPattern: 'test/cypress/**/*.cy.{js,jsx,ts,tsx}', + supportFile: 'src/cypress/support/e2e.{js,jsx,ts,tsx}', + testIsolation: false, + async setupNodeEvents(on, config) { + return installSynpress(on, config) + } + } +}) diff --git a/wallets/metamask/package.json b/wallets/metamask/package.json index d9b2eed90..4c64ce20c 100644 --- a/wallets/metamask/package.json +++ b/wallets/metamask/package.json @@ -15,15 +15,16 @@ ], "scripts": { "build": "pnpm run clean && pnpm run build:dist && pnpm run build:types", - "build:cache": "synpress-cache test/wallet-setup", - "build:cache:headless": "synpress-cache test/wallet-setup --headless", - "build:cache:headless:force": "synpress-cache test/wallet-setup --headless --force", + "build:cache": "synpress-cache test/playwright/wallet-setup", + "build:cache:headless": "synpress-cache test/playwright/wallet-setup --headless", + "build:cache:headless:force": "synpress-cache test/playwright/wallet-setup --headless --force", "build:dist": "tsup --tsconfig tsconfig.build.json", "build:types": "tsc --emitDeclarationOnly --project tsconfig.build.json", "clean": "rimraf dist types", "test": "vitest run", "test:coverage": "vitest run --coverage", "test:e2e:headful": "playwright test", + "test:e2e:headful:cypress": "cypress run --browser chrome --headed", "test:e2e:headless": "HEADLESS=true playwright test", "test:e2e:headless:ui": "HEADLESS=true playwright test --ui", "test:watch": "vitest watch", @@ -41,6 +42,7 @@ "@types/fs-extra": "11.0.4", "@types/node": "20.11.17", "@vitest/coverage-v8": "1.2.2", + "cypress": "13.9.0", "rimraf": "5.0.5", "tsup": "8.0.2", "typescript": "5.3.3", diff --git a/wallets/metamask/src/cypress/MetaMask.ts b/wallets/metamask/src/cypress/MetaMask.ts new file mode 100644 index 000000000..3ba2d6019 --- /dev/null +++ b/wallets/metamask/src/cypress/MetaMask.ts @@ -0,0 +1,9 @@ +import { MetaMaskAbstract } from '../type/MetaMaskAbstract' +import Selectors from '../playwright/pages/LockPage/selectors' + +export class MetaMask extends MetaMaskAbstract { + async unlock() { + cy.get(Selectors.passwordInput).type(this.password) + cy.get(Selectors.submitButton).click() + } +} diff --git a/wallets/metamask/src/cypress/constants/errors.ts b/wallets/metamask/src/cypress/constants/errors.ts new file mode 100644 index 000000000..fe094a48b --- /dev/null +++ b/wallets/metamask/src/cypress/constants/errors.ts @@ -0,0 +1,3 @@ +export const NO_CONTEXT = 'No browser context found. Connect Playwright first - connectPlaywright()' +export const NO_PAGE = 'No page found. Use getPage()' +export const MISSING_INIT = 'EthereumWalletMock not initialized. Use initEthereumWalletMock()' diff --git a/wallets/metamask/src/cypress/index.ts b/wallets/metamask/src/cypress/index.ts new file mode 100644 index 000000000..8289daa24 --- /dev/null +++ b/wallets/metamask/src/cypress/index.ts @@ -0,0 +1 @@ +export * from './MetaMask' diff --git a/wallets/metamask/src/cypress/installSynpress.ts b/wallets/metamask/src/cypress/installSynpress.ts new file mode 100644 index 000000000..c5903b315 --- /dev/null +++ b/wallets/metamask/src/cypress/installSynpress.ts @@ -0,0 +1,26 @@ +import { ensureRdpPort } from '@synthetixio/synpress-core' +import { initMetaMask } from './support/initMetaMask' + +let port: number + +export default function installSynpress(on: Cypress.PluginEvents, config: Cypress.PluginConfigOptions) { + const browsers = config.browsers.filter((b) => b.name === 'chrome') + if (browsers.length === 0) { + throw new Error('No Chrome browser found in the configuration') + } + + on('before:browser:launch', async (_, launchOptions) => { + // Enable debug mode to establish playwright connection + const args = Array.isArray(launchOptions) ? launchOptions : launchOptions.args + port = ensureRdpPort(args) + + args.push(...(await initMetaMask(port))) + + return launchOptions + }) + + return { + ...config, + browsers + } +} diff --git a/wallets/metamask/src/cypress/support/e2e.ts b/wallets/metamask/src/cypress/support/e2e.ts new file mode 100644 index 000000000..92dd7558c --- /dev/null +++ b/wallets/metamask/src/cypress/support/e2e.ts @@ -0,0 +1,26 @@ +// *********************************************************** +// This example support/e2e.ts is processed and +// loaded automatically before your test files. +// +// This is a great place to put global configuration and +// behavior that modifies Cypress. +// +// You can change the location of this file or turn off +// automatically serving support files with the +// 'supportFile' configuration option. +// +// You can read more here: +// https://on.cypress.io/configuration +// *********************************************************** + +// import mockEthereum from './mockEthereum' +// Import commands.js using ES2015 syntax: +// import synpressCommands from './synpressCommands' + +// synpressCommands() +// mockEthereum() +// +// Cypress.on('uncaught:exception', () => { +// // failing the test +// return false +// }) diff --git a/wallets/metamask/src/cypress/support/initMetaMask.ts b/wallets/metamask/src/cypress/support/initMetaMask.ts new file mode 100644 index 000000000..44b8f617c --- /dev/null +++ b/wallets/metamask/src/cypress/support/initMetaMask.ts @@ -0,0 +1,64 @@ +import { type BrowserContext, type Page, chromium } from '@playwright/test' + +import { NO_CONTEXT, NO_PAGE } from '../constants/errors' +// import { getExtensionId, unlockForFixture } from '../../playwright'; +import { prepareExtension } from '../../extensionSetup/prepareExtension'; +import { unlockForCypress } from './unlockForCypress'; +import basicSetup from '../../../test/playwright/wallet-setup/basic.setup'; + +let context: BrowserContext | undefined +let cypressPage: Page | undefined + +const getCypressPage = async () => { + if (!context) { + console.error(NO_CONTEXT) + return + } + + cypressPage = context.pages()[0] + + return cypressPage +} +export async function initMetaMask(port: number) { + // await connectPlaywrightToChrome(port) + + // if (!context) { + // console.error(NO_CONTEXT) + // return [] + // } + // + // await getCypressPage() + // + // if (!cypressPage) { + // console.error(NO_PAGE) + // return [] + // } + + const metamaskPath = await prepareExtension(false) + + const browserArgs = [ + `--disable-extensions-except=${metamaskPath}`, + `--load-extension=${metamaskPath}` + ] + + + if (process.env.HEADLESS) { + browserArgs.push('--headless=new') + } + + // await chromium.launchPersistentContext('', { + // headless: false, + // args: browserArgs + // }) + + // const extensionId = await getExtensionId(context, 'MetaMask') + // cypressPage = context.pages()[0] as Page + // + // await cypressPage.goto(`chrome-extension://${extensionId}/home.html`) + // + await unlockForCypress(basicSetup.walletPassword) + + return browserArgs + // + // await context.close() +} diff --git a/wallets/metamask/src/cypress/support/synpressCommands.ts b/wallets/metamask/src/cypress/support/synpressCommands.ts new file mode 100644 index 000000000..07e4de1aa --- /dev/null +++ b/wallets/metamask/src/cypress/support/synpressCommands.ts @@ -0,0 +1,77 @@ +/// +// *********************************************** +// This example commands.ts shows you how to +// create various custom commands and overwrite +// existing commands. +// +// For more comprehensive examples of custom +// commands please read more here: +// https://on.cypress.io/custom-commands +// *********************************************** + +// import type { Network } from '../../type/Network' +// import type { WalletMock } from '../../type/WalletMock' +declare global { + namespace Cypress { + interface Chainable { + + // importWallet(seedPhrase: string): Chainable + // importWalletFromPrivateKey(privateKey: `0x${string}`): Chainable + // addNewAccount(): Chainable + // getAllAccounts(): Chainable> + // getAccountAddress(): Chainable<`0x${string}`> + // switchAccount(accountAddress: string): Chainable + // addNetwork(network: Network): Chainable + // switchNetwork(networkName: string): Chainable + // connectToDapp(wallet?: WalletMock): Chainable + } + } +} + +export default function synpressCommands() { +// Cypress.Commands.add('importWallet', (seedPhrase) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.importWallet(seedPhrase) +// }) +// +// Cypress.Commands.add('importWalletFromPrivateKey', (privateKey) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.importWalletFromPrivateKey(privateKey) +// }) +// +// Cypress.Commands.add('addNewAccount', () => { +// const ethereumWalletMock = getEthereumWalletMock() +// return ethereumWalletMock.addNewAccount() +// }) +// +// Cypress.Commands.add('getAllAccounts', () => { +// const ethereumWalletMock = getEthereumWalletMock() +// +// return ethereumWalletMock.getAllAccounts() +// }) +// +// Cypress.Commands.add('getAccountAddress', () => { +// const ethereumWalletMock = getEthereumWalletMock() +// return ethereumWalletMock.getAccountAddress() +// }) +// +// Cypress.Commands.add('switchAccount', (accountAddress) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.switchAccount(accountAddress) +// }) +// +// Cypress.Commands.add('addNetwork', (network) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.addNetwork(network) +// }) +// +// Cypress.Commands.add('switchNetwork', (networkName) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.switchNetwork(networkName) +// }) +// +// Cypress.Commands.add('connectToDapp', (wallet) => { +// const ethereumWalletMock = getEthereumWalletMock() +// ethereumWalletMock.connectToDapp(wallet) +// }) +} diff --git a/wallets/metamask/src/cypress/support/unlockForCypress.ts b/wallets/metamask/src/cypress/support/unlockForCypress.ts new file mode 100644 index 000000000..30c278538 --- /dev/null +++ b/wallets/metamask/src/cypress/support/unlockForCypress.ts @@ -0,0 +1,15 @@ +import { MetaMask } from '../MetaMask' +// import { closePopover, closeRecoveryPhraseReminder } from '../../playwright/pages/HomePage/actions'; + +export async function unlockForCypress(password: string) { + const metamask = new MetaMask(password) + + await metamask.unlock() + + // await unlockWalletButReloadIfSpinnerDoesNotVanish(metamask) + // + // await retryIfMetaMaskCrashAfterUnlock(page) + // + // await closePopover(page) + // await closeRecoveryPhraseReminder(page) +} diff --git a/wallets/metamask/src/fixture-actions/prepareExtension.ts b/wallets/metamask/src/extensionSetup/prepareExtension.ts similarity index 63% rename from wallets/metamask/src/fixture-actions/prepareExtension.ts rename to wallets/metamask/src/extensionSetup/prepareExtension.ts index 649e346d0..5adbc9259 100644 --- a/wallets/metamask/src/fixture-actions/prepareExtension.ts +++ b/wallets/metamask/src/extensionSetup/prepareExtension.ts @@ -1,14 +1,25 @@ +import path from 'node:path' import { downloadFile, ensureCacheDirExists, unzipArchive } from '@synthetixio/synpress-cache' +import fs from 'fs-extra' export const DEFAULT_METAMASK_VERSION = '11.9.1' export const EXTENSION_DOWNLOAD_URL = `https://github.com/MetaMask/metamask-extension/releases/download/v${DEFAULT_METAMASK_VERSION}/metamask-chrome-${DEFAULT_METAMASK_VERSION}.zip` -export async function prepareExtension() { - const cacheDirPath = ensureCacheDirExists() +export async function prepareExtension(forceCache = true) { + let outputDir = '' + if (forceCache) { + outputDir = ensureCacheDirExists() + } else { + outputDir = path.resolve("./", 'downloads') + + if (!(await fs.exists(outputDir))) { + fs.mkdirSync(outputDir) + } + } const downloadResult = await downloadFile({ url: EXTENSION_DOWNLOAD_URL, - outputDir: cacheDirPath, + outputDir, fileName: `metamask-chrome-${DEFAULT_METAMASK_VERSION}.zip` }) diff --git a/wallets/metamask/src/MetaMask.ts b/wallets/metamask/src/playwright/MetaMask.ts similarity index 60% rename from wallets/metamask/src/MetaMask.ts rename to wallets/metamask/src/playwright/MetaMask.ts index 90abeaeeb..1f864051c 100644 --- a/wallets/metamask/src/MetaMask.ts +++ b/wallets/metamask/src/playwright/MetaMask.ts @@ -1,16 +1,14 @@ -import type { BrowserContext, Page } from '@playwright/test' -import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages' import type { Network } from './pages/HomePage/actions' import { SettingsSidebarMenus } from './pages/HomePage/selectors/settings' import type { GasSetting } from './pages/NotificationPage/actions' +import { MetaMaskAbstract } from '../type/MetaMaskAbstract' +import type { BrowserContext, Page } from '@playwright/test' +import { CrashPage, HomePage, LockPage, NotificationPage, OnboardingPage } from './pages' import { SettingsPage } from './pages/SettingsPage/page' const NO_EXTENSION_ID_ERROR = new Error('MetaMask extensionId is not set') -/** - * This class is the heart of Synpress's MetaMask API. - */ -export class MetaMask { +export class MetaMask extends MetaMaskAbstract { /** * This property can be used to access selectors for a given page. * @@ -43,16 +41,6 @@ export class MetaMask { readonly notificationPage: NotificationPage readonly settingsPage: SettingsPage - /** - * Class constructor. - * - * @param context - The browser context. - * @param page - The MetaMask tab page. - * @param password - The password of the MetaMask wallet. - * @param extensionId - The extension ID of the MetaMask extension. Optional if no interaction with the dapp is required. - * - * @returns A new instance of the MetaMask class. - */ constructor( /** * The browser context. @@ -65,12 +53,14 @@ export class MetaMask { /** * The password of the MetaMask wallet. */ - readonly password: string, + override readonly password: string, /** * The extension ID of the MetaMask extension. Optional if no interaction with the dapp is required. */ - readonly extensionId?: string + override readonly extensionId?: string ) { + super(password, extensionId) + this.crashPage = new CrashPage() this.onboardingPage = new OnboardingPage(page) @@ -80,20 +70,10 @@ export class MetaMask { this.settingsPage = new SettingsPage(page) } - /** - * Imports a wallet using the given seed phrase. - * - * @param seedPhrase - The seed phrase to import. - */ async importWallet(seedPhrase: string) { await this.onboardingPage.importWallet(seedPhrase, this.password) } - /** - * Adds a new account with the given name. This account is based on the initially imported seed phrase. - * - * @param accountName - The name of the new account. - */ async addNewAccount(accountName: string) { await this.homePage.addNewAccount(accountName) } @@ -112,53 +92,27 @@ export class MetaMask { * * @param privateKey - The private key to import. */ + async importWalletFromPrivateKey(privateKey: string) { await this.homePage.importWalletFromPrivateKey(privateKey) } - /** - * Switches to the account with the given name. - * - * @param accountName - The name of the account to switch to. - */ async switchAccount(accountName: string) { await this.homePage.switchAccount(accountName) } - /** - * Adds a new network. - * - * @param network - The network object to use for adding the new network. - * @param network.name - The name of the network. - * @param network.rpcUrl - The RPC URL of the network. - * @param network.chainId - The chain ID of the network. - * @param network.symbol - The currency symbol of the network. - * @param network.blockExplorerUrl - The block explorer URL of the network. - */ async addNetwork(network: Network) { await this.homePage.addNetwork(network) } - /** - * Retrieves the current account address. - */ async getAccountAddress() { return await this.homePage.getAccountAddress() } - /** - * Switches to the network with the given name. - * - * @param networkName - The name of the network to switch to. - * @param isTestnet - If switch to a test network. - */ async switchNetwork(networkName: string, isTestnet = false) { await this.homePage.switchNetwork(networkName, isTestnet) } - /** - * Connects to the dapp using the currently selected account. - */ async connectToDapp(accounts?: string[]) { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -167,23 +121,14 @@ export class MetaMask { await this.notificationPage.connectToDapp(this.extensionId, accounts) } - /** - * Locks MetaMask. - */ async lock() { await this.homePage.lock() } - /** - * Unlocks MetaMask. - */ async unlock() { await this.lockPage.unlock(this.password) } - /** - * Confirms a signature request. This function supports all types of commonly used signatures. - */ async confirmSignature() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -192,9 +137,6 @@ export class MetaMask { await this.notificationPage.signMessage(this.extensionId) } - /** - * Confirms a signature request with potential risk. - */ async confirmSignatureWithRisk() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -203,9 +145,6 @@ export class MetaMask { await this.notificationPage.signMessageWithRisk(this.extensionId) } - /** - * Rejects a signature request. This function supports all types of commonly used signatures. - */ async rejectSignature() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -214,9 +153,6 @@ export class MetaMask { await this.notificationPage.rejectMessage(this.extensionId) } - /** - * Approves a new network request. - */ async approveNewNetwork() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -225,9 +161,6 @@ export class MetaMask { await this.notificationPage.approveNewNetwork(this.extensionId) } - /** - * Rejects a new network request. - */ async rejectNewNetwork() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -236,9 +169,6 @@ export class MetaMask { await this.notificationPage.rejectNewNetwork(this.extensionId) } - /** - * Approves a switch network request. - */ async approveSwitchNetwork() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -247,9 +177,6 @@ export class MetaMask { await this.notificationPage.approveSwitchNetwork(this.extensionId) } - /** - * Rejects a switch network request. - */ async rejectSwitchNetwork() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -258,12 +185,6 @@ export class MetaMask { await this.notificationPage.rejectSwitchNetwork(this.extensionId) } - /** - * Confirms a transaction request. - * - * @param options - The transaction options. - * @param options.gasSetting - The gas setting to use for the transaction. - */ async confirmTransaction(options?: { gasSetting?: GasSetting }) { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -272,9 +193,6 @@ export class MetaMask { await this.notificationPage.confirmTransaction(this.extensionId, options) } - /** - * Rejects a transaction request. - */ async rejectTransaction() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -283,17 +201,6 @@ export class MetaMask { await this.notificationPage.rejectTransaction(this.extensionId) } - /** - * Approves a permission request to spend tokens. - * - * ::: warning - * For NFT approvals, use `confirmTransaction` method. - * ::: - * - * @param options - The permission options. - * @param options.spendLimit - The spend limit to use for the permission. - * @param options.gasSetting - The gas setting to use for the approval transaction. - */ async approveTokenPermission(options?: { spendLimit?: 'max' | number gasSetting?: GasSetting @@ -305,13 +212,6 @@ export class MetaMask { await this.notificationPage.approveTokenPermission(this.extensionId, options) } - /** - * Rejects a permission request to spend tokens. - * - * ::: warning - * For NFT approvals, use `confirmTransaction` method. - * ::: - */ async rejectTokenPermission() { if (!this.extensionId) { throw NO_EXTENSION_ID_ERROR @@ -320,74 +220,35 @@ export class MetaMask { await this.notificationPage.rejectTokenPermission(this.extensionId) } - /** - * Goes back to the home page of MetaMask tab. - */ async goBackToHomePage() { await this.homePage.goBackToHomePage() } - /** - * Opens the settings page. - */ async openSettings() { await this.homePage.openSettings() } - /** - * Opens a given menu in the sidebar. - * - * @param menu - The menu to open. - */ async openSidebarMenu(menu: SettingsSidebarMenus) { await this.homePage.openSidebarMenu(menu) } - /** - * Toggles the "Show Test Networks" setting. - * - * ::: warning - * This function requires the correct menu to be already opened. - * ::: - */ async toggleShowTestNetworks() { await this.homePage.toggleShowTestNetworks() } - /** - * Toggles the "Dismiss Secret Recovery Phrase Reminder" setting. - * - * ::: warning - * This function requires the correct menu to be already opened. - * ::: - */ async toggleDismissSecretRecoveryPhraseReminder() { await this.homePage.toggleDismissSecretRecoveryPhraseReminder() } - /** - * Resets the account. - * - * ::: warning - * This function requires the correct menu to be already opened. - * ::: - */ async resetAccount() { await this.homePage.resetAccount() } - /** - * Enables the eth_sign feature in MetaMask advanced settings. - * This method is marked as unsafe because enabling eth_sign can have security implications. - */ async unsafe_enableEthSign() { await this.homePage.openSettings() await this.settingsPage.enableEthSign() } - /** - * Disables the eth_sign feature in MetaMask advanced settings. - */ async disableEthSign() { await this.homePage.openSettings() await this.settingsPage.disableEthSign() @@ -417,20 +278,6 @@ export class MetaMask { await this.notificationPage.decryptMessage(this.extensionId) } - /// ------------------------------------------- - /// ---------- EXPERIMENTAL FEATURES ---------- - /// ------------------------------------------- - - /** - * Confirms a transaction request and waits for the transaction to be mined. - * This function utilizes the "Activity" tab of the MetaMask tab. - * - * @param options - The transaction options. - * @param options.gasSetting - The gas setting to use for the transaction. - * - * @experimental - * @group Experimental Methods - */ async confirmTransactionAndWaitForMining(options?: { gasSetting?: GasSetting }) { @@ -441,24 +288,10 @@ export class MetaMask { await this.notificationPage.confirmTransactionAndWaitForMining(this.extensionId, options) } - /** - * Opens the transaction details. - * - * @param txIndex - The index of the transaction in the "Activity" tab. Starts from `0`. - * - * @experimental - * @group Experimental Methods - */ async openTransactionDetails(txIndex: number) { await this.homePage.openTransactionDetails(txIndex) } - /** - * Closes the currently opened transaction details. - * - * @experimental - * @group Experimental Methods - */ async closeTransactionDetails() { await this.homePage.closeTransactionDetails() } diff --git a/wallets/metamask/src/fixture-actions/getExtensionId.ts b/wallets/metamask/src/playwright/fixture-actions/getExtensionId.ts similarity index 100% rename from wallets/metamask/src/fixture-actions/getExtensionId.ts rename to wallets/metamask/src/playwright/fixture-actions/getExtensionId.ts diff --git a/wallets/metamask/src/fixture-actions/index.ts b/wallets/metamask/src/playwright/fixture-actions/index.ts similarity index 100% rename from wallets/metamask/src/fixture-actions/index.ts rename to wallets/metamask/src/playwright/fixture-actions/index.ts diff --git a/wallets/metamask/src/fixture-actions/persistLocalStorage.ts b/wallets/metamask/src/playwright/fixture-actions/persistLocalStorage.ts similarity index 100% rename from wallets/metamask/src/fixture-actions/persistLocalStorage.ts rename to wallets/metamask/src/playwright/fixture-actions/persistLocalStorage.ts diff --git a/wallets/metamask/src/playwright/fixture-actions/prepareExtension.ts b/wallets/metamask/src/playwright/fixture-actions/prepareExtension.ts new file mode 100644 index 000000000..e69de29bb diff --git a/wallets/metamask/src/fixture-actions/unlockForFixture.ts b/wallets/metamask/src/playwright/fixture-actions/unlockForFixture.ts similarity index 100% rename from wallets/metamask/src/fixture-actions/unlockForFixture.ts rename to wallets/metamask/src/playwright/fixture-actions/unlockForFixture.ts diff --git a/wallets/metamask/src/fixtures/metaMaskFixtures.ts b/wallets/metamask/src/playwright/fixtures/metaMaskFixtures.ts similarity index 96% rename from wallets/metamask/src/fixtures/metaMaskFixtures.ts rename to wallets/metamask/src/playwright/fixtures/metaMaskFixtures.ts index 88b3cd55a..9d850d684 100644 --- a/wallets/metamask/src/fixtures/metaMaskFixtures.ts +++ b/wallets/metamask/src/playwright/fixtures/metaMaskFixtures.ts @@ -1,5 +1,3 @@ -import { MetaMask, getExtensionId, prepareExtension, unlockForFixture } from '../../src' - import path from 'node:path' import { type Page, chromium } from '@playwright/test' import { test as base } from '@playwright/test' @@ -13,6 +11,9 @@ import { type Anvil, type CreateAnvilOptions, createPool } from '@viem/anvil' import fs from 'fs-extra' import { persistLocalStorage } from '../fixture-actions/persistLocalStorage' import { waitForMetaMaskWindowToBeStable } from '../utils/waitFor' +import type { MetaMask } from '../MetaMask' +import { prepareExtension } from '../../extensionSetup/prepareExtension' +import { getExtensionId, unlockForFixture } from '../fixture-actions' type MetaMaskFixtures = { _contextPath: string diff --git a/wallets/metamask/src/index.ts b/wallets/metamask/src/playwright/index.ts similarity index 100% rename from wallets/metamask/src/index.ts rename to wallets/metamask/src/playwright/index.ts diff --git a/wallets/metamask/src/pages/CrashPage/page.ts b/wallets/metamask/src/playwright/pages/CrashPage/page.ts similarity index 100% rename from wallets/metamask/src/pages/CrashPage/page.ts rename to wallets/metamask/src/playwright/pages/CrashPage/page.ts diff --git a/wallets/metamask/src/pages/CrashPage/selectors/index.ts b/wallets/metamask/src/playwright/pages/CrashPage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/CrashPage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/CrashPage/selectors/index.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/addNetwork.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/addNetwork.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/addNetwork.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/addNetwork.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/addNewAccount.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/addNewAccount.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/addNewAccount.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/addNewAccount.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/getAccountAddress.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/getAccountAddress.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/getAccountAddress.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/importWalletFromPrivateKey.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/importWalletFromPrivateKey.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/importWalletFromPrivateKey.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/index.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/index.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/index.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/index.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/lock.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/lock.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/lock.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/lock.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeNetworkAddedPopover.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeNewNetworkInfoPopover.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/popups/closePopover.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/popups/closePopover.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/popups/closePopover.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/closeRecoveryPhraseReminder.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeRecoveryPhraseReminder.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/popups/closeRecoveryPhraseReminder.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/popups/closeRecoveryPhraseReminder.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/popups/index.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/popups/index.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/popups/index.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/popups/index.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/renameAccount.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/renameAccount.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/renameAccount.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/renameAccount.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/settings.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/settings.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/settings.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/settings.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/switchAccount.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/switchAccount.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/switchAccount.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/switchAccount.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/switchNetwork.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/switchNetwork.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/switchNetwork.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/switchNetwork.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/toggleShowTestNetworks.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/toggleShowTestNetworks.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/toggleShowTestNetworks.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/toggleShowTestNetworks.ts diff --git a/wallets/metamask/src/pages/HomePage/actions/transactionDetails.ts b/wallets/metamask/src/playwright/pages/HomePage/actions/transactionDetails.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/actions/transactionDetails.ts rename to wallets/metamask/src/playwright/pages/HomePage/actions/transactionDetails.ts diff --git a/wallets/metamask/src/pages/HomePage/page.ts b/wallets/metamask/src/playwright/pages/HomePage/page.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/page.ts rename to wallets/metamask/src/playwright/pages/HomePage/page.ts diff --git a/wallets/metamask/src/pages/HomePage/selectors/index.ts b/wallets/metamask/src/playwright/pages/HomePage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/HomePage/selectors/index.ts diff --git a/wallets/metamask/src/pages/HomePage/selectors/settings.ts b/wallets/metamask/src/playwright/pages/HomePage/selectors/settings.ts similarity index 100% rename from wallets/metamask/src/pages/HomePage/selectors/settings.ts rename to wallets/metamask/src/playwright/pages/HomePage/selectors/settings.ts diff --git a/wallets/metamask/src/pages/LockPage/actions/index.ts b/wallets/metamask/src/playwright/pages/LockPage/actions/index.ts similarity index 100% rename from wallets/metamask/src/pages/LockPage/actions/index.ts rename to wallets/metamask/src/playwright/pages/LockPage/actions/index.ts diff --git a/wallets/metamask/src/pages/LockPage/actions/unlock.ts b/wallets/metamask/src/playwright/pages/LockPage/actions/unlock.ts similarity index 100% rename from wallets/metamask/src/pages/LockPage/actions/unlock.ts rename to wallets/metamask/src/playwright/pages/LockPage/actions/unlock.ts diff --git a/wallets/metamask/src/pages/LockPage/page.ts b/wallets/metamask/src/playwright/pages/LockPage/page.ts similarity index 100% rename from wallets/metamask/src/pages/LockPage/page.ts rename to wallets/metamask/src/playwright/pages/LockPage/page.ts diff --git a/wallets/metamask/src/pages/LockPage/selectors/index.ts b/wallets/metamask/src/playwright/pages/LockPage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/LockPage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/LockPage/selectors/index.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/approvePermission.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/approvePermission.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/approvePermission.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/approvePermission.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/connectToDapp.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/connectToDapp.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/connectToDapp.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/encryption.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/encryption.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/encryption.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/encryption.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/index.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/index.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/index.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/network.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/network.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/network.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/network.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/signSimpleMessage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/signSimpleMessage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/signSimpleMessage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/signSimpleMessage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/signStructuredMessage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/signStructuredMessage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/signStructuredMessage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/signStructuredMessage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/token.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/token.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/token.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/token.ts diff --git a/wallets/metamask/src/pages/NotificationPage/actions/transaction.ts b/wallets/metamask/src/playwright/pages/NotificationPage/actions/transaction.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/actions/transaction.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/actions/transaction.ts diff --git a/wallets/metamask/src/pages/NotificationPage/page.ts b/wallets/metamask/src/playwright/pages/NotificationPage/page.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/page.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/page.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/actionFooter.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/actionFooter.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/actionFooter.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/actionFooter.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/connectPage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/connectPage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/connectPage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/connectPage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/index.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/index.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/networkPage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/networkPage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/networkPage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/networkPage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/permissionPage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/permissionPage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/permissionPage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/permissionPage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/signaturePage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/signaturePage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/signaturePage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/signaturePage.ts diff --git a/wallets/metamask/src/pages/NotificationPage/selectors/transactionPage.ts b/wallets/metamask/src/playwright/pages/NotificationPage/selectors/transactionPage.ts similarity index 100% rename from wallets/metamask/src/pages/NotificationPage/selectors/transactionPage.ts rename to wallets/metamask/src/playwright/pages/NotificationPage/selectors/transactionPage.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/confirmSecretRecoveryPhrase.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/createPassword.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/actions/helpers/createPassword.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/createPassword.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/helpers/index.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/index.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/actions/helpers/index.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/actions/helpers/index.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/actions/importWallet.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/actions/importWallet.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/actions/importWallet.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/actions/index.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/actions/index.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/actions/index.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/actions/index.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/page.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/page.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/page.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/page.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/analyticsPage.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/analyticsPage.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/analyticsPage.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/analyticsPage.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/getStartedPage.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/getStartedPage.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/getStartedPage.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/getStartedPage.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/index.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/index.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/pinExtensionPage.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/pinExtensionPage.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/pinExtensionPage.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/pinExtensionPage.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/secretRecoveryPhrasePage.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/secretRecoveryPhrasePage.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/secretRecoveryPhrasePage.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/secretRecoveryPhrasePage.ts diff --git a/wallets/metamask/src/pages/OnboardingPage/selectors/walletCreationSuccessPage.ts b/wallets/metamask/src/playwright/pages/OnboardingPage/selectors/walletCreationSuccessPage.ts similarity index 100% rename from wallets/metamask/src/pages/OnboardingPage/selectors/walletCreationSuccessPage.ts rename to wallets/metamask/src/playwright/pages/OnboardingPage/selectors/walletCreationSuccessPage.ts diff --git a/wallets/metamask/src/pages/SettingsPage/actions/disableEthSign.ts b/wallets/metamask/src/playwright/pages/SettingsPage/actions/disableEthSign.ts similarity index 100% rename from wallets/metamask/src/pages/SettingsPage/actions/disableEthSign.ts rename to wallets/metamask/src/playwright/pages/SettingsPage/actions/disableEthSign.ts diff --git a/wallets/metamask/src/pages/SettingsPage/actions/enableEthSign.ts b/wallets/metamask/src/playwright/pages/SettingsPage/actions/enableEthSign.ts similarity index 100% rename from wallets/metamask/src/pages/SettingsPage/actions/enableEthSign.ts rename to wallets/metamask/src/playwright/pages/SettingsPage/actions/enableEthSign.ts diff --git a/wallets/metamask/src/pages/SettingsPage/actions/index.ts b/wallets/metamask/src/playwright/pages/SettingsPage/actions/index.ts similarity index 100% rename from wallets/metamask/src/pages/SettingsPage/actions/index.ts rename to wallets/metamask/src/playwright/pages/SettingsPage/actions/index.ts diff --git a/wallets/metamask/src/pages/SettingsPage/page.ts b/wallets/metamask/src/playwright/pages/SettingsPage/page.ts similarity index 100% rename from wallets/metamask/src/pages/SettingsPage/page.ts rename to wallets/metamask/src/playwright/pages/SettingsPage/page.ts diff --git a/wallets/metamask/src/pages/SettingsPage/selectors/index.ts b/wallets/metamask/src/playwright/pages/SettingsPage/selectors/index.ts similarity index 100% rename from wallets/metamask/src/pages/SettingsPage/selectors/index.ts rename to wallets/metamask/src/playwright/pages/SettingsPage/selectors/index.ts diff --git a/wallets/metamask/src/pages/index.ts b/wallets/metamask/src/playwright/pages/index.ts similarity index 100% rename from wallets/metamask/src/pages/index.ts rename to wallets/metamask/src/playwright/pages/index.ts diff --git a/wallets/metamask/src/selectors/index.ts b/wallets/metamask/src/playwright/selectors/index.ts similarity index 100% rename from wallets/metamask/src/selectors/index.ts rename to wallets/metamask/src/playwright/selectors/index.ts diff --git a/wallets/metamask/src/selectors/loading/index.ts b/wallets/metamask/src/playwright/selectors/loading/index.ts similarity index 100% rename from wallets/metamask/src/selectors/loading/index.ts rename to wallets/metamask/src/playwright/selectors/loading/index.ts diff --git a/wallets/metamask/src/utils/allTextContents.ts b/wallets/metamask/src/playwright/utils/allTextContents.ts similarity index 100% rename from wallets/metamask/src/utils/allTextContents.ts rename to wallets/metamask/src/playwright/utils/allTextContents.ts diff --git a/wallets/metamask/src/utils/clickLocatorIfCondition.ts b/wallets/metamask/src/playwright/utils/clickLocatorIfCondition.ts similarity index 100% rename from wallets/metamask/src/utils/clickLocatorIfCondition.ts rename to wallets/metamask/src/playwright/utils/clickLocatorIfCondition.ts diff --git a/wallets/metamask/src/utils/getNotificationPageAndWaitForLoad.ts b/wallets/metamask/src/playwright/utils/getNotificationPageAndWaitForLoad.ts similarity index 100% rename from wallets/metamask/src/utils/getNotificationPageAndWaitForLoad.ts rename to wallets/metamask/src/playwright/utils/getNotificationPageAndWaitForLoad.ts diff --git a/wallets/metamask/src/utils/selectors/createDataTestSelector.ts b/wallets/metamask/src/playwright/utils/selectors/createDataTestSelector.ts similarity index 100% rename from wallets/metamask/src/utils/selectors/createDataTestSelector.ts rename to wallets/metamask/src/playwright/utils/selectors/createDataTestSelector.ts diff --git a/wallets/metamask/src/utils/toggle.ts b/wallets/metamask/src/playwright/utils/toggle.ts similarity index 100% rename from wallets/metamask/src/utils/toggle.ts rename to wallets/metamask/src/playwright/utils/toggle.ts diff --git a/wallets/metamask/src/utils/waitFor.ts b/wallets/metamask/src/playwright/utils/waitFor.ts similarity index 100% rename from wallets/metamask/src/utils/waitFor.ts rename to wallets/metamask/src/playwright/utils/waitFor.ts diff --git a/wallets/metamask/src/utils/waitForSpinnerToVanish.ts b/wallets/metamask/src/playwright/utils/waitForSpinnerToVanish.ts similarity index 100% rename from wallets/metamask/src/utils/waitForSpinnerToVanish.ts rename to wallets/metamask/src/playwright/utils/waitForSpinnerToVanish.ts diff --git a/wallets/metamask/src/type/MetaMaskAbstract.ts b/wallets/metamask/src/type/MetaMaskAbstract.ts new file mode 100644 index 000000000..6ea2414c5 --- /dev/null +++ b/wallets/metamask/src/type/MetaMaskAbstract.ts @@ -0,0 +1,262 @@ +import type { Network } from '../playwright/pages/HomePage/actions' +import { SettingsSidebarMenus } from '../playwright/pages/HomePage/selectors/settings' +import type { GasSetting } from '../playwright/pages/NotificationPage/actions' + +export abstract class MetaMaskAbstract { + /** + * @param password - The password of the MetaMask wallet. + * @param extensionId - The extension ID of the MetaMask extension. Optional if no interaction with the dapp is required. + * + * @returns A new instance of the MetaMask class. + */ + constructor( + /** + * The password of the MetaMask wallet. + */ + readonly password: string, + /** + * The extension ID of the MetaMask extension. Optional if no interaction with the dapp is required. + */ + readonly extensionId?: string + ) { + this.password = password + this.extensionId = extensionId + } + + /** + * Imports a wallet using the given seed phrase. + * + * @param seedPhrase - The seed phrase to import. + */ + abstract importWallet(seedPhrase: string): void + + /** + * Adds a new account with the given name. This account is based on the initially imported seed phrase. + * + * @param accountName - The name of the new account. + */ + abstract addNewAccount(accountName: string): void + + /** + * Imports a wallet using the given private key. + * + * @param privateKey - The private key to import. + */ + abstract importWalletFromPrivateKey(privateKey: string): void + + /** + * Switches to the account with the given name. + * + * @param accountName - The name of the account to switch to. + */ + abstract switchAccount(accountName: string): void + + /** + * Adds a new network. + * + * @param network - The network object to use for adding the new network. + * @param network.name - The name of the network. + * @param network.rpcUrl - The RPC URL of the network. + * @param network.chainId - The chain ID of the network. + * @param network.symbol - The currency symbol of the network. + * @param network.blockExplorerUrl - The block explorer URL of the network. + */ + abstract addNetwork(network: Network): void + + /** + * Retrieves the current account address. + */ + abstract getAccountAddress(): void + + /** + * Switches to the network with the given name. + * + * @param networkName - The name of the network to switch to. + * @param isTestnet - If switch to a test network. + */ + abstract switchNetwork(networkName: string, isTestnet: boolean): void + + /** + * Connects to the dapp using the currently selected account. + */ + abstract connectToDapp(accounts?: string[]): void + + /** + * Locks MetaMask. + */ + abstract lock(): void + + /** + * Unlocks MetaMask. + */ + abstract unlock(): void + + /** + * Confirms a signature request. This function supports all types of commonly used signatures. + */ + abstract confirmSignature(): void + + /** + * Confirms a signature request with potential risk. + */ + abstract confirmSignatureWithRisk(): void + + /** + * Rejects a signature request. This function supports all types of commonly used signatures. + */ + abstract rejectSignature(): void + + /** + * Approves a new network request. + */ + abstract approveNewNetwork(): void + + /** + * Rejects a new network request. + */ + abstract rejectNewNetwork(): void + + /** + * Approves a switch network request. + */ + abstract approveSwitchNetwork(): void + + /** + * Rejects a switch network request. + */ + abstract rejectSwitchNetwork(): void + + /** + * Confirms a transaction request. + * + * @param options - The transaction options. + * @param options.gasSetting - The gas setting to use for the transaction. + */ + abstract confirmTransaction(options?: { gasSetting?: GasSetting }): void + + /** + * Rejects a transaction request. + */ + abstract rejectTransaction(): void + + /** + * Approves a permission request to spend tokens. + * + * ::: warning + * For NFT approvals, use `confirmTransaction` method. + * ::: + * + * @param options - The permission options. + * @param options.spendLimit - The spend limit to use for the permission. + * @param options.gasSetting - The gas setting to use for the approval transaction. + */ + abstract approveTokenPermission(options?: { + spendLimit?: 'max' | number + gasSetting?: GasSetting + }): void + + /** + * Rejects a permission request to spend tokens. + * + * ::: warning + * For NFT approvals, use `confirmTransaction` method. + * ::: + */ + abstract rejectTokenPermission(): void + + /** + * Goes back to the home page of MetaMask tab. + */ + abstract goBackToHomePage(): void + + /** + * Opens the settings page. + */ + abstract openSettings(): void + + /** + * Opens a given menu in the sidebar. + * + * @param menu - The menu to open. + */ + abstract openSidebarMenu(menu: SettingsSidebarMenus): void + /** + * Toggles the "Show Test Networks" setting. + * + * ::: warning + * This function requires the correct menu to be already opened. + * ::: + */ + abstract toggleShowTestNetworks(): void + + /** + * Toggles the "Dismiss Secret Recovery Phrase Reminder" setting. + * + * ::: warning + * This function requires the correct menu to be already opened. + * ::: + */ + abstract toggleDismissSecretRecoveryPhraseReminder(): void + + /** + * Resets the account. + * + * ::: warning + * This function requires the correct menu to be already opened. + * ::: + */ + abstract resetAccount(): void + + /** + * Enables the eth_sign feature in MetaMask advanced settings. + * This method is marked as unsafe because enabling eth_sign can have security implications. + */ + abstract unsafe_enableEthSign(): void + + /** + * Disables the eth_sign feature in MetaMask advanced settings. + */ + abstract disableEthSign(): void + + abstract addNewToken(): void + + abstract providePublicEncryptionKey(): void + + abstract decrypt(): void + + /// ------------------------------------------- + /// ---------- EXPERIMENTAL FEATURES ---------- + /// ------------------------------------------- + + /** + * Confirms a transaction request and waits for the transaction to be mined. + * This function utilizes the "Activity" tab of the MetaMask tab. + * + * @param options - The transaction options. + * @param options.gasSetting - The gas setting to use for the transaction. + * + * @experimental + * @group Experimental Methods + */ + abstract confirmTransactionAndWaitForMining(options?: { + gasSetting?: GasSetting + }): void + + /** + * Opens the transaction details. + * + * @param txIndex - The index of the transaction in the "Activity" tab. Starts from `0`. + * + * @experimental + * @group Experimental Methods + */ + abstract openTransactionDetails(txIndex: number): void + + /** + * Closes the currently opened transaction details. + * + * @experimental + * @group Experimental Methods + */ + abstract closeTransactionDetails(): void +} diff --git a/wallets/metamask/test/cypress/addNewAccount.cy.ts b/wallets/metamask/test/cypress/addNewAccount.cy.ts new file mode 100644 index 000000000..711b10a87 --- /dev/null +++ b/wallets/metamask/test/cypress/addNewAccount.cy.ts @@ -0,0 +1,3 @@ +it('should add a new accounts', () => { + cy.wait(1000000000) +}) diff --git a/wallets/metamask/test/e2e/PPOM.spec.ts b/wallets/metamask/test/playwright/e2e/PPOM.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/PPOM.spec.ts rename to wallets/metamask/test/playwright/e2e/PPOM.spec.ts diff --git a/wallets/metamask/test/e2e/addNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/addNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/addNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/addNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/addNewAccount.spec.ts b/wallets/metamask/test/playwright/e2e/addNewAccount.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/addNewAccount.spec.ts rename to wallets/metamask/test/playwright/e2e/addNewAccount.spec.ts diff --git a/wallets/metamask/test/e2e/addNewToken.spec.ts b/wallets/metamask/test/playwright/e2e/addNewToken.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/addNewToken.spec.ts rename to wallets/metamask/test/playwright/e2e/addNewToken.spec.ts diff --git a/wallets/metamask/test/e2e/approveNewNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/approveNewNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/approveNewNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/approveNewNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/approvePermission.spec.ts b/wallets/metamask/test/playwright/e2e/approvePermission.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/approvePermission.spec.ts rename to wallets/metamask/test/playwright/e2e/approvePermission.spec.ts diff --git a/wallets/metamask/test/e2e/approveSwitchNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/approveSwitchNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/approveSwitchNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/approveSwitchNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/batchTransfer.spec.ts b/wallets/metamask/test/playwright/e2e/batchTransfer.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/batchTransfer.spec.ts rename to wallets/metamask/test/playwright/e2e/batchTransfer.spec.ts diff --git a/wallets/metamask/test/e2e/closeTransactionDetails.spec.ts b/wallets/metamask/test/playwright/e2e/closeTransactionDetails.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/closeTransactionDetails.spec.ts rename to wallets/metamask/test/playwright/e2e/closeTransactionDetails.spec.ts diff --git a/wallets/metamask/test/e2e/confirmSignature.spec.ts b/wallets/metamask/test/playwright/e2e/confirmSignature.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/confirmSignature.spec.ts rename to wallets/metamask/test/playwright/e2e/confirmSignature.spec.ts diff --git a/wallets/metamask/test/e2e/confirmTransaction.spec.ts b/wallets/metamask/test/playwright/e2e/confirmTransaction.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/confirmTransaction.spec.ts rename to wallets/metamask/test/playwright/e2e/confirmTransaction.spec.ts diff --git a/wallets/metamask/test/e2e/confirmTransactionAndWaitForMining.spec.ts b/wallets/metamask/test/playwright/e2e/confirmTransactionAndWaitForMining.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/confirmTransactionAndWaitForMining.spec.ts rename to wallets/metamask/test/playwright/e2e/confirmTransactionAndWaitForMining.spec.ts diff --git a/wallets/metamask/test/e2e/connectToDapp.spec.ts b/wallets/metamask/test/playwright/e2e/connectToDapp.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/connectToDapp.spec.ts rename to wallets/metamask/test/playwright/e2e/connectToDapp.spec.ts diff --git a/wallets/metamask/test/e2e/encrypt.spec.ts b/wallets/metamask/test/playwright/e2e/encrypt.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/encrypt.spec.ts rename to wallets/metamask/test/playwright/e2e/encrypt.spec.ts diff --git a/wallets/metamask/test/e2e/goBackToHomePage.spec.ts b/wallets/metamask/test/playwright/e2e/goBackToHomePage.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/goBackToHomePage.spec.ts rename to wallets/metamask/test/playwright/e2e/goBackToHomePage.spec.ts diff --git a/wallets/metamask/test/e2e/importWallet.spec.ts b/wallets/metamask/test/playwright/e2e/importWallet.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/importWallet.spec.ts rename to wallets/metamask/test/playwright/e2e/importWallet.spec.ts diff --git a/wallets/metamask/test/e2e/importWalletFromPrivateKey.spec.ts b/wallets/metamask/test/playwright/e2e/importWalletFromPrivateKey.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/importWalletFromPrivateKey.spec.ts rename to wallets/metamask/test/playwright/e2e/importWalletFromPrivateKey.spec.ts diff --git a/wallets/metamask/test/e2e/lock.spec.ts b/wallets/metamask/test/playwright/e2e/lock.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/lock.spec.ts rename to wallets/metamask/test/playwright/e2e/lock.spec.ts diff --git a/wallets/metamask/test/e2e/openSettings.spec.ts b/wallets/metamask/test/playwright/e2e/openSettings.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/openSettings.spec.ts rename to wallets/metamask/test/playwright/e2e/openSettings.spec.ts diff --git a/wallets/metamask/test/e2e/openSidebarMenu.spec.ts b/wallets/metamask/test/playwright/e2e/openSidebarMenu.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/openSidebarMenu.spec.ts rename to wallets/metamask/test/playwright/e2e/openSidebarMenu.spec.ts diff --git a/wallets/metamask/test/e2e/openTransactionDetails.spec.ts b/wallets/metamask/test/playwright/e2e/openTransactionDetails.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/openTransactionDetails.spec.ts rename to wallets/metamask/test/playwright/e2e/openTransactionDetails.spec.ts diff --git a/wallets/metamask/test/e2e/rejectAddNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/rejectAddNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/rejectAddNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/rejectAddNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/rejectPermission.spec.ts b/wallets/metamask/test/playwright/e2e/rejectPermission.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/rejectPermission.spec.ts rename to wallets/metamask/test/playwright/e2e/rejectPermission.spec.ts diff --git a/wallets/metamask/test/e2e/rejectSignature.spec.ts b/wallets/metamask/test/playwright/e2e/rejectSignature.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/rejectSignature.spec.ts rename to wallets/metamask/test/playwright/e2e/rejectSignature.spec.ts diff --git a/wallets/metamask/test/e2e/rejectSwitchNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/rejectSwitchNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/rejectSwitchNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/rejectSwitchNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/rejectTransaction.spec.ts b/wallets/metamask/test/playwright/e2e/rejectTransaction.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/rejectTransaction.spec.ts rename to wallets/metamask/test/playwright/e2e/rejectTransaction.spec.ts diff --git a/wallets/metamask/test/e2e/renameAccount.spec.ts b/wallets/metamask/test/playwright/e2e/renameAccount.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/renameAccount.spec.ts rename to wallets/metamask/test/playwright/e2e/renameAccount.spec.ts diff --git a/wallets/metamask/test/e2e/resetAccount.spec.ts b/wallets/metamask/test/playwright/e2e/resetAccount.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/resetAccount.spec.ts rename to wallets/metamask/test/playwright/e2e/resetAccount.spec.ts diff --git a/wallets/metamask/test/e2e/switchAccount.spec.ts b/wallets/metamask/test/playwright/e2e/switchAccount.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/switchAccount.spec.ts rename to wallets/metamask/test/playwright/e2e/switchAccount.spec.ts diff --git a/wallets/metamask/test/e2e/switchNetwork.spec.ts b/wallets/metamask/test/playwright/e2e/switchNetwork.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/switchNetwork.spec.ts rename to wallets/metamask/test/playwright/e2e/switchNetwork.spec.ts diff --git a/wallets/metamask/test/e2e/toggleDismissSecretRecoveryPhraseReminder.spec.ts b/wallets/metamask/test/playwright/e2e/toggleDismissSecretRecoveryPhraseReminder.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/toggleDismissSecretRecoveryPhraseReminder.spec.ts rename to wallets/metamask/test/playwright/e2e/toggleDismissSecretRecoveryPhraseReminder.spec.ts diff --git a/wallets/metamask/test/e2e/toggleShowTestNetworks.spec.ts b/wallets/metamask/test/playwright/e2e/toggleShowTestNetworks.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/toggleShowTestNetworks.spec.ts rename to wallets/metamask/test/playwright/e2e/toggleShowTestNetworks.spec.ts diff --git a/wallets/metamask/test/e2e/unlock.spec.ts b/wallets/metamask/test/playwright/e2e/unlock.spec.ts similarity index 100% rename from wallets/metamask/test/e2e/unlock.spec.ts rename to wallets/metamask/test/playwright/e2e/unlock.spec.ts diff --git a/wallets/metamask/test/synpress.ts b/wallets/metamask/test/playwright/synpress.ts similarity index 77% rename from wallets/metamask/test/synpress.ts rename to wallets/metamask/test/playwright/synpress.ts index bf6f76793..c7e12ca98 100644 --- a/wallets/metamask/test/synpress.ts +++ b/wallets/metamask/test/playwright/synpress.ts @@ -1,5 +1,5 @@ import { testWithSynpress } from '@synthetixio/synpress-core' -import { metaMaskFixtures } from '../src' import connectedSetup from './wallet-setup/connected.setup' +import { metaMaskFixtures } from '../../src/playwright' export default testWithSynpress(metaMaskFixtures(connectedSetup)) diff --git a/wallets/metamask/test/wallet-setup/basic.setup.d.ts b/wallets/metamask/test/playwright/wallet-setup/basic.setup.d.ts similarity index 100% rename from wallets/metamask/test/wallet-setup/basic.setup.d.ts rename to wallets/metamask/test/playwright/wallet-setup/basic.setup.d.ts diff --git a/wallets/metamask/test/wallet-setup/basic.setup.d.ts.map b/wallets/metamask/test/playwright/wallet-setup/basic.setup.d.ts.map similarity index 100% rename from wallets/metamask/test/wallet-setup/basic.setup.d.ts.map rename to wallets/metamask/test/playwright/wallet-setup/basic.setup.d.ts.map diff --git a/wallets/metamask/test/wallet-setup/basic.setup.ts b/wallets/metamask/test/playwright/wallet-setup/basic.setup.ts similarity index 100% rename from wallets/metamask/test/wallet-setup/basic.setup.ts rename to wallets/metamask/test/playwright/wallet-setup/basic.setup.ts diff --git a/wallets/metamask/test/wallet-setup/connected.setup.ts b/wallets/metamask/test/playwright/wallet-setup/connected.setup.ts similarity index 100% rename from wallets/metamask/test/wallet-setup/connected.setup.ts rename to wallets/metamask/test/playwright/wallet-setup/connected.setup.ts diff --git a/wallets/metamask/tsconfig.json b/wallets/metamask/tsconfig.json index 15e94bcc2..4e7446721 100644 --- a/wallets/metamask/tsconfig.json +++ b/wallets/metamask/tsconfig.json @@ -4,14 +4,8 @@ "rootDir": ".", "exactOptionalPropertyTypes": false, // Allows for `undefined` in `playwright.config.ts` "types": ["cypress"], + "sourceMap": false }, - "include": [ - "src", - "test" - ], - "files": [ - "environment.d.ts", - "playwright.config.ts", - "vitest.config.ts", - ] + "include": ["src", "test"], + "files": ["environment.d.ts", "playwright.config.ts", "vitest.config.ts"] }