test(e2e): mock Polymarket endpoints to remove from allowlist (MMQA-1800)#29811
Conversation
…800)
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>
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
CI surfaced two pre-existing leaks the *.polymarket.com wildcard had
been masking. Both are fixed here so the wildcard removal can ship.
- POLYMARKET_COMPLETE_MOCKS: add prices-history mock returning
{ history: [] }. Predict happy-path specs (open-position, cash-out,
claim-positions, geo-restriction) were making live calls to
clob.polymarket.com/prices-history; the chart consumer in
PolymarketProvider treats a non-array history as empty so this
empty payload is safe.
- trending-api-mocks: add events/1 (rich Bitcoin event payload
matching the existing pagination response) and prices-history
(empty history). trending-feed.spec.ts taps prediction row 1, which
navigates to a detail screen that calls these endpoints; without
the mocks the detail screen renders empty and the wallet's React
tree throws.
- defaults/polymarket-apis: drop the events/{id} and
events?parent_event_id matchers. They were too aggressive — empty
payloads cause the wallet to crash in detail screens. Detail-level
calls should be covered by the spec's testSpecificMock, not by
generic defaults.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…QA-1800)
Two more endpoints surfaced on the previous CI run:
- POLYMARKET_EVENT_DETAILS_MOCKS lacked an explicit priority. Tied at
default priority with the proxy fallback handler in MockServerE2E,
the wildcard *.polymarket.com allowlist had been hiding cases where
the fallback won. Bump to PRIORITY.BASE so events/{id} interception
is reliable. Fixes events/60362 (predict-claim-positions) and
events/79682 (predict-open-position).
- trending-api-mocks: add a POST /clob.polymarket.com/prices mock
returning {} so the prediction detail render in trending-feed.spec
doesn't leak.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ef93a06. Configure here.
The main merge brought in TeamsCache (app/components/UI/Predict/ providers/polymarket/TeamsCache.ts) which fetches gamma-api.polymarket.com/teams?league=...&abbreviation=... when rendering sports markets that have team metadata (NBA, NFL, etc.). Adds: - POLYMARKET_TEAMS_MOCKS function in polymarket-mocks.ts (returns []), wired into POLYMARKET_COMPLETE_MOCKS so predict specs are covered. - Default GET matcher in defaults/polymarket-apis.ts so non-predict specs that pass through Explore don't leak when team-aware markets render. Empty array is safe — TeamsCache short-circuits on non-array responses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
@metamaskbot update-mobile-fixture |
Cursor Bugbot flagged that the previous matcher
`url.includes('gamma-api.polymarket.com/events/')` also matches
`events/pagination` because the substring `events/` appears in
`events/pagination`. With the priority bump in commit 42b2b55,
this rule was at the same priority (PRIORITY.BASE = 999) as the
dedicated POLYMARKET_MARKET_FEEDS_MOCKS pagination matcher.
In practice the bug didn't manifest in the green CI run because
mockttp at equal priority picks the later-registered rule, and
MARKET_FEEDS_MOCKS is registered after EVENT_DETAILS_MOCKS in
POLYMARKET_COMPLETE_MOCKS. But the dependency on registration
order is fragile.
Tighten the matcher to only catch numeric event-id URLs
(/events/{digits}). Now `events/pagination` and
`events?parent_event_id=...` fall through to their dedicated
mocks regardless of registration order.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Investigation revealed why predict-* specs were failing on cash-out
button lookup after main was merged in.
Path:
- Production default for predictLiveSports has leagues=['nfl','nba']
(registry: tests/feature-flags/feature-flag-registry.ts:3471)
- The tests load this default via setupRemoteFeatureFlagsMock, so
liveSportsEnabled=true and the wallet calls TeamsCache.ensureTeamsLoaded
for game events
- TeamsCache caches teams by abbreviation; if a team is missing,
buildGameData (gameParser.ts:412-417) returns null, which leaves
market.game undefined
- PredictMarketDetails.tsx:370 only renders the new
PredictGameDetailsContent (which contains the picks list with
predict-picks-cash-out-button-{positionId}) when market?.game is set;
otherwise it falls back to the legacy market detail layout that
doesn't have the picks list
Returning [] from /teams (previous behavior) caused the wallet to fall
back to the legacy layout, so the cash-out button was never rendered.
This change replaces the static [] with a callback that returns the
NBA/NFL teams referenced by predict E2E fixtures (sas, nop, bos, bkn
for NBA; buf/atl/chi/was/den/nyj/det/kc/jax/pit/cin/sea/sf/tb/dal for
NFL). The wallet's TeamsCache stores all returned teams and looks
them up by abbreviation, so returning the full league roster is safe.
The defaults entry stays at [] since non-predict specs don't render
PredictGameDetailsContent — the [] only needs to absorb the leak,
not produce a working render.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection:
Selected tags:
No app code was changed, so no performance tests are needed. Performance Test Selection: |
|




Description
Removes both Polymarket entries from
ALLOWLISTED_HOSTSby adding default mocks for the Polymarket endpoints fired by the wallet's Explore tab and shoring up several pre-existing test-mock gaps the wildcard had been masking. Parent epic MMQA-1364.Why these were allowlisted in the first place
The wallet's Explore tab (
TrendingView/usePredictMarketData) fetches data fromgamma-api.polymarket.comand other Polymarket hosts when rendered. Many specs pass through Explore on the way to the browser —tests/flows/browser.flow.ts:118callsnavigateToBrowserView()viaExplore → Trending → Browser, so Polymarket calls fire across many specs that have nothing to do with prediction markets.What this PR adds
defaults/polymarket-apis.tsfor the Explore-render endpoints:gamma-api.polymarket.com/events/pagination?...{ data: [] }gamma-api.polymarket.com/public-search?...{ events: [] }gamma-api.polymarket.com/markets?...[]gamma-api.polymarket.com/teams?...[](defensive — non-predict specs that hit the new TeamsCache get an empty payload to absorb the leak)polymarket.com/api/homepage/carousel[]polymarket.com/api/crypto/crypto-price?...{}data-api.polymarket.com/positions?...[]data-api.polymarket.com/activity?...[]data-api.polymarket.com/upnl?...[]gamma-api.polymarket.com/events/{id}andevents?parent_event_id=...are intentionally not in defaults — empty payloads for those routes caused the wallet's detail screens to render the legacy layout (no picks list). They're now covered by spec-specific mocks instead.POLYMARKET_COMPLETE_MOCKSwith two new helpers:POLYMARKET_PRICES_HISTORY_MOCKS—clob.polymarket.com/prices-historyreturning{ history: [] }. Predict happy-path specs were making live calls here via the wildcard.POLYMARKET_TEAMS_MOCKS—gamma-api.polymarket.com/teams?league=...returning realistic NBA + NFL team rosters via a callback. Required because the newTeamsCache/buildGameDatapath (recently added on main) dropsmarket.gametoundefinedwhen teams aren't found, causingPredictMarketDetails.tsx:370to render the legacy layout (no picks list, no cash-out button).POLYMARKET_EVENT_DETAILS_MOCKS:PRIORITY.BASE(was at default mockttp priority, tied with the proxy fallback handler — the wildcard was masking cases where the fallback won)./events/{numericId}only, after Cursor Bugbot flagged thatincludes('events/')also matchesevents/paginationbecauseevents/is a substring ofevents/pagination. The new regexgamma-api\.polymarket\.com\/events\/[0-9]+ensures pagination requests fall through to their dedicated mock regardless of registration order.trending-api-mocks.tswith three new entries used by the trending feed's prediction detail flow:gamma-api.polymarket.com/events/1returning the same Bitcoin event payload as the existingevents/paginationmockclob.polymarket.com/prices-historyreturning{ history: [] }clob.polymarket.com/prices(POST) returning{}Allowlist entries removed:
gamma-api.polymarket.com(was redundant — covered by the wildcard)*.polymarket.com(covered all subdomains + apex)ALLOWLISTED_HOSTSis now down to 5 entries: 4 local +metamask.github.io.Changelog
CHANGELOG entry: null
Related issues
MMQA-1800
Parent epic: MMQA-1364
Fixes:
Manual testing steps
Screenshots/Recordings
Before
tests/api-mocking/mock-e2e-allowlist.ts:tests/api-mocking/mock-responses/defaults/polymarket-apis.tshad a single entry: the geoblock mock. All other Polymarket calls leaked to live via the wildcard, masking gaps in test-specific mocks.After
tests/api-mocking/mock-e2e-allowlist.ts:defaults/polymarket-apis.tsnow has 10 default GET matchers (geoblock + 9 new) covering Explore-render endpoints.POLYMARKET_COMPLETE_MOCKScoversclob.polymarket.com/prices-historyandgamma-api.polymarket.com/teamswith realistic NBA + NFL rosters.POLYMARKET_EVENT_DETAILS_MOCKShas explicitPRIORITY.BASEand a tightened numeric-ID matcher.TRENDING_API_MOCKScoversevents/1,prices-history, andprices.CI verification (commit
a3d232d3):All E2E smoke suites pass with zero leak warnings sampled across
prediction-market-{android,ios}-smoke,wallet-platform-{android,ios}-smoke(which includestrending-feed.spec.ts),confirmations-{android,ios}-smoke, andbrowser-ios-smoke. Run: https://github.com/MetaMask/metamask-mobile/actions/runs/25526071329Pre-merge author checklist
Performance checks (if applicable)
trace()for usage andaddTokenfor an exampleFor performance guidelines and tooling, see the Performance Guide.
Pre-merge reviewer checklist