Skip to content

Commit e96f851

Browse files
authored
test: removing some entries from live request allowlist by adding missing mocks (#31504)
<!-- 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** Removing some entries from the live server allow list from our e2e, and adding their corresponding global mocks. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/31504?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. All specs should continue to work normally ## **Screenshots/Recordings** n/a ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [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/main/.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.
1 parent acab3e9 commit e96f851

7 files changed

+923
-45
lines changed

test/e2e/mock-e2e-allowlist.js

-45
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
11
// Please do not add any more items to this list.
22
// This list is temporary and the goal is to reduce it to 0, meaning all requests are mocked in our e2e tests.
33
const ALLOWLISTED_URLS = [
4-
'https://account.api.cx.metamask.io/networks/1/tokens',
5-
'https://account.api.cx.metamask.io/networks/10/tokens',
6-
'https://account.api.cx.metamask.io/networks/100/tokens',
7-
'https://account.api.cx.metamask.io/networks/1101/tokens',
8-
'https://account.api.cx.metamask.io/networks/1284/tokens',
9-
'https://account.api.cx.metamask.io/networks/1285/tokens',
10-
'https://account.api.cx.metamask.io/networks/1313161554/tokens',
11-
'https://account.api.cx.metamask.io/networks/137/tokens',
12-
'https://account.api.cx.metamask.io/networks/25/tokens',
13-
'https://account.api.cx.metamask.io/networks/250/tokens',
14-
'https://account.api.cx.metamask.io/networks/324/tokens',
15-
'https://account.api.cx.metamask.io/networks/42161/tokens',
16-
'https://account.api.cx.metamask.io/networks/42220/tokens',
17-
'https://account.api.cx.metamask.io/networks/43114/tokens',
18-
'https://account.api.cx.metamask.io/networks/56/tokens',
19-
'https://account.api.cx.metamask.io/networks/59144/tokens',
20-
'https://account.api.cx.metamask.io/networks/8453/tokens',
214
'https://accounts.google.com/ListAccounts?gpsia=1&source=ChromiumBrowser&json=standard',
225
'https://acl.execution.metamask.io/latest/registry.json',
236
'https://acl.execution.metamask.io/latest/signature.json',
@@ -29,7 +12,6 @@ const ALLOWLISTED_URLS = [
2912
'https://authentication.api.cx.metamask.io/siwe/verify',
3013
'https://bafkreifvhjdf6ve4jfv6qytqtux5nd4nwnelioeiqx5x2ez5yrgrzk7ypi.ipfs.dweb.link/',
3114
'https://bafybeidxfmwycgzcp4v2togflpqh2gnibuexjy4m4qqwxp7nh3jx5zlh4y.ipfs.dweb.link/1.json',
32-
'https://bridge.api.cx.metamask.io/getAllFeatureFlags',
3315
'https://bridge.api.cx.metamask.io/getTokens?chainId=1',
3416
'https://cdn.contentful.com/spaces/jdkgyfmyd9sw/environments/master/entries?content_type=productAnnouncement&order=-sys.createdAt&fields.clients=portfolio',
3517
'https://cdn.segment.com/analytics-next/bundles/ajs-destination.bundle.ed53a26b6edc80c65d73.js',
@@ -40,9 +22,7 @@ const ALLOWLISTED_URLS = [
4022
'https://cdn.segment.com/v1/projects/MHae0tTVRqyHDim9qQ9ablSZpvm3Tvzc/settings',
4123
'https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.14.1/css/mdb.min.css',
4224
'https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.1/css/bootstrap.min.css',
43-
'https://chainid.network/chains.json',
4425
'https://client-config.api.cx.metamask.io/v1/flags?client=extension&distribution=flask&environment=dev',
45-
'https://client-side-detection.api.cx.metamask.io/v1/request-blocklist',
4626
'https://d6tizftlrpuof.cloudfront.net/themes/production/consensys-button-8ad6c4bb549247e0276dd160e2d8e00d.png',
4727
'https://doesntexist.test/customRPC',
4828
'https://etherscan.io/favicon.ico',
@@ -112,12 +92,6 @@ const ALLOWLISTED_URLS = [
11292
'https://nft.api.cx.metamask.io/collections?chainId=0x539&contract=0x5fbdb2315678afecb367f032d93f642f64180aa3',
11393
'https://nft.api.cx.metamask.io/users/0x5cfe73b6021e818b776b421b1c4db2474086a7e1/tokens?chainIds=1&limit=50&includeTopBid=true&continuation=',
11494
'https://o1377931.ingest.sentry.io/api/6689755/envelope/?sentry_key=be397d53390141cda058e18f3749c8e4&sentry_version=7&sentry_client=sentry.javascript.react%2F7.102.1',
115-
'https://on-ramp-content.api.cx.metamask.io/regions/networks?context=extension',
116-
'https://on-ramp.api.cx.metamask.io/eligibility/mm-card?id=',
117-
'https://on-ramp.api.cx.metamask.io/eligibility/mm-card?id=0x01a92b9df8ce522a8f98161a97378bfdb2cce64f2d4293657e7eefe818d9ffbc',
118-
'https://on-ramp.api.cx.metamask.io/eligibility/mm-card?id=0xb1b1aa3036452bf32c1159266d1886279e4890ba907ed275e39fbc56906a8be2',
119-
'https://on-ramp.api.cx.metamask.io/eligibility/mm-card?id=7ea301c0-6a98-11ef-a19e-f3acaa606eca',
120-
'https://on-ramp.api.cx.metamask.io/eligibility/mm-card?id=8af26790-6a98-11ef-bee7-5553e37c0097',
12195
'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/master/src/config.json',
12296
'https://responsive-rpc.test/',
12397
'https://security-alerts.api.cx.metamask.io/validate/0x1',
@@ -127,16 +101,6 @@ const ALLOWLISTED_URLS = [
127101
'https://signature-insights.api.cx.metamask.io/v1/signature?chainId=0x539',
128102
'https://sourcify.dev/server/files/any/1337/0x',
129103
'https://staking.api.cx.metamask.io/v1/pooled-staking/eligibility?addresses=',
130-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0x0000000000000000000000000000000000000000.png',
131-
'https://static.cx.metamask.io/api/v1/tokenIcons/1/0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2.png',
132-
'https://static.cx.metamask.io/api/v1/tokenIcons/1/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png',
133-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0x581c3c1a2a4ebde2a0df29b5cf4c116e42945947.png',
134-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0x6b175474e89094c44da98b954eedeac495271d0f.png',
135-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0x86002be4cdd922de1ccb831582bf99284b99ac12.png',
136-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48.png',
137-
'https://static.cx.metamask.io/api/v1/tokenIcons/1337/0xc6bdb96e29c38dc43f014eed44de4106a6a8eb5f.png',
138-
'https://static.cx.metamask.io/api/v1/tokenIcons/56/0x0d8775f648430679a709e98d2b0cb6250d2887ef.png',
139-
'https://static.cx.metamask.io/api/v1/tokenIcons/56/0x6b175474e89094c44da98b954eedeac495271d0f.png',
140104
'https://swap.api.cx.metamask.io/networks/1',
141105
'https://swap.api.cx.metamask.io/networks/1/trades?destinationToken=0x6b175474e89094c44da98b954eedeac495271d0f&sourceToken=0x0000000000000000000000000000000000000000&sourceAmount=1000000000000000&slippage=2&timeout=10000&walletAddress=0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
142106
'https://swap.api.cx.metamask.io/networks/1/trades?destinationToken=0x6b175474e89094c44da98b954eedeac495271d0f&sourceToken=0x0000000000000000000000000000000000000000&sourceAmount=2000000000000000000&slippage=2&timeout=10000&walletAddress=0x5cfe73b6021e818b776b421b1c4db2474086a7e1',
@@ -153,15 +117,6 @@ const ALLOWLISTED_URLS = [
153117
'https://verify.walletconnect.com/e6360eaee594162688065f1c70c863b7',
154118
'https://w.usabilla.com/ade130c1096e.js?lv=1',
155119
'https://websites.cdn.getfeedback.com/embed/aaeNy60jTL/gf.js',
156-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x',
157-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x048226a0',
158-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x095ea7b3',
159-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x23b872dd',
160-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x2e1a7d4d',
161-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x39509351',
162-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x5f575529',
163-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0x60806040',
164-
'https://www.4byte.directory/api/v1/signatures/?hex_signature=0xd0e30db0',
165120
];
166121

167122
const ALLOWLISTED_HOSTS = [

test/e2e/mock-e2e.js

+107
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,17 @@ const CDN_STALE_DIFF_RES_HEADERS_PATH =
3535
const CDN_STALE_RES_HEADERS_PATH =
3636
'test/e2e/mock-cdn/cdn-stale-res-headers.json';
3737

38+
const ACCOUNTS_API_TOKENS_PATH =
39+
'test/e2e/mock-response-data/accounts-api-tokens.json';
3840
const AGGREGATOR_METADATA_PATH =
3941
'test/e2e/mock-response-data/aggregator-metadata.json';
42+
const BRIDGE_GET_ALL_FEATURE_FLAGS_PATH =
43+
'test/e2e/mock-response-data/bridge-get-all-feature-flags.json';
44+
const CHAIN_ID_NETWORKS_PATH =
45+
'test/e2e/mock-response-data/chain-id-network-chains.json';
46+
const CLIENT_SIDE_DETECTION_BLOCKLIST_PATH =
47+
'test/e2e/mock-response-data/client-side-detection-blocklist.json';
48+
const ON_RAMP_CONTENT_PATH = 'test/e2e/mock-response-data/on-ramp-content.json';
4049
const TOKEN_BLOCKLIST_PATH = 'test/e2e/mock-response-data/token-blocklist.json';
4150

4251
const blocklistedHosts = [
@@ -829,6 +838,104 @@ async function setupMocking(
829838
};
830839
});
831840

841+
// On Ramp Content
842+
const ON_RAMP_CONTENT = fs.readFileSync(ON_RAMP_CONTENT_PATH);
843+
await server
844+
.forGet('https://on-ramp-content.api.cx.metamask.io/regions/networks')
845+
.thenCallback(() => {
846+
return {
847+
statusCode: 200,
848+
json: JSON.parse(ON_RAMP_CONTENT),
849+
};
850+
});
851+
852+
// Chains Metadata
853+
const CHAIN_ID_NETWORKS = fs.readFileSync(CHAIN_ID_NETWORKS_PATH);
854+
await server
855+
.forGet('https://chainid.network/chains.json')
856+
.thenCallback(() => {
857+
return {
858+
statusCode: 200,
859+
json: JSON.parse(CHAIN_ID_NETWORKS),
860+
};
861+
});
862+
863+
// Accounts API: supported networks
864+
await server
865+
.forGet('https://accounts.api.cx.metamask.io/v1/supportedNetworks')
866+
.thenCallback(() => {
867+
return {
868+
statusCode: 200,
869+
json: {
870+
fullSupport: [1, 137, 56, 59144, 8453, 10, 42161, 534352],
871+
partialSupport: {
872+
balances: [42220, 43114],
873+
},
874+
},
875+
};
876+
});
877+
878+
// Accounts API: tokens
879+
const ACCOUNTS_API_TOKENS = fs.readFileSync(ACCOUNTS_API_TOKENS_PATH);
880+
await server
881+
.forGet('https://account.api.cx.metamask.io/networks')
882+
.thenCallback(() => {
883+
return {
884+
statusCode: 200,
885+
json: JSON.parse(ACCOUNTS_API_TOKENS),
886+
};
887+
});
888+
889+
// Bridge Feature Flags
890+
const BRIDGE_GET_ALL_FEATURE_FLAGS = fs.readFileSync(
891+
BRIDGE_GET_ALL_FEATURE_FLAGS_PATH,
892+
);
893+
await server
894+
.forGet('https://bridge.api.cx.metamask.io/getAllFeatureFlags')
895+
.thenCallback(() => {
896+
return {
897+
statusCode: 200,
898+
json: JSON.parse(BRIDGE_GET_ALL_FEATURE_FLAGS),
899+
};
900+
});
901+
902+
// Client Side Detecition: Request Blocklist
903+
const CLIENT_SIDE_DETECTION_BLOCKLIST = fs.readFileSync(
904+
CLIENT_SIDE_DETECTION_BLOCKLIST_PATH,
905+
);
906+
await server
907+
.forGet(
908+
'https://client-side-detection.api.cx.metamask.io/v1/request-blocklist',
909+
)
910+
.thenCallback(() => {
911+
return {
912+
statusCode: 200,
913+
json: JSON.parse(CLIENT_SIDE_DETECTION_BLOCKLIST),
914+
};
915+
});
916+
917+
// On Ramp: Eligibility MetaMask Card
918+
await server
919+
.forGet('https://on-ramp.api.cx.metamask.io/eligibility/mm-card')
920+
.thenCallback(() => {
921+
return {
922+
statusCode: 200,
923+
body: true,
924+
headers: {
925+
'Content-Type': 'text/html; charset=utf-8',
926+
},
927+
};
928+
});
929+
930+
// Token Icons
931+
await server
932+
.forGet('https://static.cx.metamask.io/api/v1/tokenIcons')
933+
.thenCallback(() => {
934+
return {
935+
statusCode: 200,
936+
};
937+
});
938+
832939
/**
833940
* Returns an array of alphanumerically sorted hostnames that were requested
834941
* during the current test suite.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[
2+
{
3+
"name": "Ethereum",
4+
"symbol": "ETH",
5+
"decimals": 18,
6+
"address": "0x0000000000000000000000000000000000000000",
7+
"iconUrl": "https://token.api.cx.metamask.io/assets/nativeCurrencyLogos/ethereum.svg",
8+
"occurrences": 100,
9+
"sources": [],
10+
"chainId": 1,
11+
"coingeckoId": "ethereum"
12+
}
13+
]

0 commit comments

Comments
 (0)