Skip to content

Commit 9aff235

Browse files
seaonasahar-fehri
andauthored
Multichain debug (#28402)
<!-- 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** List of failing tests: - Malicious Confirmation Signature - Bad Domain @no-mmi displays alert for domain binding and confirms - Malicious Confirmation Signature - Bad Domain @no-mmi initiates and rejects from confirmation screen - Malicious Confirmation Signature - Bad Domain @no-mmi initiates and rejects from alert friction modal - Malicious Confirmation Signature - Bad Domain @no-mmi displays alert for domain binding and confirms - Malicious Confirmation Signature - Bad Domain @no-mmi initiates and rejects from confirmation screen - Malicious Confirmation Signature - Bad Domain @no-mmi initiates and rejects from alert friction modal - smart transactions @no-mmi Completes a Swap - Simple Send Security Alert - Blockaid @no-mmi should not show security alerts for benign requests - Simple Send Security Alert - Blockaid @no-mmi should show security alerts for malicious requests - MultiRpc: should select rpc from modal - MetaMask onboarding @no-mmi doesn't make any network requests to infura before create new wallet onboarding is completed - MetaMask onboarding @no-mmi doesn't make any network requests to infura before onboarding by import is completed - MetaMask onboarding @no-mmi doesn't make any network requests to infura before create new wallet onboarding is completed - MetaMask onboarding @no-mmi doesn't make any network requests to infura before onboarding by import is completed - [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/28402?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** Swaps https://github.com/user-attachments/assets/656ba20a-bc48-4f57-84d4-8b11e62a25cf ENS https://github.com/user-attachments/assets/aa23bb34-aeb0-48e9-af17-c98a82367437 ## **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. --------- Co-authored-by: sahar-fehri <[email protected]>
1 parent a21214b commit 9aff235

File tree

9 files changed

+198
-182
lines changed

9 files changed

+198
-182
lines changed

test/e2e/helpers.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ async function withFixtures(options, testSuite) {
119119
contractRegistry = ganacheSeeder.getContractRegistry();
120120
}
121121

122+
await fixtureServer.start();
123+
fixtureServer.loadJsonState(fixtures, contractRegistry);
124+
122125
if (ganacheOptions?.concurrent) {
123126
ganacheOptions.concurrent.forEach(async (ganacheSettings) => {
124127
const { port, chainId, ganacheOptions2 } = ganacheSettings;
@@ -138,8 +141,6 @@ async function withFixtures(options, testSuite) {
138141
await initBundler(bundlerServer, ganacheServer, usePaymaster);
139142
}
140143

141-
await fixtureServer.start();
142-
fixtureServer.loadJsonState(fixtures, contractRegistry);
143144
await phishingPageServer.start();
144145
if (dapp) {
145146
if (dappOptions?.numberOfDapps) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { MockttpServer } from 'mockttp';
2+
3+
const CONTRACT_ADDRESS = {
4+
BalanceCheckerEthereumMainnet: '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39',
5+
BalanceCheckerLineaMainnet: '0xf62e6a41561b3650a69bb03199c735e3e3328c0d',
6+
};
7+
8+
const infuraUrl: string =
9+
'https://mainnet.infura.io/v3/00000000000000000000000000000000';
10+
const infuraLineaMainnetUrl: string =
11+
'https://linea-mainnet.infura.io/v3/00000000000000000000000000000000';
12+
const infuraLineaSepoliaUrl: string =
13+
'https://linea-sepolia.infura.io/v3/00000000000000000000000000000000';
14+
const infuraSepoliaUrl: string =
15+
'https://sepolia.infura.io/v3/00000000000000000000000000000000';
16+
17+
/**
18+
* Mocks multi network balance polling requests.
19+
*
20+
* @param mockServer - The mock server instance to set up the mocks on.
21+
* @returns A promise that resolves when all mocks have been set up.
22+
*/
23+
export async function mockMultiNetworkBalancePolling(
24+
mockServer: MockttpServer,
25+
): Promise<void> {
26+
await mockServer
27+
.forPost(infuraUrl)
28+
.withJsonBodyIncluding({ method: 'eth_getBalance' })
29+
.thenCallback(() => ({
30+
statusCode: 200,
31+
json: {
32+
jsonrpc: '2.0',
33+
id: '1111111111111111',
34+
result: '0x1158E460913D00000',
35+
},
36+
}));
37+
38+
await mockServer
39+
.forPost(infuraSepoliaUrl)
40+
.withJsonBodyIncluding({ method: 'eth_getBalance' })
41+
.thenCallback(() => ({
42+
statusCode: 200,
43+
json: {
44+
jsonrpc: '2.0',
45+
id: '6183194981233610',
46+
result: '0x1158E460913D00000',
47+
},
48+
}));
49+
50+
await mockServer
51+
.forPost(infuraLineaMainnetUrl)
52+
.withJsonBodyIncluding({ method: 'eth_getBalance' })
53+
.thenCallback(() => ({
54+
statusCode: 200,
55+
json: {
56+
jsonrpc: '2.0',
57+
id: '6183194981233610',
58+
result: '0x1158E460913D00000',
59+
},
60+
}));
61+
62+
await mockServer
63+
.forPost(infuraLineaSepoliaUrl)
64+
.withJsonBodyIncluding({ method: 'eth_getBalance' })
65+
.thenCallback(() => ({
66+
statusCode: 200,
67+
json: {
68+
jsonrpc: '2.0',
69+
id: '6183194981233610',
70+
result: '0x1158E460913D00000',
71+
},
72+
}));
73+
74+
await mockServer
75+
.forPost(infuraUrl)
76+
.withJsonBodyIncluding({ method: 'net_version' })
77+
.thenCallback(() => ({
78+
statusCode: 200,
79+
json: {
80+
jsonrpc: '2.0',
81+
id: '6183194981233610',
82+
result: '0x1',
83+
},
84+
}));
85+
86+
await mockServer
87+
.forPost(infuraLineaMainnetUrl)
88+
.withJsonBodyIncluding({ method: 'eth_call' })
89+
.thenCallback(() => ({
90+
statusCode: 200,
91+
json: {
92+
jsonrpc: '2.0',
93+
id: '1111111111111111',
94+
result:
95+
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000001158E460913D000000000000000000000000000000000000000000000000000000001699651aa88200000000000000000000000000000000000000000000000000001beca58919dc0000000000000000000000000000000000000000000000000000974189179054f0000000000000000000000000000000000000000000000000001d9ae54845818000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110d9316ec0000000000000000000000000000000000000000000000000000000000000000000',
96+
},
97+
}));
98+
99+
await mockServer
100+
.forPost(infuraUrl)
101+
.withJsonBodyIncluding({
102+
method: 'eth_call',
103+
params: [
104+
{
105+
to: CONTRACT_ADDRESS.BalanceCheckerEthereumMainnet,
106+
},
107+
],
108+
})
109+
.thenCallback(() => ({
110+
statusCode: 200,
111+
json: {
112+
jsonrpc: '2.0',
113+
id: '6183194981233610',
114+
result:
115+
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000001158E460913D000000000000000000000000000000000000000000000000000000001699651aa88200000000000000000000000000000000000000000000000000001beca58919dc0000000000000000000000000000000000000000000000000000974189179054f0000000000000000000000000000000000000000000000000001d9ae54845818000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110d9316ec0000000000000000000000000000000000000000000000000000000000000000000',
116+
},
117+
}));
118+
119+
await mockServer
120+
.forGet(
121+
'https://accounts.api.cx.metamask.io/v2/accounts/0x5cfe73b6021e818b776b421b1c4db2474086a7e1/balances',
122+
)
123+
.withQuery({
124+
networks: 1,
125+
})
126+
.thenCallback(() => ({
127+
statusCode: 200,
128+
json: {
129+
count: 0,
130+
balances: [
131+
{
132+
object: 'token',
133+
address: '0x0000000000000000000000000000000000000000',
134+
symbol: 'ETH',
135+
name: 'Ether',
136+
type: 'native',
137+
timestamp: '2015-07-30T03:26:13.000Z',
138+
decimals: 18,
139+
chainId: 1,
140+
balance: '20',
141+
},
142+
],
143+
unprocessedNetworks: [],
144+
},
145+
}));
146+
}

test/e2e/mock-e2e.js

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ const blacklistedHosts = [
4343
'goerli.infura.io',
4444
'mainnet.infura.io',
4545
'sepolia.infura.io',
46+
'linea-mainnet.infura.io',
47+
'linea-sepolia.infura.io',
4648
];
4749
const {
4850
mockEmptyStalelistAndHotlist,

test/e2e/page-objects/flows/login.flow.ts

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export const loginWithoutBalanceValidation = async (
1717
await driver.navigate();
1818
const loginPage = new LoginPage(driver);
1919
await loginPage.check_pageIsLoaded();
20-
await driver.delay(10000);
2120
await loginPage.loginToHomepage(password);
2221
};
2322

test/e2e/tests/ppom/ppom-blockaid-alert-simple-send.spec.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const {
88
logInWithBalanceValidation,
99
WINDOW_TITLES,
1010
} = require('../../helpers');
11+
const {
12+
mockMultiNetworkBalancePolling,
13+
} = require('../../mock-balance-polling/mock-balance-polling');
1114
const { SECURITY_ALERTS_PROD_API_BASE_URL } = require('./constants');
1215
const { mockServerJsonRpc } = require('./mocks/mock-server-json-rpc');
1316

@@ -32,13 +35,13 @@ const SEND_REQUEST_BASE_MOCK = {
3235
};
3336

3437
async function mockInfura(mockServer) {
38+
await mockMultiNetworkBalancePolling(mockServer);
3539
await mockServerJsonRpc(mockServer, [
3640
['eth_blockNumber'],
3741
['eth_call'],
3842
['eth_estimateGas'],
3943
['eth_feeHistory'],
4044
['eth_gasPrice'],
41-
['eth_getBalance'],
4245
['eth_getBlockByNumber'],
4346
['eth_getCode'],
4447
['eth_getTransactionCount'],

0 commit comments

Comments
 (0)