Skip to content

Commit

Permalink
♻️ refactor(metamask): Add testWithMetaMask fixture (#996)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception authored Nov 15, 2023
1 parent 7b15861 commit d6af806
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 108 deletions.
15 changes: 3 additions & 12 deletions wallets/metamask/test/e2e/metamask/approveNewNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect } = test

test('should add a new network', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await expect(page.locator('#chainId')).toHaveText('0x1')

test('should add a new network', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
Expand Down
21 changes: 4 additions & 17 deletions wallets/metamask/test/e2e/metamask/approveSwitchNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect, describe } = test

describe('when adding a new network', () => {
test('should switch to the new network', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await expect(page.locator('#chainId')).toHaveText('0x1')

test('should switch to the new network', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
Expand All @@ -24,11 +15,7 @@ describe('when adding a new network', () => {
})
})

test('should switch to the requested network', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should switch to the requested network', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
Expand Down
31 changes: 6 additions & 25 deletions wallets/metamask/test/e2e/metamask/confirmSignature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect } = test

test('should confirm `personal_sign`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should confirm `personal_sign`', async ({ page, metamask }) => {
await page.locator('#personalSign').click()

await metamask.confirmSignature()
Expand All @@ -30,11 +23,7 @@ test('should confirm `personal_sign`', async ({ context, metamaskPage, page, ext
)
})

test('should confirm `eth_signTypedData`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should confirm `eth_signTypedData`', async ({ page, metamask }) => {
await page.locator('#signTypedData').click()

await metamask.confirmSignature()
Expand All @@ -48,11 +37,7 @@ test('should confirm `eth_signTypedData`', async ({ context, metamaskPage, page,
await expect(page.locator('#signTypedDataVerifyResult')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
})

test('should confirm `eth_signTypedData_v3`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should confirm `eth_signTypedData_v3`', async ({ page, metamask }) => {
await page.locator('#signTypedDataV3').click()

await metamask.confirmSignature()
Expand All @@ -66,11 +51,7 @@ test('should confirm `eth_signTypedData_v3`', async ({ context, metamaskPage, pa
await expect(page.locator('#signTypedDataV3VerifyResult')).toHaveText('0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266')
})

test('should confirm `eth_signTypedData_v4`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should confirm `eth_signTypedData_v4`', async ({ page, metamask }) => {
await page.locator('#signTypedDataV4').click()

await metamask.confirmSignature()
Expand Down
15 changes: 3 additions & 12 deletions wallets/metamask/test/e2e/metamask/rejectAddNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect } = test

test('should reject new network request', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await expect(page.locator('#chainId')).toHaveText('0x1')

test('should reject new network request', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.rejectNewNetwork()
Expand Down
31 changes: 6 additions & 25 deletions wallets/metamask/test/e2e/metamask/rejectSignature.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect } = test

test('should reject `personal_sign`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should reject `personal_sign`', async ({ page, metamask }) => {
await page.locator('#personalSign').click()

await metamask.rejectSignature()
Expand All @@ -22,11 +15,7 @@ test('should reject `personal_sign`', async ({ context, metamaskPage, page, exte
await expect(page.locator('#personalSignResult')).toHaveText('')
})

test('should reject `eth_signTypedData`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should reject `eth_signTypedData`', async ({ page, metamask }) => {
await page.locator('#signTypedData').click()

await metamask.rejectSignature()
Expand All @@ -36,11 +25,7 @@ test('should reject `eth_signTypedData`', async ({ context, metamaskPage, page,
)
})

test('should reject `eth_signTypedData_v3`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should reject `eth_signTypedData_v3`', async ({ page, metamask }) => {
await page.locator('#signTypedDataV3').click()

await metamask.rejectSignature()
Expand All @@ -50,11 +35,7 @@ test('should reject `eth_signTypedData_v3`', async ({ context, metamaskPage, pag
)
})

test('should reject `eth_signTypedData_v4`', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should reject `eth_signTypedData_v4`', async ({ page, metamask }) => {
await page.locator('#signTypedDataV4').click()

await metamask.rejectSignature()
Expand Down
21 changes: 4 additions & 17 deletions wallets/metamask/test/e2e/metamask/rejectSwitchNetwork.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../../src'
import { testWithMetaMask } from '../testWithMetaMask'

import connectedSetup from '../wallet-setup/connected.setup'

const test = testWithSynpress(connectedSetup, unlockForFixture)
const test = testWithMetaMask

const { expect, describe } = test

describe('when adding a new network', () => {
test('should reject switch network request', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

await expect(page.locator('#chainId')).toHaveText('0x1')

test('should reject switch network request', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
Expand All @@ -24,11 +15,7 @@ describe('when adding a new network', () => {
})
})

test('should reject switch network request', async ({ context, metamaskPage, page, extensionId }) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await page.goto('https://metamask.github.io/test-dapp/')

test('should reject switch network request', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
Expand Down
17 changes: 17 additions & 0 deletions wallets/metamask/test/e2e/testWithMetaMask.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { testWithSynpress } from 'fixtures'
import { MetaMask, unlockForFixture } from '../../src'

import connectedSetup from './wallet-setup/connected.setup'

export const testWithMetaMask = testWithSynpress(connectedSetup, unlockForFixture).extend<{ metamask: MetaMask }>({
metamask: async ({ context, metamaskPage, extensionId }, use) => {
const metamask = new MetaMask(context, metamaskPage, connectedSetup.walletPassword, extensionId)

await use(metamask)
},
page: async ({ page }, use) => {
await page.goto('https://metamask.github.io/test-dapp/')

await use(page)
}
})

0 comments on commit d6af806

Please sign in to comment.