Skip to content

Conversation

110CodingP
Copy link
Contributor

@110CodingP 110CodingP commented Aug 12, 2025

Description

Added basic tests to the testenv for testing custom persistence backends. Partially solves bdk_wallet#14 and might help with bdk_wallet#234.

Notes to the reviewers

An alternative approach could be to create a struct whose methods are these tests but the current approach seems better since these tests are meant to be used as unit tests. For the same reason redundant functions to check persistence of individual fields of the ChangeSets are provided.

Update

  • Modified the default feature of testenv to specify bdk_chain/default as the only optional dependency.
  • Feature gate test utils functions introduced by default feature.

Changelog notice

Changed
    - default feature in testenv to specify only `bdk_chain/default` as the optional dependency.
Added
    - functions to testenv to check `ChangeSet`s are persisted and merged `ChangeSet`s are loaded properly ,gated by the `default` feature flag.
    - tests to `file_store` and `chain` based on utilities added to `testenv`.

Todo

  • Add docs
  • Add tests to bdk_chain based on testenv utilities

Checklists

All Submissions:

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

@110CodingP 110CodingP force-pushed the add_persist_test_utils branch 3 times, most recently from 8f06dc6 to 247d478 Compare August 15, 2025 11:53
@110CodingP 110CodingP marked this pull request as ready for review August 15, 2025 13:13
@notmandatory notmandatory moved this to Needs Review in BDK Chain Aug 19, 2025
@110CodingP 110CodingP force-pushed the add_persist_test_utils branch from 247d478 to 83b54a6 Compare August 19, 2025 05:33
@ValuedMammal
Copy link
Collaborator

I tried re-running CI to no avail, maybe try force pushing.

@110CodingP 110CodingP force-pushed the add_persist_test_utils branch from 83b54a6 to 51d148e Compare August 20, 2025 15:44
@ValuedMammal ValuedMammal moved this to Needs Review in BDK Wallet Aug 21, 2025
@ValuedMammal ValuedMammal added this to the Wallet 2.2.0 milestone Aug 21, 2025
@evanlinjin
Copy link
Member

Great idea. ConceptACK

@oleonardolima oleonardolima added new feature New feature or request tests labels Aug 29, 2025
Added the following functions to test if persistence of `bdk_chain` is
happening correctly.
  - `persist_txgraph_changeset`
  - `persist_indexer_changeset`
  - `persist_local_chain_changeset`
  - `persist_last_seen`, `persist_last_evicted`, `persist_first_seen`
  - `persist_txouts`
  - `persist_txs`
  - `persist_anchors`
  - `persist_last_revealed`
  - `persist_spk_cache`

Even though the first three tests cover every part of the `ChangeSet`s ,
the other tests are retained so as to help in unit testing.
Since there is no way we can enable miniscript/no-std for
bdk_chain::miniscript, cargo throws up an error when compiling with
`--no-default-features`. Adding miniscript as another dependency does
not resolve the issue because bdk_chain/miniscript is also required.

Removed unnecessary links from docs as just learned that docs.rs can
infers the links to dependencies.
@110CodingP 110CodingP force-pushed the add_persist_test_utils branch 2 times, most recently from f2623db to b77a114 Compare September 14, 2025 18:14
@110CodingP
Copy link
Contributor Author

In 10c42dc I added a miniscript feature to testenv but I am not sure if this is the correct approach. Earlier I was including the miniscript feature of bdk_chain by default but that doesn't work since miniscript requires either std or no-std but cargo doesn't allow specifying the feature of a dependency of a dependency. Adding miniscript as a separate dependency also does not work since we require bdk_chain/miniscript. But the current solution is also not satisfactory since miniscript feature requires the std feature!

@ValuedMammal
Copy link
Collaborator

In 10c42dc I added a miniscript feature to testenv but I am not sure if this is the correct approach. Earlier I was including the miniscript feature of bdk_chain by default but that doesn't work since miniscript requires either std or no-std but cargo doesn't allow specifying the feature of a dependency of a dependency. Adding miniscript as a separate dependency also does not work since we require bdk_chain/miniscript. But the current solution is also not satisfactory since miniscript feature requires the std feature!

We could have the testenv default feature enable bdk_chain/default, which in turn enables miniscript/std. I'm not aware of anyone needing a miniscript/no-std feature for the testenv crate.

@110CodingP
Copy link
Contributor Author

Should the miniscript feature introduced be removed? I was thinking if some users might not want bdk_chain/miniscript feature to be enabled?

@110CodingP 110CodingP force-pushed the add_persist_test_utils branch from b77a114 to 1eee95b Compare September 24, 2025 07:54
The miniscript feature is retained so as to not be coupled with
"download".
@110CodingP 110CodingP force-pushed the add_persist_test_utils branch from 1eee95b to fd9429c Compare September 24, 2025 08:22
@110CodingP
Copy link
Contributor Author

miniscript feature still depends on std feature of testenv since ig it would be confusing otherwise like when miniscript is enabled but not std even though miniscript would activate bdk_chain/std. Made miniscript a default feature too. Sorry if I am overthinking 😅 .

Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like the correct thing to do is something like this by making the dependency explicit.

[dependencies]
miniscript = { version = "12.3.5", default-features = false, optional = true }

[features]
default = ["std" , "download", "bdk_chain/default"]
miniscript = ["dep:miniscript"]
std = ["bdk_chain/std", "miniscript?/std"]
serde = ["bdk_chain/serde", "miniscript?/serde"]

But a simpler hack is to just have default = ["bdk_chain/default"] (which seems to be missing and should probably be done anyway). In that case the cfg attribute would be changed to #[cfg(feature = "default"]. Sorry to cause more bikeshedding on the matter. I'll be in favor of whatever is clear and easy to understand.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with the second approach since the first seemed a bit complicated 😅 (like the test utils are gated by miniscript feature which might not be enabled even though all we need is bdk_chain/default).

@notmandatory
Copy link
Member

notmandatory commented Sep 24, 2025

Since this is currently based on the master branch should we re-assign this to the 3.0 milestone and then do a new PR to back port it to 2.2? Nevermind, this is for the bdk crate so my question doesn't apply.

The feature now depends on `bdk_chain/default`. Now default feature
gates the persistence test utils rather than std.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request tests
Projects
Status: Needs Review
Development

Successfully merging this pull request may close these issues.

5 participants