Repository navigation
Commit 25f68e8
authored
test(bitcoin): expand send E2E coverage (#47234)
## **Description**
This pull request introduces several improvements and new utilities to
the Bitcoin end-to-end (E2E) test suite, focusing on more robust and
flexible Bitcoin transaction testing. The most significant changes
include new helper functions for sending and confirming Bitcoin
transactions, enhanced activity tab assertions, and refactoring of the
Bitcoin node seeder for improved block mining and address management.
**E2E Bitcoin transaction flow enhancements:**
* Added `landOnBitcoinSendScreen`, `confirmBitcoinSendAndAssertPending`,
and `waitForBitcoinSendConfirmation` helper functions to streamline and
clarify Bitcoin send E2E flows, including robust balance checks and
confirmation waits.
[[1]](diffhunk://#diff-12faa4bbc8672b24b5b1ab66785152b91f63b431785307f7b261e88e2e8efe49R4-R42)
[[2]](diffhunk://#diff-12faa4bbc8672b24b5b1ab66785152b91f63b431785307f7b261e88e2e8efe49R84-R143)
**Activity tab and transaction status assertions:**
* Enhanced the `ActivityTab` page object with methods to wait for
transactions with a specific amount and status, improving reliability of
transaction state assertions in tests.
[[1]](diffhunk://#diff-af5a4e69660c3aecba247b96e1878009cdb4158dee534de0bfa486aee226a17aR81-R83)
[[2]](diffhunk://#diff-af5a4e69660c3aecba247b96e1878009cdb4158dee534de0bfa486aee226a17aR511-R570)
**Bitcoin node seeder improvements:**
* Refactored `BitcoinNode` to add a `mineBlocks` method for mining
blocks to a fresh address, centralized address generation via a new
`getNewAddress` helper, and removed unused P2P port configuration.
[[1]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eL41)
[[2]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eR362-R376)
[[3]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eL632-R646)
[[4]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eR675-R678)
[[5]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eL774-R788)
[[6]](diffhunk://#diff-e17aad52c59176635dd97c1e03cf95e92c340dd99f249e9b58038760a0c5533eL793-R807)
**Test and assertion robustness:**
* Improved assertions on the Bitcoin review transaction page to check
for the exact send amount using a stricter selector and value
comparison.
[[1]](diffhunk://#diff-479d4f36276fc7f5132be843d652bcba71848d95c8c7ba330c8eb49860c13e61R1)
[[2]](diffhunk://#diff-479d4f36276fc7f5132be843d652bcba71848d95c8c7ba330c8eb49860c13e61L69-R73)
* Added error checking for invalid value errors in the send page, making
negative test cases clearer and more maintainable.
[[1]](diffhunk://#diff-23828c5e64c661f3108743386dec1d663d909fafaff393d01548c25e6d6e754cR69-R72)
[[2]](diffhunk://#diff-23828c5e64c661f3108743386dec1d663d909fafaff393d01548c25e6d6e754cR250-R254)
**Test coverage and fixtures:**
* Introduced a comprehensive test suite for `withBitcoinFixtures`,
covering fixture forwarding, node options, static mocks, error
propagation, and custom hooks.
* Added a unit test for the new `mineBlocks` method in the Bitcoin node
helper tests.
* Added a `refreshPage` utility to the home page object to ensure UI
state is reliably updated after network or balance changes.
## **Changelog**
CHANGELOG entry: null
## **Related issues**
Fixes: WPN-2136
## **Manual testing steps**
1. Build and load the extension, then unlock the test wallet.
2. Select Bitcoin and open the Send flow.
3. Enter a valid recipient without an amount, continue, and verify that
a transaction error is shown and Continue becomes disabled.
4. Enter the available BTC balance minus the displayed network fee and
verify that the transaction can be reviewed and submitted.
5. Send `0.5 BTC` and open Activity.
6. Verify that the activity entry displays `-0.5 BTC`, initially shows
Pending, and changes to Confirmed after the transaction is mined.
<!--
## **Screenshots/Recordings**
### **Before**
### **After**
-->
## **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
- [ ] 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 E2E test helpers, mocks, and page objects;
production wallet or send logic is not modified.
>
> **Overview**
> Expands Bitcoin send E2E coverage by splitting the old monolithic send
specs into focused scenarios under `tests/send/bitcoin/` (invalid
address, empty amount, over-balance, review amounts, max send, partial
send with on-chain confirmation). Those specs share a new
**`withBitcoinFixtures`** wrapper that starts anvil plus an optional
regtest `BitcoinNode`, wires `proxyBitcoinBlockchainCalls` or static
`mockInitialFullScan`, and registers the usual price/token mocks.
>
> **Test infrastructure changes:** Esplora **`POST /tx`** now returns
the real witness-stripped txid (with unit tests in
`bitcoin-esplora.test.ts`); **`BitcoinNode.mineBlocks`** and shared
**`getNewAddress`** support confirming sends in E2E; regtest bitcoind
drops P2P port allocation and runs with **`-listen=0`**. Page objects
gain **`HomePage.refreshPage`**, **`SendPage.checkInvalidValueError`**,
stricter snap review amount matching via XPath, and
**`ActivityTab.checkWaitForTransactionStatusByAmount`** for rows
identified by amount. The shared **`broadcastBitcoinSend`** flow file is
removed in favor of inline steps (activity spec updated). Jest coverage
documents **`withBitcoinFixtures`** behavior and **`mineBlocks`** RPC
usage.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
3d62499. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 0d6c299 commit 25f68e8
21 files changed
Lines changed: 1141 additions & 403 deletions
File tree
- test/e2e
- helpers
- page-objects
- flows
- pages
- home
- send
- seeder/bitcoin
- tests
- btc
- fixtures
- mocks
- send
- bitcoin
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 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 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
0 commit comments