Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: MetaMask PPOM tests #1114

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { getNotificationPageAndWaitForLoad } from '../../../src/utils/getNotificationPageAndWaitForLoad'
import { createDataTestSelector } from '../../../src/utils/selectors/createDataTestSelector'
import { testWithMetaMask } from '../testWithMetaMask'

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()
})
})
Loading