From 333ce3788802a7579f6f64ee5879a20be7f514c6 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 21 Feb 2025 14:55:16 -0330 Subject: [PATCH 1/4] fix: Add transaction simulation supported networks global mock A global mock has been added for the "supported networks" check made as part of the transaction simulations feature. This is triggered by certain types of confirmations (those that support transaction simulations), so it's triggered by a wide variety of E2E tests. Fixes #30490 --- shared/constants/transaction.ts | 7 +++++++ test/e2e/mock-e2e.js | 5 +++++ .../simulation-details.spec.ts | 16 ++-------------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/shared/constants/transaction.ts b/shared/constants/transaction.ts index 38311de3be76..5b0eb84af916 100644 --- a/shared/constants/transaction.ts +++ b/shared/constants/transaction.ts @@ -199,3 +199,10 @@ export enum TokenStandard { /** Not a token, but rather the base asset of the selected chain. */ none = 'NONE', } + +/** + * The hostname used for Ethereum Mainnet transaction simulations, and for + * retrieving "supported networks". + */ +export const TX_SENTINEL_URL = + 'https://tx-sentinel-ethereum-mainnet.api.cx.metamask.io'; diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index 748c00fcbd5c..43892a74f99a 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -13,6 +13,7 @@ const { SWAPS_API_V2_BASE_URL, TOKEN_API_BASE_URL, } = require('../../shared/constants/swaps'); +const { TX_SENTINEL_URL } = require('../../shared/constants/transaction'); const { SECURITY_ALERTS_PROD_API_BASE_URL } = require('./tests/ppom/constants'); const { DEFAULT_FEATURE_FLAGS_RESPONSE: BRIDGE_DEFAULT_FEATURE_FLAGS_RESPONSE, @@ -302,6 +303,10 @@ async function setupMocking( }; }); + await server.forGet(`${TX_SENTINEL_URL}/networks`).thenJson(200, { + 1: { name: 'Mainnet', confirmations: true }, + }); + await server .forGet(`${SWAPS_API_V2_BASE_URL}/featureFlags`) .thenCallback(() => { diff --git a/test/e2e/tests/simulation-details/simulation-details.spec.ts b/test/e2e/tests/simulation-details/simulation-details.spec.ts index 20475a945dde..717c7626a0f0 100644 --- a/test/e2e/tests/simulation-details/simulation-details.spec.ts +++ b/test/e2e/tests/simulation-details/simulation-details.spec.ts @@ -1,6 +1,7 @@ import { hexToNumber } from '@metamask/utils'; import { Mockttp, MockttpServer } from 'mockttp'; import { CHAIN_IDS } from '../../../../shared/constants/network'; +import { TX_SENTINEL_URL } from '../../../../shared/constants/transaction'; import FixtureBuilder from '../../fixture-builder'; import { createDappTransaction, @@ -43,15 +44,6 @@ import { } from './mock-request-send-eth'; import { MockRequestResponse } from './types'; -const TX_SENTINEL_URL = - 'https://tx-sentinel-ethereum-mainnet.api.cx.metamask.io/'; - -const mockNetworkRequest = async (mockServer: Mockttp) => { - await mockServer.forGet(`${TX_SENTINEL_URL}/networks`).thenJson(200, { - '1': { name: 'Mainnet', confirmations: true }, - }); -}; - async function withFixturesForSimulationDetails( { title, @@ -64,17 +56,13 @@ async function withFixturesForSimulationDetails( }, test: (args: Pick) => Promise, ) { - const testSpecificMock = async (mockServer: MockttpServer) => { - await mockNetworkRequest(mockServer); - await mockRequests(mockServer); - }; await withFixtures( { fixtures: new FixtureBuilder({ inputChainId }) .withPermissionControllerConnectedToTestDapp() .build(), title, - testSpecificMock, + mockRequests, dapp: true, localNodeOptions: { hardfork: 'london', From ddb6c1e98d91c919870094c0db740412b40b8bab Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 21 Feb 2025 15:33:53 -0330 Subject: [PATCH 2/4] Return valid data for supported transaction simulation mock (network was missing) --- test/e2e/mock-e2e.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/test/e2e/mock-e2e.js b/test/e2e/mock-e2e.js index 43892a74f99a..7bc77dc3daca 100644 --- a/test/e2e/mock-e2e.js +++ b/test/e2e/mock-e2e.js @@ -303,8 +303,19 @@ async function setupMocking( }; }); + // This endpoint returns metadata for "transaction simulation" supported networks. await server.forGet(`${TX_SENTINEL_URL}/networks`).thenJson(200, { - 1: { name: 'Mainnet', confirmations: true }, + 1: { + name: 'Mainnet', + group: 'ethereum', + chainID: 1, + nativeCurrency: { name: 'ETH', symbol: 'ETH', decimals: 18 }, + network: 'ethereum-mainnet', + explorer: 'https://etherscan.io', + confirmations: true, + smartTransactions: true, + hidden: false, + }, }); await server From 0bc9421ee6507c58e8fb4f1093eebb076dab1fd2 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Fri, 21 Feb 2025 15:34:32 -0330 Subject: [PATCH 3/4] Adjust comment --- shared/constants/transaction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared/constants/transaction.ts b/shared/constants/transaction.ts index 5b0eb84af916..ac4bb77b070a 100644 --- a/shared/constants/transaction.ts +++ b/shared/constants/transaction.ts @@ -202,7 +202,7 @@ export enum TokenStandard { /** * The hostname used for Ethereum Mainnet transaction simulations, and for - * retrieving "supported networks". + * retrieving metadata for transaction simulation supported networks. */ export const TX_SENTINEL_URL = 'https://tx-sentinel-ethereum-mainnet.api.cx.metamask.io'; From e05b2c1db917be7f5ab4b8f62db1a83aa0f662bb Mon Sep 17 00:00:00 2001 From: seaona Date: Fri, 21 Feb 2025 20:51:47 +0100 Subject: [PATCH 4/4] name testspecificmock --- test/e2e/tests/simulation-details/simulation-details.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/tests/simulation-details/simulation-details.spec.ts b/test/e2e/tests/simulation-details/simulation-details.spec.ts index 717c7626a0f0..c69a2f798b3d 100644 --- a/test/e2e/tests/simulation-details/simulation-details.spec.ts +++ b/test/e2e/tests/simulation-details/simulation-details.spec.ts @@ -62,7 +62,7 @@ async function withFixturesForSimulationDetails( .withPermissionControllerConnectedToTestDapp() .build(), title, - mockRequests, + testSpecificMock: mockRequests, dapp: true, localNodeOptions: { hardfork: 'london',