Skip to content

Commit 5c9abbe

Browse files
test(e2e): mock Polymarket endpoints to remove from allowlist (MMQA-1800)
The wallet's Explore tab (TrendingView / usePredictMarketData) fetches data from gamma-api.polymarket.com and other Polymarket hosts when rendered. Many specs pass through Explore on the way to the browser via navigateToBrowserView() — Explore → Trending → Browser — so Polymarket calls fire across many specs that aren't predict-related. Adds minimal-safe default mocks for the endpoints fired during Explore render (events/pagination, public-search, events/{id}, markets, parent events, homepage/carousel, crypto-price, data-api positions/activity/ upnl). Response shapes match the consumer's expected payload (e.g. events/pagination returns { data: [] } since the consumer reads data?.data). Predict and trending specs already register POLYMARKET_COMPLETE_MOCKS as testSpecificMock at higher priority, so their flows are unaffected by these defaults. Removes both Polymarket entries from ALLOWLISTED_HOSTS: - gamma-api.polymarket.com (was redundant — covered by the wildcard) - *.polymarket.com (covered all subdomains + apex) clob.polymarket.com is not in defaults because it only fires on trade actions, not Explore render. If CI surfaces leakage, follow up. ALLOWLISTED_HOSTS is now down to 5 entries (4 local + metamask.github.io). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent aac019d commit 5c9abbe

2 files changed

Lines changed: 74 additions & 4 deletions

File tree

tests/api-mocking/mock-e2e-allowlist.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ export const ALLOWLISTED_HOSTS = [
66
'127.0.0.1',
77
'localhost',
88
'10.0.2.2', // Android emulator host
9-
'gamma-api.polymarket.com',
10-
'*.polymarket.com',
119
'metamask.github.io', // Test-snaps and test-dapp pages loaded in browser
1210
];
1311

tests/api-mocking/mock-responses/defaults/polymarket-apis.ts

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
/**
2-
* Default mock responses for Polymarket API endpoints
2+
* Default mock responses for Polymarket API endpoints.
3+
*
4+
* These defaults cover the calls fired by the wallet's Explore tab
5+
* (TrendingView / usePredictMarketData) so that non-predict specs that pass
6+
* through Explore (e.g. via navigateToBrowserView()) don't leak live requests
7+
* to Polymarket. Predict and trending specs override these via
8+
* POLYMARKET_COMPLETE_MOCKS registered as testSpecificMock at higher priority.
9+
*
10+
* clob.polymarket.com is intentionally not covered here — it only fires on
11+
* trade actions, never during Explore render.
312
*/
413

514
/** Single source of truth for geoblock mock (eligible region). Reused in defaults and in POLYMARKET_COMPLETE_MOCKS. */
@@ -13,7 +22,70 @@ export const POLYMARKET_GEOBLOCK_ELIGIBLE = {
1322
} as const;
1423

1524
export const POLYMARKET_API_MOCKS = {
16-
GET: [POLYMARKET_GEOBLOCK_ELIGIBLE],
25+
GET: [
26+
POLYMARKET_GEOBLOCK_ELIGIBLE,
27+
// gamma-api: events pagination — consumer reads `data?.data`
28+
{
29+
urlEndpoint:
30+
/^https:\/\/gamma-api\.polymarket\.com\/events\/pagination(\?.*)?$/,
31+
responseCode: 200,
32+
response: { data: [] },
33+
},
34+
// gamma-api: public-search — consumer reads `data?.events`
35+
{
36+
urlEndpoint:
37+
/^https:\/\/gamma-api\.polymarket\.com\/public-search(\?.*)?$/,
38+
responseCode: 200,
39+
response: { events: [] },
40+
},
41+
// gamma-api: single event lookup — consumer accesses `data?.markets`
42+
{
43+
urlEndpoint: /^https:\/\/gamma-api\.polymarket\.com\/events\/[^/?]+$/,
44+
responseCode: 200,
45+
response: { markets: [] },
46+
},
47+
// gamma-api: parent event lookup
48+
{
49+
urlEndpoint:
50+
/^https:\/\/gamma-api\.polymarket\.com\/events(\?.*parent_event_id=.*)?$/,
51+
responseCode: 200,
52+
response: [],
53+
},
54+
// gamma-api: markets list
55+
{
56+
urlEndpoint: /^https:\/\/gamma-api\.polymarket\.com\/markets(\?.*)?$/,
57+
responseCode: 200,
58+
response: [],
59+
},
60+
// polymarket.com: homepage carousel
61+
{
62+
urlEndpoint: 'https://polymarket.com/api/homepage/carousel',
63+
responseCode: 200,
64+
response: [],
65+
},
66+
// polymarket.com: crypto price feed
67+
{
68+
urlEndpoint: /^https:\/\/polymarket\.com\/api\/crypto\/crypto-price.*$/,
69+
responseCode: 200,
70+
response: {},
71+
},
72+
// data-api: positions / activity / upnl
73+
{
74+
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/positions(\?.*)?$/,
75+
responseCode: 200,
76+
response: [],
77+
},
78+
{
79+
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/activity(\?.*)?$/,
80+
responseCode: 200,
81+
response: [],
82+
},
83+
{
84+
urlEndpoint: /^https:\/\/data-api\.polymarket\.com\/upnl(\?.*)?$/,
85+
responseCode: 200,
86+
response: [],
87+
},
88+
],
1789
POST: [],
1890
PUT: [],
1991
DELETE: [],

0 commit comments

Comments
 (0)