Repository navigation
feat(e2e): Tron API mocks and local-node proxy [WPN-536] - #43723
ulissesferreira wants to merge 1 commit into
Conversation
|
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. |
✨ Files requiring CODEOWNER review ✨🧪 @MetaMask/qa (2 files, +11 -7)
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 3 potential issues.
❌ 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 d5c95fc. Configure here.
| return { | ||
| statusCode: 200, | ||
| json: { ...base, data }, | ||
| }; |
There was a problem hiding this comment.
TRC20 history wrong JSON shape
Medium Severity
The mocked GET …/transactions/trc20 handler returns the same native-transaction objects as the plain transactions endpoint (txID, raw_data, TransferContract-style fields). TronGrid’s TRC20 history uses entries with transaction_id, token_info, from, to, type, and value, so activity parsing for captured smart-contract sends can fail when using proxyTronBlockchainCalls.
Reviewed by Cursor Bugbot for commit d5c95fc. Configure here.
Builds ready [d5c95fc]
⚡ Performance Benchmarks (Total: 🟢 12 pass · 🟡 13 warn · 🔴 0 fail)
Bundle size diffs
|
d20d219 to
29f81a3
Compare
d5c95fc to
533c871
Compare
Builds ready [533c871]
⚡ Performance Benchmarks (Total: 🟢 18 pass · 🟡 6 warn · 🔴 0 fail)
Bundle size diffs
|
533c871 to
fb8d80c
Compare
9746150 to
47e14ce
Compare
fb8d80c to
39457f7
Compare
Builds ready [39457f7]
⚡ Performance Benchmarks (Total: 🟢 13 pass · 🟡 10 warn · 🔴 1 fail)
Bundle size diffs [🚀 Bundle size reduced!]
|
1486437 to
5a9a731
Compare
39457f7 to
068f7c8
Compare
Builds ready [068f7c8]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Add TronGrid/Infura/accounts-API mock helpers, local-node request proxying, and pass localNodes context into test-specific mocks. Co-authored-by: Cursor <cursoragent@cursor.com>
068f7c8 to
d43a3ab
Compare
|
Builds ready [d43a3ab] [reused from 068f7c8]
⚡ Performance Benchmarks (Total: 🟢 15 pass · 🟡 9 warn · 🔴 0 fail)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
… parameterized fixtures (MetaMask#44485) ## **Description** Extends shared Tron E2E mock infrastructure with swap-token registry data, stateful account balances, parameterized transaction fixtures, and default transaction data. It is one reviewable step of a linear stack. Based on a fresh `main` and under 500 changed lines. ## **Changelog** CHANGELOG entry: null ## **Related issues** Part of the local-blockchain E2E initiative (WPN-536). Part 1 of 2 splitting MetaMask#44157 (was "Part 1 of 3 splitting MetaMask#43723"). ## **Manual testing steps** 1. `yarn build:test` 2. Confirm Tron E2E specs that consume the shared mocks still load and render asset data. ## **Screenshots/Recordings** N/A — test infrastructure only, no user-facing UI change. ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only mock helpers in `test/e2e`; no production wallet or runtime behavior changes. > > **Overview** > Extends shared Tron E2E mocks in `common-tron.ts` so upcoming swap and balance-delta tests can reuse canonical token metadata and flip account state after a broadcast. > > Adds **`TRON_SWAP_TOKEN_REGISTRY`** (TRX, USDT, USDD) plus **`TronSwapSymbol`**, and **`createStatefulTronAccountMock`**, which pairs account GET mocks with broadcast POST handling: balances stay on a `before` snapshot until a broadcast runs, then switch to an optional `after` snapshot (broadcast still returns the existing transaction-expiration style response). > > **`tronInfuraUrl`** now matches Infura URLs that include query strings (`($|\?)`), not only bare paths. TRC20 and native transaction list mocks take an optional **`transactions`** argument, with prior inline payloads moved to **`DEFAULT_TRON_TRC20_TRANSACTIONS`** and **`DEFAULT_TRON_TRANSACTIONS`**; response meta uses dynamic timestamps and page sizes. > > Existing **`mockTronGetAccount`** / **`mockBroadTransaction`** are unchanged for callers that do not adopt the stateful helper. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 0a401b8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY -->
## **Description** Adds a local Tron node proxy layer for E2E tests. It proxies blockchain calls to the local node, returns deterministic seeded token data, scopes account history, and captures only successful broadcasts for confirmation polling. It is one reviewable step of a linear stack. Based on a fresh `main` and under 700 changed lines. ## **Changelog** CHANGELOG entry: null ## **Related issues** Part of the local-blockchain E2E initiative (WPN-536). Part 2 of 2 splitting MetaMask#44157 (was "Part 1 of 3 splitting MetaMask#43723"). ## **Manual testing steps** 1. `yarn build:test` 2. Confirm Tron E2E specs that consume the proxy still load. 3. Send a native Tron or TRC-20 transaction and confirm successful broadcasts appear in account activity history, while a failed broadcast does not appear as confirmed. ## **Screenshots/Recordings** N/A — test infrastructure only, no user-facing UI change. ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Test-only mock infrastructure; no production wallet or runtime behavior changes. > > **Overview** > Adds **`proxyTronBlockchainCalls`** in `local-tron-node-mocks.ts` so Tron E2E can route Infura/TronGrid blockchain traffic through **mockttp** to a **local Tron node**, while still shaping a few responses tests depend on. > > Most wallet RPC calls are **forwarded** (`getblock`, account, resources, `createtransaction`, etc.). **Seeded TRC-20** contracts get **deterministic** `triggersmartcontract` / `triggerconstantcontract` payloads instead of hitting the node. **`broadcasttransaction`** is proxied but, on **`result: true`**, txs are **captured** and replayed on **`/v1/accounts/.../transactions`** and **`.../trc20`** as confirmed history for the given accounts—failed broadcasts are not added. > > In **`createStatefulTronAccountMock`** (`common-tron.ts`), the swap broadcast mock now returns a **successful** broadcast (`result: true`) instead of **`TRANSACTION_EXPIRATION_ERROR`**, aligned with the proxy’s success-only capture behavior. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 5550ec8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
…44159) ## **Description** Adds the Tron swap token registry and full bridge quote fixtures to `common-tron.ts`, including `TRON_SWAP_TOKEN_REGISTRY`, `TronQuoteFixture`, and `mockBridgeGetTronQuoteFor` for parameterized TRX→USDT (and other) swap quotes with the complete payload the swap UI expects (fees, slippage, price data). Rebased onto `main` after MetaMask#44157 and MetaMask#44485 merged, removing duplicate history that inflated the prior diff to ~2009 lines. This PR is now **657 changed lines** (383 additions, 274 deletions) in a single file. Part of the local-blockchain E2E initiative (WPN-536). Together with the preceding merged Tron mock PRs, this supersedes MetaMask#43723. ## **Changelog** CHANGELOG entry: null ## **Related issues** Part of the local-blockchain E2E initiative (WPN-536). Together with MetaMask#44157 and MetaMask#44485 supersedes MetaMask#43723. ## **Manual testing steps** 1. `yarn build:test` 2. `yarn test:e2e:single test/e2e/tests/tron/check-balance.spec.ts --browser=chrome` (expect 3/3 passing). ## **Screenshots/Recordings** N/A — test infrastructure only, no user-facing UI change. ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/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-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **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. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Changes are confined to Tron E2E mock helpers in a single test file; no production wallet, bridge, or auth paths are modified. > > **Overview** > Extends Tron E2E mocks so swap flows can drive **bridge `getQuote`** responses from a **`TronQuoteFixture`** (`src`/`dest` symbols, amounts, optional metabridge fee) via **`mockBridgeGetTronQuoteFor`**, while **`mockBridgeGetTronQuote`** keeps the prior default TRX→USDT case by delegating to that helper. > > Quote payloads are built from **`TRON_SWAP_TOKEN_REGISTRY`** (fees, slippage floor, Rango/SunSwap metadata). **TRX→USDT** trades now include a **TriggerSmartContract** shape with **protobuf-encoded `raw_data_hex`** and a **SHA256 `txID`** tied to `call_value`; other pairs get a lightweight placeholder trade. > > **`mockTronSpotPrices`** and **`mockTronAssets`** accept an optional **`TronNode`** token map, derive asset IDs from shared **TRC10/TRC20 defaults**, return **spot prices filtered by `assetIds`**, and supply **non-null** prices for GAS_FREE and SEED where they were previously `null`. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit cd71987. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Cursor <cursoragent@cursor.com>





Summary
Adds the Tron mock library and local-node HTTP proxy used by Tron E2E specs, plus wiring so
testSpecificMockreceives{ localNodes }.Stack: builds on #43722 →
WPN-536c-tron-fixturesExplainer — mocked endpoints & canned responses
common-tron.ts— external API mocks (no local node required)GET …/v1/accounts/{TRON_ACCOUNT_ADDRESS}GAS_FREE(33.33M), TRC20 HTX/SEED/USDT/USDD balances; optionalmockZeroBalancezeros allGET …/v1/accounts/{addr}/tokensGET …/v1/accounts/{addr}/transactions(/trc20)?…/wallet/getaccountresource(POST)getblock,getnowblock,getblockbynumPOST …/wallet/broadcasttransaction{ result: true, txid: <fixed> }accounts.api.cx.metamask.ioprice.api.cx.metamask.io, exchange-rate hoststokens.api.cx.metamask.iov2/v3client-config.api.cx.metamask.iotronAccounts+ BIP44 stage-2 multichain flagsmockTronApis()registers the full default set;mockTronSwapApis()adds bridge quote mocks.local-tron-node-mocks.ts— proxy to runningTronNodeWhen a local java-tron instance is up,
proxyTronBlockchainCalls(mockServer, localNode, addresses)intercepts TronGrid/Infura-shaped URLs and:POST /wallet/getblock,getaccountresource,getcontract,gettransactionbyidlocalNode.baseUrlPOST /wallet/broadcasttransaction,createtransactionPOST /wallet/triggersmartcontractGET /wallet/getchainparameters,POST getnextmaintenancetimeGET /v1/accounts/{addr}(scoped addresses)TronNode.getTronGridAccountResponse()so balances match seeded statehelpers.js/mock-e2e*wiringafterLocalNodesStart({ localNodes })hook (from PR1) is now usable by downstream fixtures.testSpecificMock(server, { localNodes })receives started node instances so mocks can callproxyTronBlockchainCalls.Test plan
yarn test:unit test/e2e/helpers/tron-assets.test.ts(profiles still valid with mocks present)mockTronApis/common-troncontinue to pass (covered in PR3 stack)CHANGELOG entry: null
Made with Cursor