Skip to content

Commit

Permalink
✨ feat: MetaMask PPOM tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matstyler committed Mar 4, 2024
1 parent b1099c7 commit 5aaa7b2
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
82 changes: 82 additions & 0 deletions wallets/metamask/test/e2e/metamask/PPOM.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { testWithMetaMask } from '../testWithMetaMask'
import { createDataTestSelector } from '../../../src/utils/selectors/createDataTestSelector'
import { getNotificationPageAndWaitForLoad } from '../../../src/utils/getNotificationPageAndWaitForLoad'

const test = testWithMetaMask

const { describe, expect } = test

const PPOM_ERROR = 'This is a deceptive request'
const PPOM_WARNING = 'Request may not be safe'

describe('using PPOM security mechanism', () => {
test('should prevent malicious ETH transfer', async ({ context, page, metamask }) => {
await page.locator('#maliciousRawEthButton').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_ERROR
)
})

test('should prevent malicious ERC20 transfer', async ({ context, page, metamask }) => {
await page.locator('#maliciousERC20TransferButton').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_WARNING
)
})

test('should prevent malicious ERC20 approval', async ({ context, page, metamask }) => {
await page.locator('#maliciousApprovalButton').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_WARNING
)
})

test('should prevent malicious approval for all', async ({ context, page, metamask }) => {
await page.locator('#maliciousSetApprovalForAll').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_WARNING
)
})

test('should prevent malicious permit', async ({ context, page, metamask }) => {
await page.locator('#maliciousPermit').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_ERROR
)
})

test('should prevent malicious trade order', async ({ context, page, metamask }) => {
await page.locator('#maliciousTradeOrder').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_ERROR
)
})

test('should prevent malicious seaport', async ({ context, page, metamask }) => {
await page.locator('#maliciousSeaport').click()

const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!)

await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText(
PPOM_ERROR
)
})
})
13 changes: 13 additions & 0 deletions wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,16 @@ describe('without gas limit', () => {
await metamask.confirmTransaction()
})
})

describe('using custom transaction form', () => {
test('should send defined amount', async ({ page, metamask, connectToAnvil }) => {
await connectToAnvil()

await page.locator('#toInput').fill('0x70997970C51812dc3A010C7d01b50e0d17dc79C8')
await page.locator('#amountInput').fill('3')
await page.locator('#gasInput').fill('1000000000')

await page.locator('#submitForm').click()
await metamask.confirmTransaction()
})
})

0 comments on commit 5aaa7b2

Please sign in to comment.