Skip to content

Commit

Permalink
fix: naming
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler committed May 6, 2024
1 parent bf29144 commit 132bb53
Show file tree
Hide file tree
Showing 15 changed files with 57 additions and 51 deletions.
10 changes: 5 additions & 5 deletions examples/new-dawn/test/e2e/00_mock.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ const test = testWithSynpress(ethereumWalletMockFixtures)

const { expect } = test

test('should mock MetaMask in the Test Dapp', async ({ page, walletMock }) => {
expect(await walletMock.getAllAccounts()).toHaveLength(1)
test('should mock MetaMask in the Test Dapp', async ({ page, ethereumWalletMock }) => {
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(1)

await page.locator('#connectButton').click()

await expect(page.locator('#accounts')).toHaveText('0xd73b04b0e696b0945283defa3eee453814758f1a')
})

test('should add new account using MetaMask mock', async ({ page }) => {
const walletMock = new EthereumWalletMock(page)
const ethereumWalletMock = new EthereumWalletMock(page)

await walletMock.importWallet('candy maple cake sugar pudding cream honey rich smooth crumble sweet treat')
await walletMock.addNewAccount()
await ethereumWalletMock.importWallet('candy maple cake sugar pudding cream honey rich smooth crumble sweet treat')
await ethereumWalletMock.addNewAccount()

await page.locator('#connectButton').click()

Expand Down
4 changes: 3 additions & 1 deletion examples/new-dawn/test/e2e/03_advanced.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const test = testWithSynpress(advancedFixtures)

const { expect, describe } = test

const tokenLocator = '.multichain-token-list-item'

describe('Token', () => {
test('should confirm tokens transfer', async ({ page, metamask, connectToAnvil, deployToken }) => {
await connectToAnvil()
Expand All @@ -31,7 +33,7 @@ describe('Token', () => {

await metamask.addNewToken()

await expect(metamaskPage.locator('.multichain-token-list-item').nth(1)).toContainText('TST')
await expect(metamaskPage.locator(tokenLocator).nth(1)).toContainText('TST')
})
})

Expand Down
4 changes: 2 additions & 2 deletions wallets/ethereum-wallet-mock/src/EthereumWalletMock.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
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'
import { ACCOUNT_MOCK, BLOCKCHAIN, OPTIMISM_NETWORK_ID } from './utils'

export type WalletMock = 'metamask' | 'coinbase' | 'phantom' | 'walletconnect' | 'walletlink'

Expand Down Expand Up @@ -172,7 +172,7 @@ export class EthereumWalletMock {
params: [{ chainId }]
})
},
[BLOCKCHAIN, this.wallet, networkName, BSC_NETWORK_ID]
[BLOCKCHAIN, this.wallet, networkName, OPTIMISM_NETWORK_ID]
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const require = createRequire(import.meta.url)
const web3MockPath = require.resolve('@depay/web3-mock/dist/umd/index.bundle.js')

type EthereumWalletMockFixtures = {
walletMock: EthereumWalletMock
ethereumWalletMock: EthereumWalletMock
}

export const ethereumWalletMockFixtures = base.extend<EthereumWalletMockFixtures>({
Expand All @@ -33,11 +33,11 @@ export const ethereumWalletMockFixtures = base.extend<EthereumWalletMockFixtures

await use(page)
},
walletMock: async ({ page }, use) => {
const walletMock = new EthereumWalletMock(page)
ethereumWalletMock: async ({ page }, use) => {
const ethereumWalletMock = new EthereumWalletMock(page)

walletMock.importWallet(SEED_PHRASE)
await ethereumWalletMock.importWallet(SEED_PHRASE)

await use(walletMock)
await use(ethereumWalletMock)
}
})
2 changes: 1 addition & 1 deletion wallets/ethereum-wallet-mock/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export const SEED_PHRASE = 'test test test test test test test test test test te

export const PRIVATE_KEY = 'ea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a'

export const BSC_NETWORK_ID = '0x38'
export const OPTIMISM_NETWORK_ID = '0xa'
14 changes: 7 additions & 7 deletions wallets/ethereum-wallet-mock/test/e2e/addNewAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import test from '../synpress'

const { expect } = test

test('should add a new account with specified name', async ({ walletMock }) => {
test('should add a new account with specified name', async ({ ethereumWalletMock }) => {
// Imported wallet includes 1 account
expect(await walletMock.getAllAccounts()).toHaveLength(1)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(1)

await walletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()

expect(await walletMock.getAllAccounts()).toHaveLength(2)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(2)

await walletMock.addNewAccount()
await walletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()

expect(await walletMock.getAllAccounts()).toHaveLength(4)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(4)
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import test from '../synpress'

const { expect } = test

test('should import account using private key', async ({ page, walletMock }) => {
await walletMock.importWalletFromPrivateKey('0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a')
test('should import account using private key', async ({ page, ethereumWalletMock }) => {
await ethereumWalletMock.importWalletFromPrivateKey(
'0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a'
)

await page.locator('#getAccounts').click()
await expect(page.locator('#getAccountsResult')).toHaveText('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import test from '../../synpress'

const { expect } = test

test('should add a new account with specified name', async ({ walletMock }) => {
test('should add a new account with specified name', async ({ ethereumWalletMock }) => {
// Imported wallet includes 1 account
expect(await walletMock.getAllAccounts()).toHaveLength(1)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(1)

await walletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()

expect(await walletMock.getAllAccounts()).toHaveLength(2)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(2)

await walletMock.addNewAccount()
await walletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()
await ethereumWalletMock.addNewAccount()

expect(await walletMock.getAllAccounts()).toHaveLength(4)
expect(await ethereumWalletMock.getAllAccounts()).toHaveLength(4)
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import test from '../../synpress'

const { expect } = test

test('should import account using private key', async ({ page, walletMock }) => {
await walletMock.importWalletFromPrivateKey('0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a')
test('should import account using private key', async ({ page, ethereumWalletMock }) => {
await ethereumWalletMock.importWalletFromPrivateKey(
'0xea084c575a01e2bbefcca3db101eaeab1d8af15554640a510c73692db24d0a6a'
)

await page.locator('#getAccounts').click()
await expect(page.locator('#getAccountsResult')).toHaveText('0xa2ce797cA71d0EaE1be5a7EffD27Fd6C38126801')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ test('should connect to ethereum', async ({ page }) => {
expect(currentChainId).toEqual('0x1')
})

test('should be able to connect to every supported ethereum wallet', async ({ page, walletMock }) => {
test('should be able to connect to every supported ethereum wallet', async ({ page, ethereumWalletMock }) => {
// Metamask
let ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isMetaMask).toBe(true)
expect(ethereum.isCoinbaseWallet).toBe(undefined)

// Coinbase wallet
await walletMock.connectToDapp('coinbase')
await ethereumWalletMock.connectToDapp('coinbase')
ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isCoinbaseWallet).toBe(true)

// Walletconnect
await walletMock.connectToDapp('walletconnect')
await ethereumWalletMock.connectToDapp('walletconnect')
ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isWalletLink).toBe(true)
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import test from '../../synpress'

const { expect } = test

test('should switch account', async ({ page, walletMock }) => {
await walletMock.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')
test('should switch account', async ({ page, ethereumWalletMock }) => {
await ethereumWalletMock.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')

await page.locator('#getAccounts').click()
await expect(page.locator('#getAccountsResult')).toHaveText('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ function createAnvilNetwork() {
}
}

test('should switch network', async ({ walletMock, page }) => {
test('should switch network', async ({ ethereumWalletMock, page }) => {
const network = createAnvilNetwork()

await walletMock.addNetwork(network)
await ethereumWalletMock.addNetwork(network)

await walletMock.switchNetwork(network.name)
await ethereumWalletMock.switchNetwork(network.name)

const chainId = await page.evaluate(async () => {
return await window.ethereum.request({ method: 'eth_chainId' })
})

expect(chainId).toBe('0x38')
expect(chainId).toBe('0xa')
})
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ test('should connect to ethereum', async ({ page }) => {
expect(currentChainId).toEqual('0x1')
})

test('should be able to connect to every supported ethereum wallet', async ({ page, walletMock }) => {
test('should be able to connect to every supported ethereum wallet', async ({ page, ethereumWalletMock }) => {
// Metamask
let ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isMetaMask).toBe(true)
expect(ethereum.isCoinbaseWallet).toBe(undefined)

// Coinbase wallet
await walletMock.connectToDapp('coinbase')
await ethereumWalletMock.connectToDapp('coinbase')
ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isCoinbaseWallet).toBe(true)

// Walletconnect
await walletMock.connectToDapp('walletconnect')
await ethereumWalletMock.connectToDapp('walletconnect')
ethereum = await page.evaluate(() => window.ethereum)
expect(ethereum.isWalletLink).toBe(true)
})
4 changes: 2 additions & 2 deletions wallets/ethereum-wallet-mock/test/e2e/switchAccount.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import test from '../synpress'

const { expect } = test

test('should switch account', async ({ page, walletMock }) => {
await walletMock.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')
test('should switch account', async ({ page, ethereumWalletMock }) => {
await ethereumWalletMock.switchAccount('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')

await page.locator('#getAccounts').click()
await expect(page.locator('#getAccountsResult')).toHaveText('0x4444797cA71d0EaE1be5a7EffD27Fd6C38126801')
Expand Down
10 changes: 5 additions & 5 deletions wallets/ethereum-wallet-mock/test/e2e/switchNetwork.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ function createAnvilNetwork() {
}
}

test('should switch network', async ({ walletMock, page }) => {
test('should switch network', async ({ ethereumWalletMock, page }) => {
const network = createAnvilNetwork()

await walletMock.addNetwork(network)
await ethereumWalletMock.addNetwork(network)

await walletMock.switchNetwork(network.name)
await ethereumWalletMock.switchNetwork(network.name)

const chainId = await page.evaluate(async () => {
return await window.ethereum.request({ method: 'eth_chainId' })
})

// Mocked BSC chain id due to https://github.com/DePayFi/web3-mock/issues/33
expect(chainId).toBe('0x38')
// Mocked Optimism chain id due to https://github.com/DePayFi/web3-mock/issues/33
expect(chainId).toBe('0xa')
})

0 comments on commit 132bb53

Please sign in to comment.