Skip to content

Commit

Permalink
revert: un-revert metrics and signature refactor test (#25758)
Browse files Browse the repository at this point in the history
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/25758?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [ ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've completed the PR template to the best of my ability
- [ ] I’ve included tests if applicable
- [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [ ] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.
  • Loading branch information
pnarayanaswamy authored Jul 12, 2024
1 parent 528c653 commit 613b7a5
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 136 deletions.
114 changes: 0 additions & 114 deletions test/e2e/tests/confirmations/header.spec.js

This file was deleted.

51 changes: 51 additions & 0 deletions test/e2e/tests/confirmations/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import FixtureBuilder from '../../fixture-builder';
import { defaultGanacheOptions, withFixtures } from '../../helpers';
import { Mockttp } from '../../mock-e2e';
import { Driver } from '../../webdriver/driver';

export async function scrollAndConfirmAndAssertConfirm(driver: Driver) {
Expand All @@ -23,6 +24,10 @@ export function withRedesignConfirmationFixtures(
},
fixtures: new FixtureBuilder()
.withPermissionControllerConnectedToTestDapp()
.withMetaMetricsController({
metaMetricsId: 'fake-metrics-id',
participateInMetaMetrics: true,
})
.withPreferencesController({
preferences: {
redesignedConfirmationsEnabled: true,
Expand All @@ -31,7 +36,53 @@ export function withRedesignConfirmationFixtures(
.build(),
ganacheOptions: defaultGanacheOptions,
title,
testSpecificMock: mockSegment,
},
testFunction,
);
}

async function mockSegment(mockServer: Mockttp) {
return [
await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [{ type: 'track', event: 'Signature Requested' }],
})
.thenCallback(() => {
return {
statusCode: 200,
};
}),
await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [{ type: 'track', event: 'Signature Approved' }],
})
.thenCallback(() => {
return {
statusCode: 200,
};
}),
await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [{ type: 'track', event: 'Signature Rejected' }],
})
.thenCallback(() => {
return {
statusCode: 200,
};
}),
await mockServer
.forPost('https://api.segment.io/v1/batch')
.withJsonBodyIncluding({
batch: [{ type: 'track', event: 'Account Details Opened' }],
})
.thenCallback(() => {
return {
statusCode: 200,
};
}),
];
}
64 changes: 56 additions & 8 deletions test/e2e/tests/confirmations/signatures/permit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,32 @@ import {
} from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';
import { Mockttp } from '../../../mock-e2e';
import {
assertAccountDetailsMetrics,
assertHeaderInfoBalance,
assertPastedAddress,
assertSignatureMetrics,
clickHeaderInfoBtn,
copyAddressAndPasteWalletAddress,
} from './signature-helpers';

describe('Confirmation Signature - Permit', function (this: Suite) {
if (!process.env.ENABLE_CONFIRMATION_REDESIGN) {
return;
}

it('initiates and confirms', async function () {
it('initiates and confirms and emits the correct events', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({
driver,
ganacheServer,
mockedEndpoint: mockedEndpoints,
}: {
driver: Driver;
ganacheServer: Ganache;
mockedEndpoint: Mockttp;
}) => {
const addresses = await ganacheServer.getAccounts();
const publicAddress = addresses?.[0] as string;
Expand All @@ -37,17 +48,45 @@ describe('Confirmation Signature - Permit', function (this: Suite) {
await driver.clickElement('#signPermit');
await switchToNotificationWindow(driver);

await clickHeaderInfoBtn(driver);
await assertHeaderInfoBalance(driver);
await assertAccountDetailsMetrics(
driver,
mockedEndpoints,
'eth_signTypedData_v4',
);

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await switchToNotificationWindow(driver);

await assertInfoValues(driver);
await scrollAndConfirmAndAssertConfirm(driver);
await driver.delay(1000);

await assertSignatureMetrics(
driver,
mockedEndpoints,
'eth_signTypedData_v4',
'Permit',
['redesigned_confirmation', 'permit'],
);

await assertVerifiedResults(driver, publicAddress);
},
);
});

it('initiates and rejects', async function () {
it('initiates and rejects and emits the correct events', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver }: { driver: Driver }) => {
async ({
driver,
mockedEndpoint: mockedEndpoints,
}: {
driver: Driver;
mockedEndpoint: Mockttp;
}) => {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#signPermit');
Expand All @@ -56,15 +95,24 @@ describe('Confirmation Signature - Permit', function (this: Suite) {
await driver.clickElement(
'[data-testid="confirm-footer-cancel-button"]',
);
await driver.delay(1000);

await driver.waitUntilXWindowHandles(2);
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);

const rejectionResult = await driver.waitForSelector({
css: '#signPermitResult',
text: 'Error: User rejected the request.',
});
assert.ok(rejectionResult);
const rejectionResult = await driver.findElement('#signPermitResult');
assert.equal(
await rejectionResult.getText(),
'Error: User rejected the request.',
);

await assertSignatureMetrics(
driver,
mockedEndpoints,
'eth_signTypedData_v4',
'Permit',
['redesigned_confirmation', 'permit'],
);
},
);
});
Expand Down
32 changes: 31 additions & 1 deletion test/e2e/tests/confirmations/signatures/personal-sign.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ import {
} from '../../../helpers';
import { Ganache } from '../../../seeder/ganache';
import { Driver } from '../../../webdriver/driver';
import { Mockttp } from '../../../mock-e2e';
import {
assertHeaderInfoBalance,
assertPastedAddress,
clickHeaderInfoBtn,
copyAddressAndPasteWalletAddress,
assertSignatureMetrics,
assertAccountDetailsMetrics,
} from './signature-helpers';

describe('Confirmation Signature - Personal Sign', function (this: Suite) {
if (!process.env.ENABLE_CONFIRMATION_REDESIGN) {
Expand All @@ -22,9 +31,11 @@ describe('Confirmation Signature - Personal Sign', function (this: Suite) {
async ({
driver,
ganacheServer,
mockedEndpoint: mockedEndpoints,
}: {
driver: Driver;
ganacheServer: Ganache;
mockedEndpoint: Mockttp;
}) => {
const addresses = await ganacheServer.getAccounts();
const publicAddress = addresses?.[0] as string;
Expand All @@ -34,19 +45,37 @@ describe('Confirmation Signature - Personal Sign', function (this: Suite) {
await driver.clickElement('#personalSign');
await switchToNotificationWindow(driver);

await clickHeaderInfoBtn(driver);
await assertHeaderInfoBalance(driver);

await copyAddressAndPasteWalletAddress(driver);
await assertPastedAddress(driver);
await assertAccountDetailsMetrics(
driver,
mockedEndpoints,
'personal_sign',
);
await switchToNotificationWindow(driver);
await assertInfoValues(driver);

await driver.clickElement('[data-testid="confirm-footer-button"]');

await assertVerifiedPersonalMessage(driver, publicAddress);
await assertSignatureMetrics(driver, mockedEndpoints, 'personal_sign');
},
);
});

it('initiates and rejects', async function () {
await withRedesignConfirmationFixtures(
this.test?.fullTitle(),
async ({ driver }: { driver: Driver }) => {
async ({
driver,
mockedEndpoint: mockedEndpoints,
}: {
driver: Driver;
mockedEndpoint: Mockttp;
}) => {
await unlockWallet(driver);
await openDapp(driver);
await driver.clickElement('#personalSign');
Expand All @@ -64,6 +93,7 @@ describe('Confirmation Signature - Personal Sign', function (this: Suite) {
text: 'Error: User rejected the request.',
});
assert.ok(rejectionResult);
await assertSignatureMetrics(driver, mockedEndpoints, 'personal_sign');
},
);
});
Expand Down
Loading

0 comments on commit 613b7a5

Please sign in to comment.