Commit ea334d0
test(e2e): mock Polymarket endpoints to remove from allowlist (MMQA-1800) (#29811)
## **Description**
Removes both Polymarket entries from `ALLOWLISTED_HOSTS` by 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](https://consensyssoftware.atlassian.net/browse/MMQA-1364).
**Why these were allowlisted in the first place**
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
— `tests/flows/browser.flow.ts:118` calls `navigateToBrowserView()` via
`Explore → Trending → Browser`, so Polymarket calls fire across many
specs that have nothing to do with prediction markets.
**What this PR adds**
1. **New default mocks under `defaults/polymarket-apis.ts`** for the
Explore-render endpoints:
| Endpoint | Default response |
| --- | --- |
| `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}` and `events?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.
2. **Extended `POLYMARKET_COMPLETE_MOCKS`** with two new helpers:
- `POLYMARKET_PRICES_HISTORY_MOCKS` —
`clob.polymarket.com/prices-history` returning `{ 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 new `TeamsCache`/`buildGameData` path (recently added on
main) drops `market.game` to `undefined` when teams aren't found,
causing `PredictMarketDetails.tsx:370` to render the legacy layout (no
picks list, no cash-out button).
3. **Tightened `POLYMARKET_EVENT_DETAILS_MOCKS`**:
- Bumped to explicit `PRIORITY.BASE` (was at default mockttp priority,
tied with the proxy fallback handler — the wildcard was masking cases
where the fallback won).
- Tightened matcher to `/events/{numericId}` only, after Cursor Bugbot
flagged that `includes('events/')` also matches `events/pagination`
because `events/` is a substring of `events/pagination`. The new regex
`gamma-api\.polymarket\.com\/events\/[0-9]+` ensures pagination requests
fall through to their dedicated mock regardless of registration order.
4. **Extended `trending-api-mocks.ts`** with three new entries used by
the trending feed's prediction detail flow:
- `gamma-api.polymarket.com/events/1` returning the same Bitcoin event
payload as the existing `events/pagination` mock
- `clob.polymarket.com/prices-history` returning `{ 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_HOSTS` is now down to **5** entries: 4 local +
`metamask.github.io`.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
[MMQA-1800](https://consensyssoftware.atlassian.net/browse/MMQA-1800)
Parent epic:
[MMQA-1364](https://consensyssoftware.atlassian.net/browse/MMQA-1364)
Fixes:
## **Manual testing steps**
```gherkin
Feature: E2E mock coverage for Polymarket Explore-tab calls
Scenario: browser specs that pass through Explore no longer leak Polymarket requests
Given an E2E spec calls navigateToBrowserView()
And the flow taps Explore → Trending → Browser
When TrendingView renders sports market feeds via usePredictMarketData
Then requests to gamma-api.polymarket.com (events/pagination, public-search, markets, teams) are answered by the default mocks
And requests to data-api.polymarket.com (positions, activity, upnl) are answered by the default mocks
And requests to polymarket.com (homepage/carousel, crypto/crypto-price) are answered by the default mocks
And no entries for Polymarket hosts are required in mock-e2e-allowlist.ts
Scenario: predict specs render market detail with picks list and cash-out button
Given the spec registers POLYMARKET_COMPLETE_MOCKS as its testSpecificMock
And the production default for predictLiveSports has leagues ['nfl','nba']
When the test taps a position and navigates to PredictMarketDetails
Then gamma-api.polymarket.com/teams returns realistic team payloads for the requested league
And buildGameData populates market.game with home/away team data
And PredictMarketDetails renders PredictGameDetailsContent with the picks list
And the predict-picks-cash-out-button-{positionId} element is present for the test to tap
Scenario: trending-feed renders prediction detail without leaking
Given the spec registers TRENDING_API_MOCKS as its testSpecificMock
When the test taps a prediction row and the wallet navigates to the detail screen
Then events/{id}, prices, and prices-history are answered by the trending mocks
And the spec passes without a live request leak
```
## **Screenshots/Recordings**
### **Before**
`tests/api-mocking/mock-e2e-allowlist.ts`:
```ts
export const ALLOWLISTED_HOSTS = [
'0.0.0.0', '127.0.0.1', 'localhost', '10.0.2.2',
'gamma-api.polymarket.com',
'*.polymarket.com',
'metamask.github.io',
];
```
`tests/api-mocking/mock-responses/defaults/polymarket-apis.ts` had 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`:
```ts
export const ALLOWLISTED_HOSTS = [
'0.0.0.0', '127.0.0.1', 'localhost', '10.0.2.2',
'metamask.github.io',
];
```
`defaults/polymarket-apis.ts` now has 10 default GET matchers (geoblock
+ 9 new) covering Explore-render endpoints.
`POLYMARKET_COMPLETE_MOCKS` covers `clob.polymarket.com/prices-history`
and `gamma-api.polymarket.com/teams` with realistic NBA + NFL rosters.
`POLYMARKET_EVENT_DETAILS_MOCKS` has explicit `PRIORITY.BASE` and a
tightened numeric-ID matcher. `TRENDING_API_MOCKS` covers `events/1`,
`prices-history`, and `prices`.
**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 includes
`trending-feed.spec.ts`), `confirmations-{android,ios}-smoke`, and
`browser-ios-smoke`. Run:
https://github.com/MetaMask/metamask-mobile/actions/runs/25526071329
## **Pre-merge author checklist**
- [x] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
#### Performance checks (if applicable)
- [ ] I've tested on Android
- Ideally on a mid-range device; emulator is acceptable
- [ ] I've tested with a power user scenario
- Use these [power-user
SRPs](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/edit-v2/401401446401?draftShareId=9d77e1e1-4bdc-4be1-9ebb-ccd916988d93)
to import wallets with many accounts and tokens
- [ ] I've instrumented key operations with Sentry traces for production
performance metrics
- See [`trace()`](/app/util/trace.ts) for usage and
[`addToken`](/app/components/Views/AddAsset/components/AddCustomToken/AddCustomToken.tsx#L274)
for an example
For performance guidelines and tooling, see the [Performance
Guide](https://consensyssoftware.atlassian.net/wiki/spaces/TL1/pages/400085549067/Performance+Guide+for+Engineers).
## **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.
[MMQA-1364]:
https://consensyssoftware.atlassian.net/browse/MMQA-1364?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
[MMQA-1800]:
https://consensyssoftware.atlassian.net/browse/MMQA-1800?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 4b4292d commit ea334d0
4 files changed
Lines changed: 377 additions & 5 deletions
File tree
- tests/api-mocking
- mock-responses
- defaults
- polymarket
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
| |||
Lines changed: 67 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
3 | 12 | | |
4 | 13 | | |
5 | 14 | | |
| |||
13 | 22 | | |
14 | 23 | | |
15 | 24 | | |
16 | | - | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
17 | 82 | | |
18 | 83 | | |
19 | 84 | | |
| |||
Lines changed: 256 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
215 | 219 | | |
| 220 | + | |
216 | 221 | | |
217 | 222 | | |
218 | 223 | | |
| |||
656 | 661 | | |
657 | 662 | | |
658 | 663 | | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
| 859 | + | |
| 860 | + | |
| 861 | + | |
| 862 | + | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
659 | 912 | | |
660 | 913 | | |
661 | 914 | | |
| |||
2214 | 2467 | | |
2215 | 2468 | | |
2216 | 2469 | | |
| 2470 | + | |
| 2471 | + | |
2217 | 2472 | | |
2218 | 2473 | | |
2219 | 2474 | | |
| |||
0 commit comments