Skip to content

Commit

Permalink
Adding e2e for signature decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri committed Nov 26, 2024
1 parent a6e1a74 commit a1b6d9f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/tests/confirmations/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]');
Expand Down Expand Up @@ -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',
},
],
},
})),
];
}
31 changes: 31 additions & 0 deletions test/e2e/tests/confirmations/signatures/permit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';
import {
DECODING_E2E_API_URL,
mockPermitDecoding,
mockSignatureApproved,
mockSignatureRejected,
scrollAndConfirmAndAssertConfirm,
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit a1b6d9f

Please sign in to comment.