Skip to content

Commit b180b6a

Browse files
committed
Adds blockaid multiple network support test
1 parent 3e166b7 commit b180b6a

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: transfer_farming\n`,
96+
);
97+
assert(
98+
bannerAlertText.includes(expectedDescriptionMainnet),
99+
`Unexpected banner alert description. Expected: ${expectedDescriptionMainnet} \nExpected reason: transfer_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: transfer_farming\n`,
143+
);
144+
assert(
145+
bannerAlertText.includes(expectedDescriptionArbitrum),
146+
`Unexpected banner alert description. Expected: ${expectedDescriptionArbitrum} \nExpected reason: transfer_farming\n`,
147+
);
148+
},
149+
);
150+
});
151+
});

0 commit comments

Comments
 (0)