diff --git a/examples/new-dawn/test/e2e/00_mock.spec.ts b/examples/new-dawn/test/e2e/00_mock.spec.ts index ebcbf11fa..02a1ff137 100644 --- a/examples/new-dawn/test/e2e/00_mock.spec.ts +++ b/examples/new-dawn/test/e2e/00_mock.spec.ts @@ -1,11 +1,13 @@ -import { MetaMaskMock, testWithMetaMaskMock } from '@synthetixio/synpress' +import { EthereumWalletMock, testWithEthereumWalletMock } from '@synthetixio/synpress' -const test = testWithMetaMaskMock +const test = testWithEthereumWalletMock const { expect } = test -test('should mock MetaMask in the Test Dapp', async ({ page }) => { - await page.goto('/') +test('should mock MetaMask in the Test Dapp', async ({ page, walletMock }) => { + expect(await walletMock.getAllAccounts()).toHaveLength(1) + + await page.locator('#connectButton').click() await expect(page.locator('#accounts')).toHaveText('0xd73b04b0e696b0945283defa3eee453814758f1a') @@ -14,10 +16,14 @@ test('should mock MetaMask in the Test Dapp', async ({ page }) => { }) test('should add new account using MetaMask mock', async ({ page }) => { - const metamask = new MetaMaskMock(page) + const walletMock = new EthereumWalletMock(page) - metamask.importWallet('candy maple cake sugar pudding cream honey rich smooth crumble sweet treat') - await metamask.addNewAccount() + await walletMock.importWallet('candy maple cake sugar pudding cream honey rich smooth crumble sweet treat') + await walletMock.addNewAccount() - await expect(page.locator('#accounts')).toHaveText('0xd73b04b0e696b0945283defa3eee453814758f1a') + await page.locator('#connectButton').click() + + await expect(page.locator('#accounts')).toHaveText( + '0x6503D95e3F20389EE9496b277ABfFDb8eCCD2cc5,0xd73b04b0e696b0945283defa3eee453814758f1a' + ) }) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 711978ab3..010ad8f50 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -211,6 +211,9 @@ importers: '@playwright/test': specifier: 1.41.2 version: 1.41.2 + '@synthetixio/ethereum-wallet-mock': + specifier: 0.0.1-alpha.3 + version: link:../wallets/ethereum-wallet-mock '@synthetixio/synpress-core': specifier: 0.0.1-alpha.3 version: link:../packages/core @@ -220,9 +223,6 @@ importers: '@synthetixio/synpress-metamask': specifier: 0.0.1-alpha.3 version: link:../wallets/metamask - '@synthetixio/synpress-metamask-mock': - specifier: 0.0.1-alpha.3 - version: link:../wallets/metamask-mock devDependencies: '@synthetixio/synpress-tsconfig': specifier: 0.0.1-alpha.3 @@ -240,20 +240,17 @@ importers: specifier: 5.3.3 version: 5.3.3 - wallets/metamask: + wallets/ethereum-wallet-mock: dependencies: + '@depay/web3-mock': + specifier: 14.17.0 + version: 14.17.0 '@playwright/test': specifier: 1.41.2 version: 1.41.2 - '@synthetixio/synpress-core': - specifier: 0.0.1-alpha.3 - version: link:../../packages/core - '@synthetixio/synpress-fixtures': - specifier: 0.0.1-alpha.3 - version: link:../../packages/fixtures - zod: - specifier: 3.22.4 - version: 3.22.4 + viem: + specifier: 2.9.9 + version: 2.9.9(typescript@5.3.3) devDependencies: '@synthetixio/synpress-tsconfig': specifier: 0.0.1-alpha.3 @@ -273,21 +270,21 @@ importers: typescript: specifier: 5.3.3 version: 5.3.3 - vitest: - specifier: 1.2.2 - version: 1.2.2(@types/node@20.11.17) - wallets/metamask-mock: + wallets/metamask: dependencies: - '@depay/web3-mock': - specifier: 14.17.0 - version: 14.17.0 '@playwright/test': specifier: 1.41.2 version: 1.41.2 - viem: - specifier: 2.9.9 - version: 2.9.9(typescript@5.3.3) + '@synthetixio/synpress-core': + specifier: 0.0.1-alpha.3 + version: link:../../packages/core + '@synthetixio/synpress-fixtures': + specifier: 0.0.1-alpha.3 + version: link:../../packages/fixtures + zod: + specifier: 3.22.4 + version: 3.22.4 devDependencies: '@synthetixio/synpress-tsconfig': specifier: 0.0.1-alpha.3 @@ -307,6 +304,9 @@ importers: typescript: specifier: 5.3.3 version: 5.3.3 + vitest: + specifier: 1.2.2 + version: 1.2.2(@types/node@20.11.17) packages: diff --git a/release/package.json b/release/package.json index 37240e689..0a3902bde 100644 --- a/release/package.json +++ b/release/package.json @@ -26,10 +26,10 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "@synthetixio/ethereum-wallet-mock": "0.0.1-alpha.3", "@synthetixio/synpress-core": "0.0.1-alpha.3", "@synthetixio/synpress-fixtures": "0.0.1-alpha.3", - "@synthetixio/synpress-metamask": "0.0.1-alpha.3", - "@synthetixio/synpress-metamask-mock": "0.0.1-alpha.3" + "@synthetixio/synpress-metamask": "0.0.1-alpha.3" }, "devDependencies": { "@synthetixio/synpress-tsconfig": "0.0.1-alpha.3", diff --git a/release/src/index.ts b/release/src/index.ts index 75bd9686d..e0bb3d6ce 100644 --- a/release/src/index.ts +++ b/release/src/index.ts @@ -1,15 +1,15 @@ +import { EthereumWalletMock, testWithEthereumWalletMock } from '@synthetixio/ethereum-wallet-mock' import { defineWalletSetup } from '@synthetixio/synpress-core' import { getExtensionId, testWithSynpress } from '@synthetixio/synpress-fixtures' import { MetaMask, homePageSelectors, unlockForFixture } from '@synthetixio/synpress-metamask' -import { MetaMaskMock, testWithMetaMaskMock } from '@synthetixio/synpress-metamask-mock' export { // Framework fixtures testWithSynpress, - testWithMetaMaskMock, + testWithEthereumWalletMock, // API MetaMask, - MetaMaskMock, + EthereumWalletMock, // Helpers defineWalletSetup, getExtensionId, diff --git a/wallets/metamask-mock/environment.d.ts b/wallets/ethereum-wallet-mock/environment.d.ts similarity index 100% rename from wallets/metamask-mock/environment.d.ts rename to wallets/ethereum-wallet-mock/environment.d.ts diff --git a/wallets/metamask-mock/package.json b/wallets/ethereum-wallet-mock/package.json similarity index 95% rename from wallets/metamask-mock/package.json rename to wallets/ethereum-wallet-mock/package.json index 12baa8293..79dfa6411 100644 --- a/wallets/metamask-mock/package.json +++ b/wallets/ethereum-wallet-mock/package.json @@ -1,5 +1,5 @@ { - "name": "@synthetixio/synpress-metamask-mock", + "name": "@synthetixio/ethereum-wallet-mock", "version": "0.0.1-alpha.3", "type": "module", "exports": { diff --git a/wallets/metamask-mock/playwright.config.ts b/wallets/ethereum-wallet-mock/playwright.config.ts similarity index 100% rename from wallets/metamask-mock/playwright.config.ts rename to wallets/ethereum-wallet-mock/playwright.config.ts diff --git a/wallets/metamask-mock/src/metamask-mock.ts b/wallets/ethereum-wallet-mock/src/ethereum-wallet-mock.ts similarity index 63% rename from wallets/metamask-mock/src/metamask-mock.ts rename to wallets/ethereum-wallet-mock/src/ethereum-wallet-mock.ts index 798277a1c..81f9314b4 100644 --- a/wallets/metamask-mock/src/metamask-mock.ts +++ b/wallets/ethereum-wallet-mock/src/ethereum-wallet-mock.ts @@ -1,35 +1,15 @@ -// @ts-ignore -import { connect } from '@depay/web3-mock' import type { Page } from '@playwright/test' import { mnemonicToAccount, privateKeyToAccount } from 'viem/accounts' import type { Network } from './network/Network' +import { ACCOUNT_MOCK, BLOCKCHAIN, BSC_NETWORK_ID } from './utils' -export const blockchain = 'ethereum' -export const wallet = 'metamask' +export type WalletMock = 'metamask' | 'coinbase' | 'phantom' | 'walletconnect' | 'walletlink' -const networkConfig = { - blockchain, - wallet -} - -const BSC_NETWORK_ID = '0x38' - -export const SEED_PHRASE = 'test test test test test test test test test test test junk' - -export const PRIVATE_KEY = 'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' - -/** - * This class is the heart of Synpress's MetaMask API. - */ -export class MetaMaskMock { +export class EthereumWalletMock { seedPhrase = '' + wallet: WalletMock = 'metamask' - constructor( - /** - * The MetaMask tab page. - */ - readonly page: Page - ) { + constructor(readonly page: Page) { this.page = page } @@ -40,6 +20,19 @@ export class MetaMaskMock { */ importWallet(seedPhrase: string) { this.seedPhrase = seedPhrase + + return this.page.evaluate( + ([blockchain, wallet, accounts]) => { + return Web3Mock.mock({ + blockchain, + wallet, + accounts: { + return: accounts + } + }) + }, + [BLOCKCHAIN, this.wallet, [ACCOUNT_MOCK]] + ) } /** @@ -62,15 +55,16 @@ export class MetaMaskMock { }) return this.page.evaluate( - ([networkConfig, accounts]) => { + ([blockchain, wallet, accounts]) => { return Web3Mock.mock({ - ...networkConfig, + blockchain, + wallet, accounts: { return: accounts } }) }, - [networkConfig, [newAccount.address, ...accounts]] + [BLOCKCHAIN, this.wallet, [newAccount.address, ...accounts]] ) } @@ -83,15 +77,16 @@ export class MetaMaskMock { const newAccount = privateKeyToAccount(privateKey) return this.page.evaluate( - ([networkConfig, account]) => { + ([blockchain, wallet, account]) => { return Web3Mock.mock({ - ...networkConfig, + blockchain, + wallet, accounts: { return: account } }) }, - [networkConfig, [newAccount.address]] + [BLOCKCHAIN, this.wallet, [newAccount.address]] ) } @@ -102,16 +97,16 @@ export class MetaMaskMock { */ async switchAccount(accountAddress: string) { return this.page.evaluate( - ([networkConfig, accountAddress]) => { + ([blockchain, wallet, accountAddress]) => { return Web3Mock.mock({ - // @ts-ignore - ...networkConfig, + blockchain, + wallet, accounts: { return: [accountAddress] } }) }, - [networkConfig, accountAddress] + [BLOCKCHAIN, this.wallet, accountAddress] ) } @@ -135,15 +130,16 @@ export class MetaMaskMock { } return this.page.evaluate( - ([networkConfig, networkInfo]) => { + ([blockchain, wallet, networkInfo]) => { return Web3Mock.mock({ - ...networkConfig, + blockchain, + wallet, network: { add: networkInfo } }) }, - [networkConfig, networkInfo] + [BLOCKCHAIN, this.wallet, networkInfo] ) } @@ -161,10 +157,10 @@ export class MetaMaskMock { */ async switchNetwork(networkName: string) { return this.page.evaluate( - ([networkConfig, networkName, chainId]) => { + ([blockchain, wallet, networkName, chainId]) => { Web3Mock.mock({ - // @ts-ignore - ...networkConfig, + blockchain, + wallet, network: { switchTo: networkName } @@ -176,14 +172,36 @@ export class MetaMaskMock { params: [{ chainId }] }) }, - [networkConfig, networkName, BSC_NETWORK_ID] + [BLOCKCHAIN, this.wallet, networkName, BSC_NETWORK_ID] ) } /** - * Connects to the dapp using the currently selected account. + * Connects wallet to the dapp. */ - async connectToDapp(network: string) { - connect(network) + async connectToDapp(wallet: WalletMock = 'metamask') { + this.wallet = wallet + return this.page.evaluate( + ([blockchain, accounts, wallet]) => { + // Cannot pass custom class as an argument to `page.evaluate` + class WalletConnectStub {} + + let connector: WalletConnectStub | undefined + + if (wallet === 'walletconnect') { + connector = WalletConnectStub + } + + return Web3Mock.mock({ + blockchain, + wallet, + accounts: { + return: accounts + }, + connector + }) + }, + [BLOCKCHAIN, [ACCOUNT_MOCK], wallet] + ) } } diff --git a/wallets/ethereum-wallet-mock/src/index.ts b/wallets/ethereum-wallet-mock/src/index.ts new file mode 100644 index 000000000..c75e6ec10 --- /dev/null +++ b/wallets/ethereum-wallet-mock/src/index.ts @@ -0,0 +1,3 @@ +export * from './ethereum-wallet-mock' +export * from './utils' +export * from './testWithEthereumWalletMock' diff --git a/wallets/metamask-mock/src/network/Network.ts b/wallets/ethereum-wallet-mock/src/network/Network.ts similarity index 100% rename from wallets/metamask-mock/src/network/Network.ts rename to wallets/ethereum-wallet-mock/src/network/Network.ts diff --git a/wallets/metamask-mock/src/testWithMetaMaskMock.ts b/wallets/ethereum-wallet-mock/src/testWithEthereumWalletMock.ts similarity index 76% rename from wallets/metamask-mock/src/testWithMetaMaskMock.ts rename to wallets/ethereum-wallet-mock/src/testWithEthereumWalletMock.ts index f6bd28f93..eb5412a83 100644 --- a/wallets/metamask-mock/src/testWithMetaMaskMock.ts +++ b/wallets/ethereum-wallet-mock/src/testWithEthereumWalletMock.ts @@ -1,19 +1,16 @@ import { readFileSync } from 'fs' import { createRequire } from 'node:module' import { test as base } from '@playwright/test' -import { MetaMaskMock, SEED_PHRASE } from './metamask-mock' +import { EthereumWalletMock } from './ethereum-wallet-mock' import type { Network } from './network/Network' -import { mockEthereum } from './utils' - -const ANVIL_CHAIN_ID = 31337 -const ANVIL_URL_URL = 'http://anvil:5000' +import { ANVIL_CHAIN_ID, ANVIL_URL_URL, SEED_PHRASE, mockEthereum } from './utils' const require = createRequire(import.meta.url) // Relative path to the web3-mock bundle const web3MockPath = require.resolve('@depay/web3-mock/dist/umd/index.bundle.js') -export const testWithMetaMaskMock = base.extend<{ - metamask: MetaMaskMock +export const testWithEthereumWalletMock = base.extend<{ + walletMock: EthereumWalletMock createAnvilNetwork: () => Network deployToken: () => Promise }>({ @@ -34,12 +31,12 @@ export const testWithMetaMaskMock = base.extend<{ await use(page) }, - metamask: async ({ page }, use) => { - const metamask = new MetaMaskMock(page) + walletMock: async ({ page }, use) => { + const walletMock = new EthereumWalletMock(page) - metamask.importWallet(SEED_PHRASE) + await walletMock.importWallet(SEED_PHRASE) - await use(metamask) + await use(walletMock) }, createAnvilNetwork: async ({ context: _ }, use) => { await use(() => { diff --git a/wallets/ethereum-wallet-mock/src/utils/constants.ts b/wallets/ethereum-wallet-mock/src/utils/constants.ts new file mode 100644 index 000000000..c55d1bd8f --- /dev/null +++ b/wallets/ethereum-wallet-mock/src/utils/constants.ts @@ -0,0 +1,12 @@ +export const BLOCKCHAIN = 'ethereum' + +export const ACCOUNT_MOCK = '0xd73b04b0e696b0945283defa3eee453814758f1a' + +export const SEED_PHRASE = 'test test test test test test test test test test test junk' + +export const PRIVATE_KEY = 'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a' + +export const ANVIL_CHAIN_ID = 31337 +export const ANVIL_URL_URL = 'http://anvil:5000' + +export const BSC_NETWORK_ID = '0x38' diff --git a/wallets/metamask-mock/src/utils/index.ts b/wallets/ethereum-wallet-mock/src/utils/index.ts similarity index 67% rename from wallets/metamask-mock/src/utils/index.ts rename to wallets/ethereum-wallet-mock/src/utils/index.ts index 8fe4e82ee..2813a058c 100644 --- a/wallets/metamask-mock/src/utils/index.ts +++ b/wallets/ethereum-wallet-mock/src/utils/index.ts @@ -1 +1,2 @@ export { default as mockEthereum } from './mockEthereum' +export * from './constants' diff --git a/wallets/ethereum-wallet-mock/src/utils/mockEthereum.ts b/wallets/ethereum-wallet-mock/src/utils/mockEthereum.ts new file mode 100644 index 000000000..a3871b9df --- /dev/null +++ b/wallets/ethereum-wallet-mock/src/utils/mockEthereum.ts @@ -0,0 +1,12 @@ +export default function mockEthereum( + wallet: 'metamask' | 'coinbase' | 'phantom' | 'walletconnect' | 'walletlink' = 'metamask', + accounts: `0x${string}`[] = [] +) { + Web3Mock.mock({ + blockchain: 'ethereum', + wallet, + accounts: { + return: accounts + } + }) +} diff --git a/wallets/ethereum-wallet-mock/test/e2e/metamask/addNewAccount.spec.ts b/wallets/ethereum-wallet-mock/test/e2e/metamask/addNewAccount.spec.ts new file mode 100644 index 000000000..7ec93d0b8 --- /dev/null +++ b/wallets/ethereum-wallet-mock/test/e2e/metamask/addNewAccount.spec.ts @@ -0,0 +1,19 @@ +import { testWithEthereumWalletMock } from '../../../src' + +const test = testWithEthereumWalletMock + +const { expect } = test + +test('should add a new account with specified name', async ({ walletMock }) => { + // Imported wallet includes 1 account + expect(await walletMock.getAllAccounts()).toHaveLength(1) + + await walletMock.addNewAccount() + + expect(await walletMock.getAllAccounts()).toHaveLength(2) + + await walletMock.addNewAccount() + await walletMock.addNewAccount() + + expect(await walletMock.getAllAccounts()).toHaveLength(4) +}) diff --git a/wallets/ethereum-wallet-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts b/wallets/ethereum-wallet-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts new file mode 100644 index 000000000..07d9d1fb1 --- /dev/null +++ b/wallets/ethereum-wallet-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts @@ -0,0 +1,12 @@ +import { testWithEthereumWalletMock } from '../../../src' + +const test = testWithEthereumWalletMock + +const { expect } = test + +test('should import account using private key', async ({ page, walletMock }) => { + await walletMock.importWalletFromPrivateKey('0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a') + + await page.locator('#getAccounts').click() + await expect(page.locator('#getAccountsResult')).toHaveText('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801') +}) diff --git a/wallets/ethereum-wallet-mock/test/e2e/metamask/mock/mockEthereum.spec.ts b/wallets/ethereum-wallet-mock/test/e2e/metamask/mock/mockEthereum.spec.ts new file mode 100644 index 000000000..4917df84f --- /dev/null +++ b/wallets/ethereum-wallet-mock/test/e2e/metamask/mock/mockEthereum.spec.ts @@ -0,0 +1,42 @@ +import { testWithEthereumWalletMock } from '../../../../src' + +const test = testWithEthereumWalletMock + +const { expect } = test + +test('should be able to access ethereum API', async ({ page }) => { + const ethereum = await page.evaluate(() => window.ethereum) + expect(ethereum).toBeTruthy() +}) + +test('should be connected to metamask by default', async ({ page }) => { + const ethereum = await page.evaluate(() => window.ethereum) + expect(ethereum.isMetaMask).toBe(true) +}) + +test('should connect to ethereum', async ({ page }) => { + const currentChainId = await page.evaluate(() => + window.ethereum.request({ + method: 'eth_chainId' + }) + ) + + expect(currentChainId).toEqual('0x1') +}) + +test('should be able to connect to every supported ethereum wallet', async ({ page, walletMock }) => { + // Metamask + let ethereum = await page.evaluate(() => window.ethereum) + expect(ethereum.isMetaMask).toBe(true) + expect(ethereum.isCoinbaseWallet).toBe(undefined) + + // Coinbase wallet + await walletMock.connectToDapp('coinbase') + ethereum = await page.evaluate(() => window.ethereum) + expect(ethereum.isCoinbaseWallet).toBe(true) + + // Walletconnect + await walletMock.connectToDapp('walletconnect') + ethereum = await page.evaluate(() => window.ethereum) + expect(ethereum.isWalletLink).toBe(true) +}) diff --git a/wallets/ethereum-wallet-mock/test/e2e/metamask/switchAccount.spec.ts b/wallets/ethereum-wallet-mock/test/e2e/metamask/switchAccount.spec.ts new file mode 100644 index 000000000..c09f541e8 --- /dev/null +++ b/wallets/ethereum-wallet-mock/test/e2e/metamask/switchAccount.spec.ts @@ -0,0 +1,12 @@ +import { testWithEthereumWalletMock } from '../../../src' + +const test = testWithEthereumWalletMock + +const { expect } = test + +test('should switch account', async ({ page, walletMock }) => { + await walletMock.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801') + + await page.locator('#getAccounts').click() + await expect(page.locator('#getAccountsResult')).toHaveText('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801') +}) diff --git a/wallets/ethereum-wallet-mock/test/e2e/metamask/switchNetwork.spec.ts b/wallets/ethereum-wallet-mock/test/e2e/metamask/switchNetwork.spec.ts new file mode 100644 index 000000000..dbee188ff --- /dev/null +++ b/wallets/ethereum-wallet-mock/test/e2e/metamask/switchNetwork.spec.ts @@ -0,0 +1,19 @@ +import { testWithEthereumWalletMock } from '../../../src' + +const test = testWithEthereumWalletMock + +const { expect } = test + +test('should switch network', async ({ createAnvilNetwork, walletMock, page }) => { + const network = createAnvilNetwork() + + await walletMock.addNetwork(network) + + await walletMock.switchNetwork(network.name) + + const chainId = await page.evaluate(async () => { + return await window.ethereum.request({ method: 'eth_chainId' }) + }) + + expect(chainId).toBe('0x38') +}) diff --git a/wallets/metamask-mock/tsconfig.build.json b/wallets/ethereum-wallet-mock/tsconfig.build.json similarity index 100% rename from wallets/metamask-mock/tsconfig.build.json rename to wallets/ethereum-wallet-mock/tsconfig.build.json diff --git a/wallets/metamask-mock/tsconfig.json b/wallets/ethereum-wallet-mock/tsconfig.json similarity index 100% rename from wallets/metamask-mock/tsconfig.json rename to wallets/ethereum-wallet-mock/tsconfig.json diff --git a/wallets/metamask-mock/tsup.config.ts b/wallets/ethereum-wallet-mock/tsup.config.ts similarity index 87% rename from wallets/metamask-mock/tsup.config.ts rename to wallets/ethereum-wallet-mock/tsup.config.ts index 63ed05775..a7e4c2978 100644 --- a/wallets/metamask-mock/tsup.config.ts +++ b/wallets/ethereum-wallet-mock/tsup.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from 'tsup' export default defineConfig({ - name: 'metamask', + name: 'ethereum-wallet-mock', entry: ['src/index.ts'], outDir: 'dist', format: 'esm', diff --git a/wallets/metamask-mock/vitest.config.ts b/wallets/ethereum-wallet-mock/vitest.config.ts similarity index 100% rename from wallets/metamask-mock/vitest.config.ts rename to wallets/ethereum-wallet-mock/vitest.config.ts diff --git a/wallets/metamask-mock/src/index.ts b/wallets/metamask-mock/src/index.ts deleted file mode 100644 index 94d5183c1..000000000 --- a/wallets/metamask-mock/src/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './metamask-mock' -export * from './utils' -export * from './testWithMetaMaskMock' diff --git a/wallets/metamask-mock/src/utils/mockEthereum.ts b/wallets/metamask-mock/src/utils/mockEthereum.ts deleted file mode 100644 index 5c500f5f7..000000000 --- a/wallets/metamask-mock/src/utils/mockEthereum.ts +++ /dev/null @@ -1,9 +0,0 @@ -export default function mockEthereum() { - Web3Mock.mock({ - blockchain: 'ethereum', - wallet: 'metamask', - accounts: { - return: ['0xd73b04b0e696b0945283defa3eee453814758f1a'] - } - }) -} diff --git a/wallets/metamask-mock/test/e2e/metamask/addNewAccount.spec.ts b/wallets/metamask-mock/test/e2e/metamask/addNewAccount.spec.ts deleted file mode 100644 index 66d501321..000000000 --- a/wallets/metamask-mock/test/e2e/metamask/addNewAccount.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { testWithMetaMaskMock } from '../../../src' - -const test = testWithMetaMaskMock - -const { expect } = test - -test('should add a new account with specified name', async ({ metamask }) => { - expect(await metamask.getAllAccounts()).toHaveLength(1) - - await metamask.addNewAccount() - - expect(await metamask.getAllAccounts()).toHaveLength(2) - - await metamask.addNewAccount() - await metamask.addNewAccount() - - expect(await metamask.getAllAccounts()).toHaveLength(4) -}) diff --git a/wallets/metamask-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts b/wallets/metamask-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts deleted file mode 100644 index 8d699d21c..000000000 --- a/wallets/metamask-mock/test/e2e/metamask/importWalletFromPrivateKey.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { testWithMetaMaskMock } from '../../../src' - -const test = testWithMetaMaskMock - -const { expect } = test - -test('should import account using private key', async ({ page, metamask }) => { - await metamask.importWalletFromPrivateKey('0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a') - - await page.locator('#getAccounts').click() - await expect(page.locator('#getAccountsResult')).toHaveText('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801') -}) diff --git a/wallets/metamask-mock/test/e2e/metamask/mock/mockEthereum.spec.ts b/wallets/metamask-mock/test/e2e/metamask/mock/mockEthereum.spec.ts deleted file mode 100644 index 70fb1be59..000000000 --- a/wallets/metamask-mock/test/e2e/metamask/mock/mockEthereum.spec.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { testWithMetaMaskMock } from '../../../../src' - -const test = testWithMetaMaskMock - -const { expect } = test - -test('should be able to access ethereum API', async ({ page }) => { - const ethereum = await page.evaluate(() => window.ethereum) - expect(ethereum).toBeTruthy() -}) - -test('should be connected to metamask', async ({ page }) => { - const ethereum = await page.evaluate(() => window.ethereum) - expect(ethereum.isMetaMask).toBe(true) -}) - -test('should connect to ethereum', async ({ page }) => { - const currentChainId = await page.evaluate(() => - window.ethereum.request({ - method: 'eth_chainId' - }) - ) - - expect(currentChainId).toEqual('0x1') -}) diff --git a/wallets/metamask-mock/test/e2e/metamask/switchAccount.spec.ts b/wallets/metamask-mock/test/e2e/metamask/switchAccount.spec.ts deleted file mode 100644 index b3570e38d..000000000 --- a/wallets/metamask-mock/test/e2e/metamask/switchAccount.spec.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { testWithMetaMaskMock } from '../../../src' - -const test = testWithMetaMaskMock - -const { expect } = test - -test('should switch account', async ({ page, metamask }) => { - await metamask.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801') - - await page.locator('#getAccounts').click() - await expect(page.locator('#getAccountsResult')).toHaveText('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801') -}) diff --git a/wallets/metamask-mock/test/e2e/metamask/switchNetwork.spec.ts b/wallets/metamask-mock/test/e2e/metamask/switchNetwork.spec.ts deleted file mode 100644 index d04a2f238..000000000 --- a/wallets/metamask-mock/test/e2e/metamask/switchNetwork.spec.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { testWithMetaMaskMock } from '../../../src' - -const test = testWithMetaMaskMock - -const { expect } = test - -test('should switch network', async ({ createAnvilNetwork, metamask, page }) => { - const network = createAnvilNetwork() - - await metamask.addNetwork(network) - - await metamask.switchNetwork(network.name) - - const chainId = await page.evaluate(async () => { - return await window.ethereum.request({ method: 'eth_chainId' }) - }) - - expect(chainId).toBe('0x38') -}) diff --git a/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts b/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts index 52c6439fd..0a9e56292 100644 --- a/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts +++ b/wallets/metamask/test/e2e/metamask/connectToDapp.spec.ts @@ -32,6 +32,6 @@ test('should connect multiple wallets to dapp', async ({ context, page, metamask await metamask.connectToDapp(['Account x2', 'Account 1']) await expect(page.locator('#accounts')).toHaveText( - '0x976ea74026e726554db657fa54763abd0c3a0aa9,0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' + '0x70997970c51812dc3a010c7d01b50e0d17dc79c8,0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266' ) })