Skip to content

Commit

Permalink
✨ feat(metamask): Add support for transactions (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception authored Nov 16, 2023
1 parent d6af806 commit 2cd47a9
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 2 deletions.
16 changes: 16 additions & 0 deletions wallets/metamask/src/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,20 @@ export class MetaMask {

await this.notificationPage.rejectSwitchNetwork(this.extensionId)
}

async confirmTransaction() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.confirmTransaction(this.extensionId)
}

async rejectTransaction() {
if (!this.extensionId) {
throw NO_EXTENSION_ID_ERROR
}

await this.notificationPage.rejectTransaction(this.extensionId)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './connectToDapp'
export * from './signSimpleMessage'
export * from './signStructuredMessage'
export * from './transaction'
export * from './network'
15 changes: 15 additions & 0 deletions wallets/metamask/src/pages/NotificationPage/actions/transaction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Page } from '@playwright/test'
import Selectors from '../selectors'

const confirmTransaction = async (notificationPage: Page) => {
await notificationPage.locator(Selectors.TransactionPage.confirmButton).click()
}

const rejectTransaction = async (notificationPage: Page) => {
await notificationPage.locator(Selectors.TransactionPage.rejectButton).click()
}

export const transaction = {
confirm: confirmTransaction,
reject: rejectTransaction
}
14 changes: 13 additions & 1 deletion wallets/metamask/src/pages/NotificationPage/page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Page } from '@playwright/test'
import { getNotificationPageAndWaitForLoad } from '../../utils/getNotificationPageAndWaitForLoad'
import { waitFor } from '../../utils/waitFor'
import { connectToDapp, network, signSimpleMessage, signStructuredMessage } from './actions'
import { connectToDapp, network, signSimpleMessage, signStructuredMessage, transaction } from './actions'
import Selectors from './selectors'

export class NotificationPage {
Expand Down Expand Up @@ -79,4 +79,16 @@ export class NotificationPage {

await network.rejectSwitchNetwork(notificationPage)
}

async confirmTransaction(extensionId: string) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

await transaction.confirm(notificationPage)
}

async rejectTransaction(extensionId: string) {
const notificationPage = await getNotificationPageAndWaitForLoad(this.page.context(), extensionId)

await transaction.reject(notificationPage)
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import NetworkPage from './networkPage'
import SignaturePage from './signaturePage'
import TransactionPage from './transactionPage'

export default {
SignaturePage,
NetworkPage
NetworkPage,
TransactionPage
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createDataTestSelector } from '../../../utils/selectors/createDataTestSelector'

export default {
confirmButton: `.page-container__footer ${createDataTestSelector('page-container-footer-next')}`,
rejectButton: `.page-container__footer ${createDataTestSelector('page-container-footer-cancel')}`
}
19 changes: 19 additions & 0 deletions wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { testWithMetaMask } from '../testWithMetaMask'

const test = testWithMetaMask

const { expect } = test

test('should confirm contract deployment', async ({ page, metamask }) => {
await page.locator('#addEthereumChain').click()

await metamask.approveNewNetwork()
await metamask.approveSwitchNetwork()

await expect(page.locator('#tokenAddresses')).toBeEmpty()
await page.locator('#createToken').click()

await metamask.confirmTransaction()

await expect(page.locator('#tokenAddresses')).toContainText(/^0x/)
})
19 changes: 19 additions & 0 deletions wallets/metamask/test/e2e/metamask/rejectTransaction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { testWithMetaMask } from '../testWithMetaMask'

const test = testWithMetaMask

const { expect } = test

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

await metamask.approveNewNetwork()
await metamask.approveSwitchNetwork()

await expect(page.locator('#tokenAddresses')).toBeEmpty()
await page.locator('#createToken').click()

await metamask.rejectTransaction()

await expect(page.locator('#tokenAddresses')).toHaveText('Creation Failed')
})

0 comments on commit 2cd47a9

Please sign in to comment.