Skip to content

Commit 4632dcd

Browse files
authored
test: adds blockaid multiple network support test (#22691)
## **Description** This PR adds an e2e spec for testing Blockaid support to multiple networks. This verifies that: - We initially display the malicious warning for Mainnet - We switch to another supported network and we continue to display the malicious warning (in this case Arbitrum) ## **Related issues** Fixes: MetaMask/MetaMask-planning#993 ## **Manual testing steps** 1. Check circle ci job 2. Alternatively, run the test locally `yarn test:e2e:single test/e2e/tests/ppom-blockaid-alert-networks-support.spec.js --browser=chrome` ## **Screenshots/Recordings** ![Screenshot from 2024-01-29 11-43-34](https://github.com/MetaMask/metamask-extension/assets/54408225/589c302c-4be4-44f0-b5d0-df57ac814951) ## **Pre-merge author checklist** - [x] I’ve followed [MetaMask Coding Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md). - [x] I've clearly explained what problem this PR is solving and how it is solved. - [x] I've linked related issues - [x] I've included manual testing steps - [x] I've included screenshots/recordings if applicable - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] 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. - [x] I’ve properly set the pull request status: - [ ] In case it's not yet "ready for review", I've set it to "draft". - [ ] In case it's "ready for review", I've changed it from "draft" to "non-draft". ## **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 c45acd7 commit 4632dcd

File tree

2 files changed

+154
-0
lines changed

2 files changed

+154
-0
lines changed

test/e2e/mock-e2e.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ async function setupMocking(server, testSpecificMock, { chainId }) {
102102
.forPost(
103103
'https://arbitrum-mainnet.infura.io/v3/00000000000000000000000000000000',
104104
)
105+
.withJsonBodyIncluding({
106+
method: 'eth_chainId',
107+
})
105108
.thenCallback(() => {
106109
return {
107110
statusCode: 200,
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
const { strict: assert } = require('assert');
2+
const FixtureBuilder = require('../fixture-builder');
3+
const { mockServerJsonRpc } = require('../mock-server-json-rpc');
4+
const {
5+
WINDOW_TITLES,
6+
defaultGanacheOptions,
7+
openDapp,
8+
unlockWallet,
9+
withFixtures,
10+
} = require('../helpers');
11+
12+
async function mockInfura(mockServer) {
13+
await mockServerJsonRpc(mockServer, [
14+
['eth_blockNumber'],
15+
['eth_call'],
16+
['eth_estimateGas'],
17+
['eth_feeHistory'],
18+
['eth_gasPrice'],
19+
['eth_getBalance'],
20+
['eth_getBlockByNumber'],
21+
['eth_getCode'],
22+
['eth_getTransactionCount'],
23+
]);
24+
}
25+
26+
async function mockInfuraWithMaliciousResponses(mockServer) {
27+
await mockInfura(mockServer);
28+
await mockServer
29+
.forPost()
30+
.withJsonBodyIncluding({
31+
method: 'debug_traceCall',
32+
params: [{ accessList: [], data: '0x00000000' }],
33+
})
34+
.thenCallback(async (req) => {
35+
return {
36+
statusCode: 200,
37+
json: {
38+
jsonrpc: '2.0',
39+
id: (await req.body.getJson()).id,
40+
error: {
41+
message:
42+
'The method debug_traceCall does not exist/is not available',
43+
},
44+
},
45+
};
46+
});
47+
}
48+
49+
describe('PPOM Blockaid Alert - Multiple Networks Support @no-mmi', function () {
50+
it('should show banner alert after switchinig to another supported network', async function () {
51+
await withFixtures(
52+
{
53+
dapp: true,
54+
fixtures: new FixtureBuilder()
55+
.withNetworkControllerOnMainnet()
56+
.withPermissionControllerConnectedToTestDapp()
57+
.withPreferencesController({
58+
securityAlertsEnabled: true,
59+
})
60+
.build(),
61+
defaultGanacheOptions,
62+
testSpecificMock: mockInfuraWithMaliciousResponses,
63+
title: this.test.fullTitle(),
64+
},
65+
66+
async ({ driver }) => {
67+
const expectedTitle = 'This is a deceptive request';
68+
const expectedDescriptionMainnet =
69+
'If you approve this request, you might lose your assets.';
70+
71+
const expectedDescriptionArbitrum =
72+
'If you approve this request, a third party known for scams will take all your assets.';
73+
74+
await unlockWallet(driver);
75+
await openDapp(driver);
76+
77+
// Click TestDapp button to send JSON-RPC request
78+
await driver.clickElement('#maliciousTradeOrder');
79+
80+
// Wait for confirmation pop-up
81+
await driver.waitUntilXWindowHandles(3);
82+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
83+
84+
const bannerAlertSelector =
85+
'[data-testid="security-provider-banner-alert"]';
86+
87+
let bannerAlertFoundByTitle = await driver.findElement({
88+
css: bannerAlertSelector,
89+
text: expectedTitle,
90+
});
91+
let bannerAlertText = await bannerAlertFoundByTitle.getText();
92+
93+
assert(
94+
bannerAlertFoundByTitle,
95+
`Banner alert not found. Expected Title: ${expectedTitle} \nExpected reason: approval_farming\n`,
96+
);
97+
assert(
98+
bannerAlertText.includes(expectedDescriptionMainnet),
99+
`Unexpected banner alert description. Expected: ${expectedDescriptionMainnet} \nExpected reason: approval_farming\n`,
100+
);
101+
102+
await driver.clickElement({ text: 'Reject', tag: 'button' });
103+
await driver.waitUntilXWindowHandles(2);
104+
await driver.switchToWindowWithTitle(
105+
WINDOW_TITLES.ExtensionInFullScreenView,
106+
);
107+
108+
// switch network to arbitrum
109+
await driver.clickElement('[data-testid="network-display"]');
110+
111+
await driver.clickElement({ tag: 'button', text: 'Add network' });
112+
await driver.clickElement({
113+
tag: 'button',
114+
text: 'Add',
115+
});
116+
117+
await driver.clickElement({ tag: 'a', text: 'View all details' });
118+
119+
await driver.clickElement({ tag: 'button', text: 'Close' });
120+
await driver.clickElement({ tag: 'button', text: 'Approve' });
121+
await driver.clickElement({
122+
tag: 'h6',
123+
text: 'Switch to Arbitrum One',
124+
});
125+
126+
await driver.switchToWindowWithTitle(WINDOW_TITLES.TestDApp);
127+
// Click TestDapp button to send JSON-RPC request
128+
await driver.clickElement('#maliciousRawEthButton');
129+
130+
// Wait for confirmation pop-up
131+
await driver.waitUntilXWindowHandles(3);
132+
await driver.switchToWindowWithTitle(WINDOW_TITLES.Dialog);
133+
134+
bannerAlertFoundByTitle = await driver.findElement({
135+
css: bannerAlertSelector,
136+
text: expectedTitle,
137+
});
138+
bannerAlertText = await bannerAlertFoundByTitle.getText();
139+
140+
assert(
141+
bannerAlertFoundByTitle,
142+
`Banner alert not found. Expected Title: ${expectedTitle} \nExpected reason: raw_native_token_transfer\n`,
143+
);
144+
assert(
145+
bannerAlertText.includes(expectedDescriptionArbitrum),
146+
`Unexpected banner alert description. Expected: ${expectedDescriptionArbitrum} \nExpected reason: raw_native_token_transfer\n`,
147+
);
148+
},
149+
);
150+
});
151+
});

0 commit comments

Comments
 (0)