Skip to content

Commit 7a5b644

Browse files
110CodingPValuedMammal
authored andcommitted
docs: document persist_test_utils module
1 parent 5d9a95c commit 7a5b644

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

wallet/src/persist_test_utils.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Utilities for testing custom persistence backends for `bdk_wallet`
2+
13
use crate::{
24
bitcoin::{
35
absolute, key::Secp256k1, transaction, Address, Amount, Network, OutPoint, ScriptBuf,
@@ -48,6 +50,14 @@ fn spk_at_index(descriptor: &Descriptor<DescriptorPublicKey>, index: u32) -> Scr
4850
.script_pubkey()
4951
}
5052

53+
/// tests if [`Wallet`] is being persisted correctly
54+
///
55+
/// [`Wallet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html>
56+
/// [`ChangeSet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html>
57+
///
58+
/// We create a dummy [`ChangeSet`], persist it and check if loaded [`ChangeSet`] matches
59+
/// the persisted one. We then create another such dummy [`ChangeSet`], persist it and load it to
60+
/// check if merged [`ChangeSet`] is returned.
5161
pub fn persist_wallet_changeset<Store, CreateStore>(filename: &str, create_store: CreateStore)
5262
where
5363
CreateStore: Fn(&Path) -> anyhow::Result<Store>,
@@ -202,6 +212,14 @@ where
202212
assert_eq!(changeset, changeset_read_new);
203213
}
204214

215+
/// tests if multiple [`Wallet`]s can be persisted in a single file correctly
216+
///
217+
/// [`Wallet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html>
218+
/// [`ChangeSet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html>
219+
///
220+
/// We create a dummy [`ChangeSet`] for first wallet and persist it then we create a dummy
221+
/// [`ChangeSet`] for second wallet and persist that. Finally we load these two [`ChangeSet`]s and
222+
/// check if they were persisted correctly.
205223
pub fn persist_multiple_wallet_changesets<Store, CreateStores>(
206224
filename: &str,
207225
create_dbs: CreateStores,
@@ -266,6 +284,13 @@ pub fn persist_multiple_wallet_changesets<Store, CreateStores>(
266284
assert_eq!(changeset_read, changeset2);
267285
}
268286

287+
/// tests if [`Network`] is being persisted correctly
288+
///
289+
/// [`Network`]: <https://docs.rs/bitcoin/latest/bitcoin/enum.Network.html>
290+
/// [`ChangeSet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html>
291+
///
292+
/// We create a dummy [`ChangeSet`] with only network field populated, persist it and check if
293+
/// loaded [`ChangeSet`] has the same [`Network`] as what we persisted.
269294
pub fn persist_network<Store, CreateStore>(filename: &str, create_store: CreateStore)
270295
where
271296
CreateStore: Fn(&Path) -> anyhow::Result<Store>,
@@ -296,6 +321,12 @@ where
296321
assert_eq!(changeset_read.network, Some(Network::Bitcoin));
297322
}
298323

324+
/// tests if descriptors are being persisted correctly
325+
///
326+
/// [`ChangeSet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html>
327+
///
328+
/// We create a dummy [`ChangeSet`] with only descriptor fields populated, persist it and check if
329+
/// loaded [`ChangeSet`] has the same descriptors as what we persisted.
299330
pub fn persist_keychains<Store, CreateStore>(filename: &str, create_store: CreateStore)
300331
where
301332
CreateStore: Fn(&Path) -> anyhow::Result<Store>,
@@ -332,6 +363,12 @@ where
332363
assert_eq!(changeset_read.change_descriptor.unwrap(), change_descriptor);
333364
}
334365

366+
/// tests if descriptor(in a single keychain wallet) is being persisted correctly
367+
///
368+
/// [`ChangeSet`]: <https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.ChangeSet.html>
369+
///
370+
/// We create a dummy [`ChangeSet`] with only descriptor field populated, persist it and check if
371+
/// loaded [`ChangeSet`] has the same descriptor as what we persisted.
335372
pub fn persist_single_keychain<Store, CreateStore>(filename: &str, create_store: CreateStore)
336373
where
337374
CreateStore: Fn(&Path) -> anyhow::Result<Store>,

0 commit comments

Comments
 (0)