From a1b6d9f5977c4403a98b77b512e838c2126eb11e Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 12 Nov 2024 19:17:04 +0530 Subject: [PATCH] Adding e2e for signature decoding --- privacy-snapshot.json | 1 + test/e2e/tests/confirmations/helpers.ts | 32 +++++++++++++++++++ .../confirmations/signatures/permit.spec.ts | 31 ++++++++++++++++++ 3 files changed, 64 insertions(+) diff --git a/privacy-snapshot.json b/privacy-snapshot.json index 36249b132bca..5620903a5c73 100644 --- a/privacy-snapshot.json +++ b/privacy-snapshot.json @@ -48,6 +48,7 @@ "price.api.cx.metamask.io", "proxy.api.cx.metamask.io", "proxy.dev-api.cx.metamask.io", + "qtgdj2huxh.execute-api.us-east-2.amazonaws.com", "raw.githubusercontent.com", "registry.npmjs.org", "responsive-rpc.test", diff --git a/test/e2e/tests/confirmations/helpers.ts b/test/e2e/tests/confirmations/helpers.ts index 355f664ec61c..e9fabe7ece04 100644 --- a/test/e2e/tests/confirmations/helpers.ts +++ b/test/e2e/tests/confirmations/helpers.ts @@ -9,6 +9,9 @@ import { MockedEndpoint, Mockttp } from '../../mock-e2e'; import { SMART_CONTRACTS } from '../../seeder/smart-contracts'; import { Driver } from '../../webdriver/driver'; +export const DECODING_E2E_API_URL = + 'https://qtgdj2huxh.execute-api.us-east-2.amazonaws.com/uat/v1'; + export async function scrollAndConfirmAndAssertConfirm(driver: Driver) { await driver.clickElementSafe('.confirm-scroll-to-bottom__button'); await driver.clickElement('[data-testid="confirm-footer-button"]'); @@ -101,3 +104,32 @@ export async function mockSignatureRejected( ...anonEvents, ]; } + +export async function mockPermitDecoding(mockServer: Mockttp) { + return [ + await mockServer + .forPost(`${DECODING_E2E_API_URL}/signature`) + .thenCallback(() => ({ + statusCode: 200, + json: { + stateChanges: [ + { + assetType: 'NATIVE', + changeType: 'RECEIVE', + address: '', + amount: '900000000000000000', + contractAddress: '', + }, + { + assetType: 'ERC721', + changeType: 'LISTING', + address: '', + amount: '', + contractAddress: '0xafd4896984CA60d2feF66136e57f958dCe9482d5', + tokenID: '2101', + }, + ], + }, + })), + ]; +} diff --git a/test/e2e/tests/confirmations/signatures/permit.spec.ts b/test/e2e/tests/confirmations/signatures/permit.spec.ts index bc74b9fd2f5f..4bd1e3bc6e89 100644 --- a/test/e2e/tests/confirmations/signatures/permit.spec.ts +++ b/test/e2e/tests/confirmations/signatures/permit.spec.ts @@ -11,6 +11,8 @@ import { import { Ganache } from '../../../seeder/ganache'; import { Driver } from '../../../webdriver/driver'; import { + DECODING_E2E_API_URL, + mockPermitDecoding, mockSignatureApproved, mockSignatureRejected, scrollAndConfirmAndAssertConfirm, @@ -111,6 +113,35 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) { mockSignatureRejected, ); }); + + it('display decoding information if available', async function () { + await withRedesignConfirmationFixtures( + this.test?.fullTitle(), + TransactionEnvelopeType.legacy, + async ({ driver }: TestSuiteArguments) => { + process.env.ENABLE_SIGNATURE_DECODING = 'true'; + process.env.DECODING_API_URL = DECODING_E2E_API_URL; + await unlockWallet(driver); + await openDapp(driver); + await driver.clickElement('#signPermit'); + await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog); + const simulationSection = driver.findElement({ + text: 'Estimated changes', + }); + const receiveChange = driver.findElement({ text: 'You receive' }); + const listChange = driver.findElement({ text: 'You list' }); + const listChangeValue = driver.findElement({ text: '#2101' }); + + assert.ok(await simulationSection, 'Estimated changes'); + assert.ok(await receiveChange, 'You receive'); + assert.ok(await listChange, 'You list'); + assert.ok(await listChangeValue, '#2101'); + + await driver.delay(10000); + }, + mockPermitDecoding, + ); + }); }); async function assertInfoValues(driver: Driver) {