-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multichain debug #28402
Multichain debug #28402
Changes from 13 commits
4d1cbfa
32ac47b
fcd2f22
616a971
fb4520d
621c92e
4962917
8a71134
a1ec7fe
a3e6510
00dcfee
911288c
1a254c3
2de5b84
30ba00e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import { MockttpServer } from 'mockttp'; | ||
|
||
const CONTRACT_ADDRESS = { | ||
BalanceCheckerEthereumMainnet: '0xb1f8e55c7f64d203c1400b9d8555d050f94adf39', | ||
BalanceCheckerLineaMainnet: '0xf62e6a41561b3650a69bb03199c735e3e3328c0d', | ||
}; | ||
|
||
const infuraUrl: string = | ||
'https://mainnet.infura.io/v3/00000000000000000000000000000000'; | ||
const infuraLineaMainnetUrl: string = | ||
'https://linea-mainnet.infura.io/v3/00000000000000000000000000000000'; | ||
const infuraLineaSepoliaUrl: string = | ||
'https://linea-sepolia.infura.io/v3/00000000000000000000000000000000'; | ||
const infuraSepoliaUrl: string = | ||
'https://sepolia.infura.io/v3/00000000000000000000000000000000'; | ||
|
||
/** | ||
* Mocks multi network balance polling requests. | ||
* | ||
* @param mockServer - The mock server instance to set up the mocks on. | ||
* @returns A promise that resolves when all mocks have been set up. | ||
*/ | ||
export async function mockMultiNetworkBalancePolling( | ||
mockServer: MockttpServer, | ||
): Promise<void> { | ||
await mockServer | ||
.forPost(infuraUrl) | ||
.withJsonBodyIncluding({ method: 'eth_getBalance' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '1111111111111111', | ||
result: '0x1158E460913D00000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraSepoliaUrl) | ||
.withJsonBodyIncluding({ method: 'eth_getBalance' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '6183194981233610', | ||
result: '0x1158E460913D00000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraLineaMainnetUrl) | ||
.withJsonBodyIncluding({ method: 'eth_getBalance' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '6183194981233610', | ||
result: '0x1158E460913D00000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraLineaSepoliaUrl) | ||
.withJsonBodyIncluding({ method: 'eth_getBalance' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '6183194981233610', | ||
result: '0x1158E460913D00000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraUrl) | ||
.withJsonBodyIncluding({ method: 'net_version' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '6183194981233610', | ||
result: '0x1', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraLineaMainnetUrl) | ||
.withJsonBodyIncluding({ method: 'eth_call' }) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '1111111111111111', | ||
result: | ||
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000001158E460913D000000000000000000000000000000000000000000000000000000001699651aa88200000000000000000000000000000000000000000000000000001beca58919dc0000000000000000000000000000000000000000000000000000974189179054f0000000000000000000000000000000000000000000000000001d9ae54845818000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110d9316ec0000000000000000000000000000000000000000000000000000000000000000000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forPost(infuraUrl) | ||
.withJsonBodyIncluding({ | ||
method: 'eth_call', | ||
params: [ | ||
{ | ||
to: CONTRACT_ADDRESS.BalanceCheckerEthereumMainnet, | ||
}, | ||
], | ||
}) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
jsonrpc: '2.0', | ||
id: '6183194981233610', | ||
result: | ||
'0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000001158E460913D000000000000000000000000000000000000000000000000000000001699651aa88200000000000000000000000000000000000000000000000000001beca58919dc0000000000000000000000000000000000000000000000000000974189179054f0000000000000000000000000000000000000000000000000001d9ae54845818000000000000000000000000000000000000000000000000000009184e72a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110d9316ec0000000000000000000000000000000000000000000000000000000000000000000', | ||
}, | ||
})); | ||
|
||
await mockServer | ||
.forGet( | ||
'https://accounts.api.cx.metamask.io/v2/accounts/0x5cfe73b6021e818b776b421b1c4db2474086a7e1/balances', | ||
) | ||
.withQuery({ | ||
networks: 1, | ||
}) | ||
.thenCallback(() => ({ | ||
statusCode: 200, | ||
json: { | ||
count: 0, | ||
balances: [ | ||
{ | ||
object: 'token', | ||
address: '0x0000000000000000000000000000000000000000', | ||
symbol: 'ETH', | ||
name: 'Ether', | ||
type: 'native', | ||
timestamp: '2015-07-30T03:26:13.000Z', | ||
decimals: 18, | ||
chainId: 1, | ||
balance: '20', | ||
}, | ||
], | ||
unprocessedNetworks: [], | ||
}, | ||
})); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { MockttpServer } from 'mockttp'; | ||
import { mockEthDaiTrade } from '../swaps/shared'; | ||
import { mockMultiNetworkBalancePolling } from '../../mock-balance-polling/mock-balance-polling'; | ||
import { mockServerJsonRpc } from '../ppom/mocks/mock-server-json-rpc'; | ||
|
||
const STX_UUID = '0d506aaa-5e38-4cab-ad09-2039cb7a0f33'; | ||
|
||
|
@@ -288,18 +290,14 @@ const GET_TRANSACTION_BY_HASH_RESPONSE = { | |
}; | ||
|
||
export const mockSwapRequests = async (mockServer: MockttpServer) => { | ||
await mockEthDaiTrade(mockServer); | ||
await mockMultiNetworkBalancePolling(mockServer); | ||
|
||
await mockServer | ||
.forJsonRpcRequest({ | ||
method: 'eth_getBalance', | ||
params: ['0x5cfe73b6021e818b776b421b1c4db2474086a7e1'], | ||
}) | ||
.thenJson(200, { | ||
id: 3806592044086814, | ||
jsonrpc: '2.0', | ||
result: '0x1bc16d674ec80000', // 2 ETH | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not needed, as we are mocking the balances using the mockMultiNetworkBalancePolling |
||
await mockServerJsonRpc(mockServer, [ | ||
['eth_blockNumber'], | ||
['eth_getBlockByNumber'], | ||
['eth_chainId', { result: `0x1` }], | ||
]); | ||
await mockEthDaiTrade(mockServer); | ||
|
||
await mockServer | ||
.forPost('https://transaction.api.cx.metamask.io/networks/1/getFees') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ import { | |
import FixtureBuilder from '../../fixture-builder'; | ||
import { unlockWallet, withFixtures } from '../../helpers'; | ||
import { Driver } from '../../webdriver/driver'; | ||
import { CHAIN_IDS } from '../../../../shared/constants/network'; | ||
import { mockSwapRequests } from './mock-requests-for-swap-test'; | ||
|
||
export async function withFixturesForSmartTransactions( | ||
|
@@ -20,10 +19,9 @@ export async function withFixturesForSmartTransactions( | |
}, | ||
test: (args: { driver: Driver }) => Promise<void>, | ||
) { | ||
const inputChainId = CHAIN_IDS.MAINNET; | ||
await withFixtures( | ||
{ | ||
fixtures: new FixtureBuilder({ inputChainId }) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not needed and creates a miss-match with networks, causing to send network requests to localhost https://github.com/MetaMask/metamask-extension/blob/develop/test/e2e/default-fixture.js#L174 (I think we should also remove this from the default fixture to avoid future network miss-matches, but we can leave this out of scope from this PR) |
||
fixtures: new FixtureBuilder() | ||
.withPermissionControllerConnectedToTestDapp() | ||
.withPreferencesControllerSmartTransactionsOptedIn() | ||
.withNetworkControllerOnMainnet() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed, as we are mocking the balances using the mockMultiNetworkBalancePolling