Skip to content

Commit ed44d49

Browse files
refactor: Use generic helper function to initiate signatures (MetaMask#26584)
## **Description** Refactor signature tests to use a helper function in order to load the test state. Also fixes the flaky SIWE tests by adding an extra scroll to bottom [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/26584?quickstart=1) ## **Related issues** Fixes: [MetaMask#24468](MetaMask#24468) [MetaMask#26445](MetaMask#26445) ## **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.
1 parent 41736f0 commit ed44d49

File tree

7 files changed

+64
-69
lines changed

7 files changed

+64
-69
lines changed

test/e2e/tests/confirmations/signatures/permit.spec.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import {
2121
assertSignatureMetrics,
2222
clickHeaderInfoBtn,
2323
copyAddressAndPasteWalletAddress,
24+
openDappAndTriggerSignature,
25+
SignatureType,
2426
} from './signature-helpers';
2527

2628
describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) {
@@ -35,10 +37,7 @@ describe('Confirmation Signature - Permit @no-mmi', function (this: Suite) {
3537
const addresses = await (ganacheServer as Ganache).getAccounts();
3638
const publicAddress = addresses?.[0] as string;
3739

38-
await unlockWallet(driver);
39-
await openDapp(driver);
40-
await driver.clickElement('#signPermit');
41-
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
40+
await openDappAndTriggerSignature(driver, SignatureType.Permit);
4241

4342
await clickHeaderInfoBtn(driver);
4443
await assertHeaderInfoBalance(driver);

test/e2e/tests/confirmations/signatures/personal-sign.spec.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp';
44
import {
55
DAPP_HOST_ADDRESS,
66
WINDOW_TITLES,
7-
openDapp,
87
switchToNotificationWindow,
9-
unlockWallet,
108
} from '../../../helpers';
119
import { Ganache } from '../../../seeder/ganache';
1210
import { Driver } from '../../../webdriver/driver';
@@ -19,6 +17,8 @@ import {
1917
assertSignatureMetrics,
2018
clickHeaderInfoBtn,
2119
copyAddressAndPasteWalletAddress,
20+
openDappAndTriggerSignature,
21+
SignatureType,
2222
} from './signature-helpers';
2323

2424
describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite) {
@@ -33,10 +33,7 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite
3333
const addresses = await (ganacheServer as Ganache).getAccounts();
3434
const publicAddress = addresses?.[0] as string;
3535

36-
await unlockWallet(driver);
37-
await openDapp(driver);
38-
await driver.clickElement('#personalSign');
39-
await switchToNotificationWindow(driver);
36+
await openDappAndTriggerSignature(driver, SignatureType.PersonalSign);
4037

4138
await clickHeaderInfoBtn(driver);
4239
await assertHeaderInfoBalance(driver);
@@ -70,10 +67,7 @@ describe('Confirmation Signature - Personal Sign @no-mmi', function (this: Suite
7067
driver,
7168
mockedEndpoint: mockedEndpoints,
7269
}: TestSuiteArguments) => {
73-
await unlockWallet(driver);
74-
await openDapp(driver);
75-
await driver.clickElement('#personalSign');
76-
await switchToNotificationWindow(driver);
70+
await openDappAndTriggerSignature(driver, SignatureType.PersonalSign);
7771

7872
await driver.clickElement(
7973
'[data-testid="confirm-footer-cancel-button"]',

test/e2e/tests/confirmations/signatures/sign-typed-data-v3.spec.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp';
44
import {
55
DAPP_HOST_ADDRESS,
66
WINDOW_TITLES,
7-
openDapp,
87
switchToNotificationWindow,
9-
unlockWallet,
108
} from '../../../helpers';
119
import { Ganache } from '../../../seeder/ganache';
1210
import { Driver } from '../../../webdriver/driver';
@@ -22,6 +20,8 @@ import {
2220
assertSignatureMetrics,
2321
clickHeaderInfoBtn,
2422
copyAddressAndPasteWalletAddress,
23+
openDappAndTriggerSignature,
24+
SignatureType,
2525
} from './signature-helpers';
2626

2727
describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this: Suite) {
@@ -36,10 +36,10 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this:
3636
const addresses = await (ganacheServer as Ganache).getAccounts();
3737
const publicAddress = addresses?.[0] as string;
3838

39-
await unlockWallet(driver);
40-
await openDapp(driver);
41-
await driver.clickElement('#signTypedDataV3');
42-
await switchToNotificationWindow(driver);
39+
await openDappAndTriggerSignature(
40+
driver,
41+
SignatureType.SignTypedDataV3,
42+
);
4343

4444
await clickHeaderInfoBtn(driver);
4545
await assertHeaderInfoBalance(driver);
@@ -73,10 +73,10 @@ describe('Confirmation Signature - Sign Typed Data V3 @no-mmi', function (this:
7373
driver,
7474
mockedEndpoint: mockedEndpoints,
7575
}: TestSuiteArguments) => {
76-
await unlockWallet(driver);
77-
await openDapp(driver);
78-
await driver.clickElement('#signTypedDataV3');
79-
await switchToNotificationWindow(driver);
76+
await openDappAndTriggerSignature(
77+
driver,
78+
SignatureType.SignTypedDataV3,
79+
);
8080

8181
await driver.clickElement(
8282
'[data-testid="confirm-footer-cancel-button"]',

test/e2e/tests/confirmations/signatures/sign-typed-data-v4.spec.ts

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { strict as assert } from 'assert';
22
import { Suite } from 'mocha';
33
import { MockedEndpoint } from 'mockttp';
4-
import {
5-
DAPP_HOST_ADDRESS,
6-
WINDOW_TITLES,
7-
openDapp,
8-
switchToNotificationWindow,
9-
unlockWallet,
10-
} from '../../../helpers';
4+
import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers';
115
import { Ganache } from '../../../seeder/ganache';
126
import { Driver } from '../../../webdriver/driver';
137
import {
@@ -22,6 +16,8 @@ import {
2216
assertSignatureMetrics,
2317
clickHeaderInfoBtn,
2418
copyAddressAndPasteWalletAddress,
19+
openDappAndTriggerSignature,
20+
SignatureType,
2521
} from './signature-helpers';
2622

2723
describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this: Suite) {
@@ -36,10 +32,10 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this:
3632
const addresses = await (ganacheServer as Ganache).getAccounts();
3733
const publicAddress = addresses?.[0] as string;
3834

39-
await unlockWallet(driver);
40-
await openDapp(driver);
41-
await driver.clickElement('#signTypedDataV4');
42-
await switchToNotificationWindow(driver);
35+
await openDappAndTriggerSignature(
36+
driver,
37+
SignatureType.SignTypedDataV4,
38+
);
4339

4440
await clickHeaderInfoBtn(driver);
4541
await assertHeaderInfoBalance(driver);
@@ -74,10 +70,10 @@ describe('Confirmation Signature - Sign Typed Data V4 @no-mmi', function (this:
7470
driver,
7571
mockedEndpoint: mockedEndpoints,
7672
}: TestSuiteArguments) => {
77-
await unlockWallet(driver);
78-
await openDapp(driver);
79-
await driver.clickElement('#signTypedDataV4');
80-
await switchToNotificationWindow(driver);
73+
await openDappAndTriggerSignature(
74+
driver,
75+
SignatureType.SignTypedDataV4,
76+
);
8177

8278
await driver.clickElement(
8379
'[data-testid="confirm-footer-cancel-button"]',

test/e2e/tests/confirmations/signatures/sign-typed-data.spec.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { strict as assert } from 'assert';
22
import { Suite } from 'mocha';
33
import { MockedEndpoint } from 'mockttp';
4-
import {
5-
DAPP_HOST_ADDRESS,
6-
WINDOW_TITLES,
7-
openDapp,
8-
switchToNotificationWindow,
9-
unlockWallet,
10-
} from '../../../helpers';
4+
import { DAPP_HOST_ADDRESS, WINDOW_TITLES } from '../../../helpers';
115
import { Ganache } from '../../../seeder/ganache';
126
import { Driver } from '../../../webdriver/driver';
137
import { withRedesignConfirmationFixtures } from '../helpers';
@@ -19,6 +13,8 @@ import {
1913
assertSignatureMetrics,
2014
clickHeaderInfoBtn,
2115
copyAddressAndPasteWalletAddress,
16+
openDappAndTriggerSignature,
17+
SignatureType,
2218
} from './signature-helpers';
2319

2420
describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Suite) {
@@ -33,10 +29,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui
3329
const addresses = await (ganacheServer as Ganache).getAccounts();
3430
const publicAddress = addresses?.[0] as string;
3531

36-
await unlockWallet(driver);
37-
await openDapp(driver);
38-
await driver.clickElement('#signTypedData');
39-
await switchToNotificationWindow(driver);
32+
await openDappAndTriggerSignature(driver, SignatureType.SignTypedData);
4033

4134
await clickHeaderInfoBtn(driver);
4235
await assertHeaderInfoBalance(driver);
@@ -72,10 +65,7 @@ describe('Confirmation Signature - Sign Typed Data @no-mmi', function (this: Sui
7265
driver,
7366
mockedEndpoint: mockedEndpoints,
7467
}: TestSuiteArguments) => {
75-
await unlockWallet(driver);
76-
await openDapp(driver);
77-
await driver.clickElement('#signTypedData');
78-
await switchToNotificationWindow(driver);
68+
await openDappAndTriggerSignature(driver, SignatureType.SignTypedData);
7969

8070
await driver.clickElement(
8171
'[data-testid="confirm-footer-cancel-button"]',

test/e2e/tests/confirmations/signatures/signature-helpers.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
11
import { strict as assert } from 'assert';
22
import { MockedEndpoint } from 'mockttp';
3-
import { WINDOW_TITLES, getEventPayloads } from '../../../helpers';
3+
import {
4+
WINDOW_TITLES,
5+
getEventPayloads,
6+
openDapp,
7+
unlockWallet,
8+
} from '../../../helpers';
49
import { Driver } from '../../../webdriver/driver';
510

611
export const WALLET_ADDRESS = '0x5CfE73b6021E818B776b421B1c4Db2474086a7e1';
712
export const WALLET_ETH_BALANCE = '25';
13+
export enum SignatureType {
14+
PersonalSign = '#personalSign',
15+
Permit = '#signPermit',
16+
SignTypedDataV3 = '#signTypedDataV3',
17+
SignTypedDataV4 = '#signTypedDataV4',
18+
SignTypedData = '#signTypedData',
19+
SIWE = '#siwe',
20+
SIWE_BadDomain = '#siweBadDomain',
21+
}
822

923
export async function assertSignatureMetrics(
1024
driver: Driver,
@@ -99,3 +113,13 @@ export async function assertPastedAddress(driver: Driver) {
99113
const formFieldEl = await driver.findElement('#eip747ContractAddress');
100114
assert.equal(await formFieldEl.getAttribute('value'), WALLET_ADDRESS);
101115
}
116+
117+
export async function openDappAndTriggerSignature(
118+
driver: Driver,
119+
type: string,
120+
) {
121+
await unlockWallet(driver);
122+
await openDapp(driver);
123+
await driver.clickElement(type);
124+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
125+
}

test/e2e/tests/confirmations/signatures/siwe.spec.ts

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import { MockedEndpoint } from 'mockttp';
44
import {
55
DAPP_HOST_ADDRESS,
66
WINDOW_TITLES,
7-
openDapp,
87
switchToNotificationWindow,
9-
unlockWallet,
108
} from '../../../helpers';
119
import { Driver } from '../../../webdriver/driver';
1210
import {
@@ -21,6 +19,8 @@ import {
2119
assertSignatureMetrics,
2220
clickHeaderInfoBtn,
2321
copyAddressAndPasteWalletAddress,
22+
openDappAndTriggerSignature,
23+
SignatureType,
2424
} from './signature-helpers';
2525

2626
describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {
@@ -31,10 +31,7 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {
3131
driver,
3232
mockedEndpoint: mockedEndpoints,
3333
}: TestSuiteArguments) => {
34-
await unlockWallet(driver);
35-
await openDapp(driver);
36-
await driver.clickElement('#siwe');
37-
await switchToNotificationWindow(driver);
34+
await openDappAndTriggerSignature(driver, SignatureType.SIWE);
3835

3936
await clickHeaderInfoBtn(driver);
4037
await assertHeaderInfoBalance(driver);
@@ -73,10 +70,7 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {
7370
driver,
7471
mockedEndpoint: mockedEndpoints,
7572
}: TestSuiteArguments) => {
76-
await unlockWallet(driver);
77-
await openDapp(driver);
78-
await driver.clickElement('#siwe');
79-
await switchToNotificationWindow(driver);
73+
await openDappAndTriggerSignature(driver, SignatureType.SIWE);
8074

8175
await driver.clickElement(
8276
'[data-testid="confirm-footer-cancel-button"]',
@@ -105,11 +99,9 @@ describe('Confirmation Signature - SIWE @no-mmi', function (this: Suite) {
10599
await withRedesignConfirmationFixtures(
106100
this.test?.fullTitle(),
107101
async ({ driver }: TestSuiteArguments) => {
108-
await unlockWallet(driver);
109-
await openDapp(driver);
110-
await driver.clickElement('#siweBadDomain');
111-
await switchToNotificationWindow(driver);
102+
await openDappAndTriggerSignature(driver, SignatureType.SIWE_BadDomain);
112103

104+
await driver.clickElementSafe('.confirm-scroll-to-bottom__button');
113105
const alert = await driver.findElement('[data-testid="inline-alert"]');
114106
assert.equal(await alert.getText(), 'Alert');
115107
await driver.clickElement('[data-testid="inline-alert"]');

0 commit comments

Comments
 (0)