Skip to content

Commit a6a91d5

Browse files
jiexiadonesky1Gudahtt
authored
test: Cleanup snap-account-signature e2e tests. Add permittedChains scenario to wallet_revokePermissions e2e test (#29761)
<!-- 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** * Fix incorrect snap-account-signature e2e test fixtures / starting state (accounts permissioned before they exist in the wallet) * Add `endowment:permitted-chains` scenario to `wallet_revokePermissions` e2e test [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29761?quickstart=1) ## **Related issues** See: #27847 ## **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/main/.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/main/.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. --------- Co-authored-by: Alex Donesky <[email protected]> Co-authored-by: Mark Stacey <[email protected]>
1 parent f503a48 commit a6a91d5

File tree

4 files changed

+138
-21
lines changed

4 files changed

+138
-21
lines changed

test/e2e/fixture-builder.js

+36
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,42 @@ class FixtureBuilder {
494494
});
495495
}
496496

497+
withPermissionControllerConnectedToTestDappWithChain() {
498+
return this.withPermissionController({
499+
subjects: {
500+
[DAPP_URL]: {
501+
origin: DAPP_URL,
502+
permissions: {
503+
eth_accounts: {
504+
id: 'ZaqPEWxyhNCJYACFw93jE',
505+
parentCapability: 'eth_accounts',
506+
invoker: DAPP_URL,
507+
caveats: [
508+
{
509+
type: 'restrictReturnedAccounts',
510+
value: [DEFAULT_FIXTURE_ACCOUNT.toLowerCase()],
511+
},
512+
],
513+
date: 1664388714636,
514+
},
515+
'endowment:permitted-chains': {
516+
id: 'D7cac0a2e3BD8f349506a',
517+
parentCapability: 'endowment:permitted-chains',
518+
invoker: DAPP_URL,
519+
caveats: [
520+
{
521+
type: 'restrictNetworkSwitching',
522+
value: ['0x539'],
523+
},
524+
],
525+
date: 1664388714637,
526+
},
527+
},
528+
},
529+
},
530+
});
531+
}
532+
497533
withPermissionControllerConnectedToTestDappWithTwoAccounts() {
498534
const subjects = {
499535
[DAPP_URL]: {

test/e2e/json-rpc/wallet_revokePermissions.spec.ts

+91-9
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,40 @@
11
import { strict as assert } from 'assert';
2-
import { ACCOUNT_1, withFixtures } from '../helpers';
2+
import { PermissionConstraint } from '@metamask/permission-controller';
3+
import { withFixtures } from '../helpers';
34
import FixtureBuilder from '../fixture-builder';
45
import TestDapp from '../page-objects/pages/test-dapp';
56
import { loginWithBalanceValidation } from '../page-objects/flows/login.flow';
67

78
describe('Revoke Dapp Permissions', function () {
8-
it('should revoke dapp permissions ', async function () {
9+
it('should revoke dapp permissions for "eth_accounts"', async function () {
910
await withFixtures(
1011
{
1112
dapp: true,
1213
fixtures: new FixtureBuilder()
13-
.withPermissionControllerConnectedToTestDapp()
14+
.withPermissionControllerConnectedToTestDappWithChain()
1415
.build(),
1516
title: this.test?.fullTitle(),
1617
},
1718
async ({ driver }) => {
1819
await loginWithBalanceValidation(driver);
1920
const testDapp = new TestDapp(driver);
2021
await testDapp.openTestDappPage();
21-
await testDapp.check_connectedAccounts(ACCOUNT_1);
2222

23-
// wallet_revokePermissions request
23+
const beforeGetPermissionsRequest = JSON.stringify({
24+
jsonrpc: '2.0',
25+
method: 'wallet_getPermissions',
26+
});
27+
const beforeGetPermissionsResult = await driver.executeScript(
28+
`return window.ethereum.request(${beforeGetPermissionsRequest})`,
29+
);
30+
const beforeGetPermissionsNames = beforeGetPermissionsResult.map(
31+
(permission: PermissionConstraint) => permission.parentCapability,
32+
);
33+
assert.deepEqual(beforeGetPermissionsNames, [
34+
'eth_accounts',
35+
'endowment:permitted-chains',
36+
]);
37+
2438
const revokePermissionsRequest = JSON.stringify({
2539
jsonrpc: '2.0',
2640
method: 'wallet_revokePermissions',
@@ -30,14 +44,82 @@ describe('Revoke Dapp Permissions', function () {
3044
},
3145
],
3246
});
47+
const revokePermissionsResult = await driver.executeScript(
48+
`return window.ethereum.request(${revokePermissionsRequest})`,
49+
);
50+
assert.deepEqual(revokePermissionsResult, null);
51+
52+
const afterGetPermissionsRequest = JSON.stringify({
53+
jsonrpc: '2.0',
54+
method: 'wallet_getPermissions',
55+
});
56+
const afterGetPermissionsResult = await driver.executeScript(
57+
`return window.ethereum.request(${afterGetPermissionsRequest})`,
58+
);
59+
const afterGetPermissionsNames = afterGetPermissionsResult.map(
60+
(permission: PermissionConstraint) => permission.parentCapability,
61+
);
62+
assert.deepEqual(afterGetPermissionsNames, [
63+
'endowment:permitted-chains',
64+
]);
65+
},
66+
);
67+
});
68+
69+
it('should revoke dapp permissions for "endowment:permitted-chains"', async function () {
70+
await withFixtures(
71+
{
72+
dapp: true,
73+
fixtures: new FixtureBuilder()
74+
.withPermissionControllerConnectedToTestDappWithChain()
75+
.build(),
76+
title: this.test?.fullTitle(),
77+
},
78+
async ({ driver }) => {
79+
await loginWithBalanceValidation(driver);
80+
const testDapp = new TestDapp(driver);
81+
await testDapp.openTestDappPage();
82+
83+
const beforeGetPermissionsRequest = JSON.stringify({
84+
jsonrpc: '2.0',
85+
method: 'wallet_getPermissions',
86+
});
87+
const beforeGetPermissionsResult = await driver.executeScript(
88+
`return window.ethereum.request(${beforeGetPermissionsRequest})`,
89+
);
90+
const beforeGetPermissionsNames = beforeGetPermissionsResult.map(
91+
(permission: PermissionConstraint) => permission.parentCapability,
92+
);
93+
assert.deepEqual(beforeGetPermissionsNames, [
94+
'eth_accounts',
95+
'endowment:permitted-chains',
96+
]);
3397

34-
const result = await driver.executeScript(
98+
const revokePermissionsRequest = JSON.stringify({
99+
jsonrpc: '2.0',
100+
method: 'wallet_revokePermissions',
101+
params: [
102+
{
103+
'endowment:permitted-chains': {},
104+
},
105+
],
106+
});
107+
const revokePermissionsResult = await driver.executeScript(
35108
`return window.ethereum.request(${revokePermissionsRequest})`,
36109
);
37-
// Response of method call
38-
assert.deepEqual(result, null);
110+
assert.deepEqual(revokePermissionsResult, null);
39111

40-
await testDapp.check_connectedAccounts(ACCOUNT_1, false);
112+
const afterGetPermissionsRequest = JSON.stringify({
113+
jsonrpc: '2.0',
114+
method: 'wallet_getPermissions',
115+
});
116+
const afterGetPermissionsResult = await driver.executeScript(
117+
`return window.ethereum.request(${afterGetPermissionsRequest})`,
118+
);
119+
const afterGetPermissionsNames = afterGetPermissionsResult.map(
120+
(permission: PermissionConstraint) => permission.parentCapability,
121+
);
122+
assert.deepEqual(afterGetPermissionsNames, ['eth_accounts']);
41123
},
42124
);
43125
});

test/e2e/tests/account/snap-account-signatures-and-disconnects.spec.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ describe('Snap Account Signatures and Disconnects @no-mmi', function (this: Suit
1919
await withFixtures(
2020
{
2121
dapp: true,
22-
fixtures: new FixtureBuilder()
23-
.withPermissionControllerConnectedToTestDapp({
24-
restrictReturnedAccounts: false,
25-
})
26-
.build(),
22+
fixtures: new FixtureBuilder().build(),
2723
title: this.test?.fullTitle(),
2824
},
2925
async ({ driver }: { driver: Driver }) => {
@@ -49,9 +45,12 @@ describe('Snap Account Signatures and Disconnects @no-mmi', function (this: Suit
4945
await experimentalSettings.check_pageIsLoaded();
5046
await experimentalSettings.toggleRedesignedSignature();
5147

52-
// Open the Test Dapp and signTypedDataV3
48+
// Open the Test Dapp and connect
5349
const testDapp = new TestDapp(driver);
5450
await testDapp.openTestDappPage();
51+
await testDapp.connectAccount({ publicAddress: newPublicKey });
52+
53+
// SignedTypedDataV3 with Test Dapp
5554
await signTypedDataV3WithSnapAccount(driver, newPublicKey, false, true);
5655

5756
// Disconnect from Test Dapp and reconnect to Test Dapp

test/e2e/tests/account/snap-account-signatures.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ describe('Snap Account Signatures @no-mmi', function (this: Suite) {
3030
await withFixtures(
3131
{
3232
dapp: true,
33-
fixtures: new FixtureBuilder()
34-
.withPermissionControllerConnectedToTestDapp({
35-
restrictReturnedAccounts: false,
36-
})
37-
.build(),
33+
fixtures: new FixtureBuilder().build(),
3834
title,
3935
},
4036
async ({ driver }: { driver: Driver }) => {
@@ -62,8 +58,12 @@ describe('Snap Account Signatures @no-mmi', function (this: Suite) {
6258
await experimentalSettings.check_pageIsLoaded();
6359
await experimentalSettings.toggleRedesignedSignature();
6460

61+
// Connect the SSK account
62+
const testDapp = new TestDapp(driver);
63+
await testDapp.openTestDappPage();
64+
await testDapp.connectAccount({ publicAddress: newPublicKey });
65+
6566
// Run all 5 signature types
66-
await new TestDapp(driver).openTestDappPage();
6767
await personalSignWithSnapAccount(
6868
driver,
6969
newPublicKey,

0 commit comments

Comments
 (0)