From 5aaa7b2d2beace126f8e678c25fb4fa94d3dfa74 Mon Sep 17 00:00:00 2001 From: matstyler Date: Mon, 4 Mar 2024 19:45:16 +0100 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20feat:=20MetaMask=20PPOM=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metamask/test/e2e/metamask/PPOM.spec.ts | 82 +++++++++++++++++++ .../e2e/metamask/confirmTransaction.spec.ts | 13 +++ 2 files changed, 95 insertions(+) create mode 100644 wallets/metamask/test/e2e/metamask/PPOM.spec.ts diff --git a/wallets/metamask/test/e2e/metamask/PPOM.spec.ts b/wallets/metamask/test/e2e/metamask/PPOM.spec.ts new file mode 100644 index 000000000..14dbb3640 --- /dev/null +++ b/wallets/metamask/test/e2e/metamask/PPOM.spec.ts @@ -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 + ) + }) +}) diff --git a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts index 30d59dc76..2db81b225 100644 --- a/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts +++ b/wallets/metamask/test/e2e/metamask/confirmTransaction.spec.ts @@ -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() + }) +}) From ef5ad7cf374f8df097af0c97958c1311f2c4bc98 Mon Sep 17 00:00:00 2001 From: matstyler Date: Mon, 4 Mar 2024 19:49:04 +0100 Subject: [PATCH 2/2] fix: cleanup --- .../metamask/test/e2e/metamask/PPOM.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/wallets/metamask/test/e2e/metamask/PPOM.spec.ts b/wallets/metamask/test/e2e/metamask/PPOM.spec.ts index 14dbb3640..37e2ca036 100644 --- a/wallets/metamask/test/e2e/metamask/PPOM.spec.ts +++ b/wallets/metamask/test/e2e/metamask/PPOM.spec.ts @@ -1,6 +1,6 @@ -import { testWithMetaMask } from '../testWithMetaMask' -import { createDataTestSelector } from '../../../src/utils/selectors/createDataTestSelector' import { getNotificationPageAndWaitForLoad } from '../../../src/utils/getNotificationPageAndWaitForLoad' +import { createDataTestSelector } from '../../../src/utils/selectors/createDataTestSelector' +import { testWithMetaMask } from '../testWithMetaMask' const test = testWithMetaMask @@ -13,7 +13,7 @@ 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!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_ERROR @@ -23,7 +23,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious ERC20 transfer', async ({ context, page, metamask }) => { await page.locator('#maliciousERC20TransferButton').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_WARNING @@ -33,7 +33,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious ERC20 approval', async ({ context, page, metamask }) => { await page.locator('#maliciousApprovalButton').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_WARNING @@ -43,7 +43,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious approval for all', async ({ context, page, metamask }) => { await page.locator('#maliciousSetApprovalForAll').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_WARNING @@ -53,7 +53,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious permit', async ({ context, page, metamask }) => { await page.locator('#maliciousPermit').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_ERROR @@ -63,7 +63,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious trade order', async ({ context, page, metamask }) => { await page.locator('#maliciousTradeOrder').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_ERROR @@ -73,7 +73,7 @@ describe('using PPOM security mechanism', () => { test('should prevent malicious seaport', async ({ context, page, metamask }) => { await page.locator('#maliciousSeaport').click() - const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId!) + const notificationPage = await getNotificationPageAndWaitForLoad(context, metamask.extensionId || '') await expect(notificationPage.locator(createDataTestSelector('security-provider-banner-alert'))).toContainText( PPOM_ERROR