Skip to content

fix(e2e): add default mock for single-token metadata API endpoint#28146

Open
dylanbutler1 wants to merge 3 commits intomainfrom
fix/default-mock-single-token-metadata
Open

fix(e2e): add default mock for single-token metadata API endpoint#28146
dylanbutler1 wants to merge 3 commits intomainfrom
fix/default-mock-single-token-metadata

Conversation

@dylanbutler1
Copy link
Copy Markdown
Contributor

@dylanbutler1 dylanbutler1 commented Mar 31, 2026

Description

The trade-ios-smoke-1 job has been failing this week across bridge, swap, gasless swap, and deeplink tests with:

Test made 2 unmocked request(s) (2 unique):
1. [GET] https://token.api.cx.metamask.io/token/1?address=0xacA92E438df0B2401fF60dA7E4337B687a2435DA&includeRwaData=true
2. [GET] https://token.api.cx.metamask.io/token/59144?address=0xacA92E438df0B2401fF60dA7E4337B687a2435DA&includeRwaData=true

Root cause: The default E2E mocks in token-apis.ts cover /tokens/{chainId} (plural — token lists), /assets? (v2), and tokens.api.../v3/assets (v3), but not /token/{chainId}?address=... (singular — single-token metadata). This endpoint is called by the token controller whenever the app encounters a token (swap quotes, bridge destinations, etc.). It was only mocked in per-test setups for specific addresses (mUSD conversion, perps, polymarket), so any test hitting a different token/chain combo triggered validateLiveRequests() failure.

The address 0xacA92E438df0B2401fF60dA7E4337B687a2435DA is the mUSD token on Ethereum (chain 1) and Linea (chain 59144).

Fix: Add a default catch-all regex mock for /token/{chainId}?address=0x... that returns a minimal valid token metadata response. Per-test mocks with higher specificity still take precedence.

Changelog

CHANGELOG entry: null

Related issues

Refs: #26568

Manual testing steps

Feature: Trade smoke E2E reliability

  Scenario: swap/bridge/gasless tests no longer fail on unmocked token metadata
    Given a CI environment running trade-ios-smoke-1

    When bridge-action-smoke, swap-action-smoke, gasless-swap, or
         swap-deeplink-smoke tests make token metadata API requests
    Then the requests are caught by the default mock
    And validateLiveRequests() does not throw

Screenshots/Recordings

N/A — no UI changes, E2E test infrastructure only.

Before

N/A

After

N/A

Pre-merge author checklist

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.

Made with Cursor


Note

Low Risk
Test-only mocking change; main risk is a too-broad regex masking missing per-test mocks or affecting tests that expect real token metadata.

Overview
Adds a default GET mock for the Token API single-token metadata endpoint (/token/{chainId}?address=0x...) in tests/api-mocking/mock-responses/defaults/token-apis.ts, matching requests via a new regex.

The mock returns a minimal token metadata payload (address/symbol/decimals/name/iconUrl, etc.) so E2E runs don’t fail validateLiveRequests() when tests encounter previously-unmocked tokens/chains.

Written by Cursor Bugbot for commit aa272f5. This will update automatically on new commits. Configure here.

The token controller fetches /token/{chainId}?address=0x... for any
token the app encounters (swap quotes, bridge destinations, mUSD, etc.).
This endpoint was only mocked per-test for specific addresses, so any
test that triggered a request for an unmocked address caused
validateLiveRequests() to fail with "unmocked request" errors.

This was the primary cause of trade-ios-smoke-1 failures this week —
bridge, swap, gasless swap, and deeplink tests all hit the mUSD token
metadata endpoint on chains 1 and 59144 without a corresponding mock.

Add a default catch-all regex for /token/{chainId}?address=... that
returns a minimal valid response. Per-test mocks with higher specificity
still take precedence via MockServerE2E's matching order.

Made-with: Cursor
@dylanbutler1 dylanbutler1 self-assigned this Mar 31, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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.

@dylanbutler1 dylanbutler1 marked this pull request as ready for review April 1, 2026 09:32
@dylanbutler1 dylanbutler1 requested a review from a team as a code owner April 1, 2026 09:32
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

shane-t
shane-t previously approved these changes Apr 1, 2026
@github-actions github-actions bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Apr 1, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeTrade, SmokeConfirmations, SmokeNetworkAbstractions, SmokeNetworkExpansion, SmokeMultiChainAPI
  • Selected Performance tags: None (no tests recommended)
  • Risk Level: medium
  • AI Confidence: 82%
click to see 🤖 AI reasoning details

E2E Test Selection:
The change adds a new default mock for the single-token metadata API endpoint (/token/{chainId}?address=0x...) to the global test mock defaults in tests/api-mocking/mock-responses/defaults/token-apis.ts.

Nature of the change:

  • Adds a regex-based default mock for https://token.api.cx.metamask.io/token/{chainId}?address=0x...
  • Returns a minimal valid token metadata response to prevent validateLiveRequests failures
  • This is a global default mock used across ALL E2E tests via DEFAULT_MOCKS in index.ts
  • The change is additive (no existing mocks modified)

Why these tags:

  • SmokeTrade: Swap and bridge flows are explicitly mentioned in the comment as triggers for this endpoint ("swap quotes, bridge destinations"). These tests are most likely to exercise the single-token metadata endpoint.
  • SmokeConfirmations: Token approval and ERC-20 transaction flows fetch token metadata. Also required as a dependent tag when SmokeTrade is selected.
  • SmokeNetworkAbstractions: Multi-chain token filtering and network-specific token operations fetch token metadata.
  • SmokeNetworkExpansion: Multi-chain provider and Solana token flows may trigger token metadata requests.
  • SmokeMultiChainAPI: Session-based multi-chain permissions involve token operations across chains.

Why not all tags:

  • The change is a defensive mock addition that prevents failures rather than changing behavior. Tests that don't involve token metadata fetches (SmokeAccounts, SmokeIdentity, SmokeRamps, SmokeCard, SmokePerps, SmokePredictions, SmokeWalletPlatform, FlaskBuildTests) are unlikely to be affected by this specific mock addition.
  • The risk is that the new mock could interfere with test-specific mocks that override the default, but since it's additive and uses a specific regex pattern, this is unlikely.

Performance tests: No performance impact expected from a test mock change.

Performance Test Selection:
This is a test infrastructure change (adding a default API mock) with no impact on app code or runtime performance. No performance tests are needed.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 1, 2026

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 1, 2026

E2E Fixture Validation — Schema is up to date
17 value mismatches detected (expected — fixture represents an existing user).
View details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-medium Moderate testing recommended · Possible bug introduction risk size-S team-earn

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants