Skip to content

test(swap): enable Smart Transactions in swap and bridge E2E tests#27836

Merged
davibroc merged 2 commits into
mainfrom
test/swap-bridge-stx
Mar 24, 2026
Merged

test(swap): enable Smart Transactions in swap and bridge E2E tests#27836
davibroc merged 2 commits into
mainfrom
test/swap-bridge-stx

Conversation

@davibroc

@davibroc davibroc commented Mar 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Introduces tests/helpers/swap/smart-transactions-mocks.ts — a reusable helper that mocks the STX backend (/getFees, /submitTransactions, /batchStatus, /getTxStatus) and forwards signed transactions to Anvil so they get mined and receipts resolve correctly.
  • Removes .withDisabledSmartTransactions() from all affected test fixtures so tests run with the same STX-enabled configuration as production.
  • Applies the new helper to all swap/bridge regression and smoke specs: swap-action-regression, swap-token-chart, swap-token-rwa, swap-action-smoke, and bridge-action-smoke.

How Smart Transactions work in tests

When STX is enabled the swap publish hook intercepts the transaction before broadcast:

  1. Calls POST /getFees → mock returns a static fee schedule so the controller can sign the tx locally.
  2. Signs the tx locally and calls POST /submitTransactions → mock forwards all rawTxs to Anvil via eth_sendRawTransaction (sequentially, preserving nonce order for approval + swap batches), then returns a UUID.
  3. Because mobileReturnTxHashAsap: true the hook resolves immediately with the locally-computed txHash — no polling needed.
  4. TransactionController polls Anvil for eth_getTransactionReceipt using that hash → Anvil returns a valid receipt → tx is marked Confirmed.

Key fix: ERC-20 → ETH batch submissions

Previously the mock only forwarded rawTxs[0] (the approval tx) to Anvil. The swap tx (rawTxs[1]) was never mined, so TransactionController never found a receipt and the swap stayed Pending. The fix loops over all entries in rawTxs and forwards each one sequentially.

Modified scripts

  • swap-action-regression — ETH→WETH and WETH→ETH swaps confirm end-to-end
  • swap-token-chart — ETH→DAI swap from token chart confirms
  • swap-token-rwa — USDC→GOOGLON swap (CowSwap intent flow)
  • swap-action-smoke — ETH→USDC and USDC→ETH swaps confirm
  • bridge-action-smoke — ETH (Mainnet)→ETH (Base) bridge confirms

🤖 Generated with Claude Code


Note

Low Risk
Low risk since changes are isolated to E2E test harnesses/mocks; main risk is increased flakiness if STX mock assumptions (fee schema, proxy matching, Anvil forwarding) diverge from app behavior.

Overview
Swap/bridge E2E tests now run with Smart Transactions enabled by removing .withDisabledSmartTransactions() from affected fixtures.

Adds setupSmartTransactionsMocks to mock the STX backend (/getFees, /submitTransactions, /batchStatus, and a low-priority /getTxStatus fallback) and, crucially, forwards all submitted rawTxs sequentially to Anvil via eth_sendRawTransaction so batched approval+swap flows get mined and receipts resolve.

Updates swap and bridge regression/smoke specs to wrap existing testSpecificMock with the new STX mocks (and bumps timeouts where needed).

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

Remove .withDisabledSmartTransactions() and wire up setupSmartTransactionsMocks
across all swap/bridge regression and smoke specs. The STX mock forwards all
rawTxs (approval + swap) to Anvil sequentially so both txs are mined and
TransactionController can resolve receipts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@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.

@metamaskbot metamaskbot added the team-qa QA team label Mar 23, 2026
@github-actions github-actions Bot added size-M risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 23, 2026
@davibroc davibroc added no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed and removed risk-medium Moderate testing recommended · Possible bug introduction risk labels Mar 23, 2026
@metamaskbot metamaskbot added the INVALID-PR-TEMPLATE PR's body doesn't match template label Mar 23, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread tests/helpers/swap/smart-transactions-mocks.ts
…ridge mock

The getTxStatus mock in setupSmartTransactionsMocks was registered at priority
999, same as bridge-mocks.ts. Since mockttp resolves ties LIFO, the STX mock
shadowed the bridge-specific one in bridge-action-smoke, incorrectly setting
destChain.txHash equal to srcTxHash.

Lower the STX getTxStatus mock to priority 1 so bridge-mocks.ts always wins
for bridge tests. Same-chain swap tests are unaffected since srcChainId ==
destChainId and reusing srcTxHash for both chains is correct.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

@davibroc davibroc left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed the cursor bot comment: the getTxStatus mock in setupSmartTransactionsMocks has been lowered to priority 1 (commit 8082888) so bridge-mocks.ts (priority 999) always takes precedence for bridge tests. Same-chain swap tests are unaffected since srcChainId == destChainId there.

@github-actions github-actions Bot added the risk-medium Moderate testing recommended · Possible bug introduction risk label Mar 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

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

E2E Test Selection:
All 6 changed files are exclusively within the swap/bridge E2E test infrastructure. The PR enables Smart Transactions (STX) in swap and bridge tests by:

  1. Adding a new helper smart-transactions-mocks.ts that mocks STX API endpoints (/getFees, /submitTransactions, /batchStatus, /getTxStatus) and forwards signed transactions to Anvil for actual mining.
  2. Removing .withDisabledSmartTransactions() from all 5 test specs (swap-action-smoke, bridge-action-smoke, swap-action-regression, swap-token-chart, swap-token-rwa).
  3. Integrating setupSmartTransactionsMocks into each test's testSpecificMock setup.
  4. Increasing timeout in swap-token-chart from 120s to 180s to accommodate the longer STX flow.

SmokeTrade is selected because the directly modified tests are swap and bridge smoke/regression tests. SmokeConfirmations is required per SmokeTrade tag description: 'When selecting SmokeTrade for swap or bridge flows, also select SmokeConfirmations (transaction confirmations are part of the flow).' No other tags are impacted as changes are purely within swap/bridge test infrastructure with no app code modifications.

Performance Test Selection:
No app code was changed - all modifications are within E2E test infrastructure (test specs and test helpers). Smart Transactions mocking changes do not affect app rendering performance, data loading, or any UI components. No performance tests are warranted.

View GitHub Actions results

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

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

@davibroc davibroc enabled auto-merge March 24, 2026 04:59
@davibroc davibroc added this pull request to the merge queue Mar 24, 2026
Merged via the queue into main with commit 1897f33 Mar 24, 2026
96 checks passed
@davibroc davibroc deleted the test/swap-bridge-stx branch March 24, 2026 09:47
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 24, 2026
@metamaskbot metamaskbot added the release-7.72.0 Issue or pull request that will be included in release 7.72.0 label Mar 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

INVALID-PR-TEMPLATE PR's body doesn't match template no-changelog no-changelog Indicates no external facing user changes, therefore no changelog documentation needed release-7.72.0 Issue or pull request that will be included in release 7.72.0 risk-medium Moderate testing recommended · Possible bug introduction risk size-M team-qa QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants