Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(wallet)!: Improve test utilities #1658

Merged

Conversation

ValuedMammal
Copy link
Contributor

@ValuedMammal ValuedMammal commented Oct 24, 2024

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

Copy link
Contributor

@oleonardolima oleonardolima left a comment

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.

crates/wallet/tests/wallet.rs Show resolved Hide 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
Member

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
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
Copy link
Member

@notmandatory notmandatory left a comment

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
Member

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

@notmandatory notmandatory merged commit 91d7d3c into bitcoindevkit:master Nov 12, 2024
21 checks passed
@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
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