Skip to content

fix(wallet)!: Improve test utilities - #1658

Merged
notmandatory merged 9 commits into
bitcoindevkit:masterfrom
ValuedMammal:test/wallet-insert-anchor
Nov 12, 2024
Merged

notmandatory merged 9 commits into
bitcoindevkit:masterfrom
ValuedMammal:test/wallet-insert-anchor

Conversation

@ValuedMammal

@ValuedMammal ValuedMammal commented Oct 24, 2024 •

Copy link
Copy Markdown
Contributor

Follow up to #1643, refactor insert_anchor_from_conf to just insert an anchor of type ConfirmationBlockTime

Notes to the reviewers

The PR introduces a public test_utils module and "test-utils" cargo feature that exposes common helpers such as get_funded_wallet. Credit to #1492 for inspiring that idea. Usage of test utilities is enhanced overall, and tests are less dependent on problematic APIs that may be removed in the future.

Changelog notice

  • bdk_wallet: Added "test-utils" feature flag that exposes common helpers for testing and development
  • Removed methods Wallet::insert_tx, Wallet::insert_checkpoint, Wallet::unbroadcast_transactions

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added docs for the new feature
  • This pull request breaks the existing API

Comment thread crates/wallet/tests/common.rs Resolved

@oleonardolima oleonardolima 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.

Concept ACK
Although I didn't get it yet why the change, mentioned in the comment below.

Comment thread crates/wallet/tests/wallet.rs Resolved
@ValuedMammal
ValuedMammal force-pushed the test/wallet-insert-anchor branch from d33116f to 771d7c1 Compare October 31, 2024 21:37
@ValuedMammal ValuedMammal changed the title test(wallet): refactor helper insert_anchor_from_conf wallet: Improve test utils Oct 31, 2024
@ValuedMammal
ValuedMammal force-pushed the test/wallet-insert-anchor branch 2 times, most recently from 95c14a2 to 869d7e6 Compare November 5, 2024 03:28
@ValuedMammal
ValuedMammal marked this pull request as ready for review November 5, 2024 03:36
@ValuedMammal
ValuedMammal force-pushed the test/wallet-insert-anchor branch from 869d7e6 to f5eeafd Compare November 5, 2024 04:00
@notmandatory

Copy link
Copy Markdown
Contributor

Is this an API break change or something that should go in the 1.0-beta milestone?

The common test utils are moved to a public `test_utils` module
behind a new test-utils feature flag
- `get_funded_wallet` requires two descriptors
- `get_funded_wallet_single` returns a single-descriptor
wallet
@ValuedMammal ValuedMammal added this to the 1.0.0-beta milestone Nov 5, 2024
@ValuedMammal ValuedMammal added the api A breaking API change label Nov 5, 2024
@ValuedMammal
ValuedMammal force-pushed the test/wallet-insert-anchor branch from f5eeafd to 1d61fde Compare November 5, 2024 19:03
@ValuedMammal

Copy link
Copy Markdown
Contributor Author

I cherry picked some of the changes from #1644. The main difference here is removing insert_tx from the wallet module and replacing it with similar functionality in test_utils. Despite the size of the PR, most of the changes are internal refactoring and adding documentation.

ValuedMammal and others added 3 commits November 5, 2024 14:14
Inserting unconfirmed txs can be done using the existing method
`apply_unconfirmed_txs`. Also removed `insert_checkpoint`, as the
API is unclear regarding where in the local chain the given block
should connect. Analogs for these methods are found in `test_utils`
module and are mainly used to facilitate testing.
This is no longer relevant as we direct callers to only insert tx into
the wallet after a successful broadcast.
Not including a `seen_at` alongside the update means the unconfirmed txs
of the update will not be considered to be part of the canonical
history. Therefore, transactions created with this wallet may replace
the update's unconfirmed txs (which is unintuitive behavior).

Also updated the docs.
@ValuedMammal
ValuedMammal force-pushed the test/wallet-insert-anchor branch from 1d61fde to b0dc3dd Compare November 5, 2024 19:14
@ValuedMammal ValuedMammal changed the title wallet: Improve test utils fix(wallet)!: Improve test utilities Nov 5, 2024

@notmandatory notmandatory 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.

ACK b0dc3dd

@notmandatory

Copy link
Copy Markdown
Contributor

This also fixes #1622 by removing functions that were only needed for testing.

@notmandatory
notmandatory merged commit 91d7d3c into bitcoindevkit:master Nov 12, 2024
@ValuedMammal
ValuedMammal deleted the test/wallet-insert-anchor branch November 12, 2024 12:18
@notmandatory notmandatory mentioned this pull request Dec 11, 2024
32 tasks done
noahjoeris added a commit to bitcoindevkit/bdk_wallet that referenced this pull request Nov 6, 2026
d3447f6 test(wallet): check foreign prevout handling (Noah Joeris)
5a69e46 fix(wallet): correct foreign prevout handling (Noah Joeris)

Pull request description:

  Closes #345
  Closes #556

  ### Description

  Fee bumping a transaction with a foreign input needs that prevout in the wallet. `insert_txout` is enough for a taproot prevout, or any witness prevout when `only_witness_utxo` is set. Legacy inputs, and other segwit inputs, need the full parent via `apply_update`. `calculate_fee`, `calculate_fee_rate`, `build_fee_bump`, and `add_foreign_utxo` now say so.

  This follows option 2 in #345: document the foreign-prevout workflow rather than make `add_foreign_utxo` fail for unregistered inputs.

  If a legacy foreign parent is missing, `build_fee_bump` used to build an input with neither UTXO field set and `finish` panicked. It now returns `TransactionNotFound`.

  ### Notes to the reviewers

  - A new `AddForeignUtxoError` variant would be a breaking change. We are avoiding one because `TxBuilder` is planned for removal in the next major release ([roadmap](#509)). This PR cannot fail early the way my previous solution did. It documents the workflow and adds checks where the existing errors allow it.
  - `Wallet::insert_tx` is not introduced as my previous solution did. It was removed on purpose in bitcoindevkit/bdk#1658, and `apply_update` is how a full parent is registered. So this API surface is not necessary.

  ### Changelog notice

  Fixed a panic when fee-bumping a legacy foreign input whose parent transaction is not in the wallet. `build_fee_bump` now returns `BuildFeeBumpError::TransactionNotFound`.

  ### Before submitting

  - [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk_wallet/blob/master/CONTRIBUTING.md)
  - [ ] This PR breaks the existing API

ACKs for top commit:
  notmandatory:
    ACK d3447f6

Tree-SHA512: 706a04ed44ecb06cd201f2ac30e8c10fecd1ca617bd47c652d2cd2ccd35c3e27440182621046f9ed89105a40b2d52b994d32738c2d65d333bfa11a3b9cdf1134
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api A breaking API change tests

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants