|
| 1 | +//! Utilities for testing custom persistence backends for `bdk_wallet` |
| 2 | +
|
1 | 3 | use crate::{ |
2 | 4 | bitcoin::{ |
3 | 5 | absolute, key::Secp256k1, transaction, Address, Amount, Network, OutPoint, ScriptBuf, |
@@ -48,6 +50,14 @@ fn spk_at_index(descriptor: &Descriptor<DescriptorPublicKey>, index: u32) -> Scr |
48 | 50 | .script_pubkey() |
49 | 51 | } |
50 | 52 |
|
| 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. |
51 | 61 | pub fn persist_wallet_changeset<Store, CreateStore>(filename: &str, create_store: CreateStore) |
52 | 62 | where |
53 | 63 | CreateStore: Fn(&Path) -> anyhow::Result<Store>, |
@@ -202,6 +212,14 @@ where |
202 | 212 | assert_eq!(changeset, changeset_read_new); |
203 | 213 | } |
204 | 214 |
|
| 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. |
205 | 223 | pub fn persist_multiple_wallet_changesets<Store, CreateStores>( |
206 | 224 | filename: &str, |
207 | 225 | create_dbs: CreateStores, |
@@ -266,6 +284,13 @@ pub fn persist_multiple_wallet_changesets<Store, CreateStores>( |
266 | 284 | assert_eq!(changeset_read, changeset2); |
267 | 285 | } |
268 | 286 |
|
| 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. |
269 | 294 | pub fn persist_network<Store, CreateStore>(filename: &str, create_store: CreateStore) |
270 | 295 | where |
271 | 296 | CreateStore: Fn(&Path) -> anyhow::Result<Store>, |
@@ -296,6 +321,12 @@ where |
296 | 321 | assert_eq!(changeset_read.network, Some(Network::Bitcoin)); |
297 | 322 | } |
298 | 323 |
|
| 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. |
299 | 330 | pub fn persist_keychains<Store, CreateStore>(filename: &str, create_store: CreateStore) |
300 | 331 | where |
301 | 332 | CreateStore: Fn(&Path) -> anyhow::Result<Store>, |
@@ -332,6 +363,12 @@ where |
332 | 363 | assert_eq!(changeset_read.change_descriptor.unwrap(), change_descriptor); |
333 | 364 | } |
334 | 365 |
|
| 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. |
335 | 372 | pub fn persist_single_keychain<Store, CreateStore>(filename: &str, create_store: CreateStore) |
336 | 373 | where |
337 | 374 | CreateStore: Fn(&Path) -> anyhow::Result<Store>, |
|
0 commit comments