Skip to content

Commit 277e18f

Browse files
Merge #661: Test: No address reuse for single descriptor
2c02a44 Test: No address reuse for single descriptor (志宇) Pull request description: ### Description Just a simple new test. This test is to ensure there are no regressions when we later change internal logic of `Wallet`. A single descriptor wallet should always get a new address with `AddressIndex::New` even if we alternate grabbing internal/external keychains. I thought of adding this during work on #647 ### Checklists #### All Submissions: * [x] I've signed all my commits * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md) * [x] I ran `cargo fmt` and `cargo clippy` before committing ACKs for top commit: danielabrozzoni: tACK 2c02a44 rajarshimaitra: tACK 2c02a44 Tree-SHA512: d065ae0979dc3ef7c26d6dfc19c88498e4bf17cc908e4f5677dcbf62ee59162e666cb00eb87b96d4c2557310960e3677eec7b6d907a5a4860cb7d2d74dba07b0
2 parents 8d3b2a9 + 2c02a44 commit 277e18f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/wallet/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,6 +4499,34 @@ pub(crate) mod test {
44994499
);
45004500
}
45014501

4502+
#[test]
4503+
fn test_get_address_no_reuse_single_descriptor() {
4504+
use crate::descriptor::template::Bip84;
4505+
use std::collections::HashSet;
4506+
4507+
let key = bitcoin::util::bip32::ExtendedPrivKey::from_str("tprv8ZgxMBicQKsPcx5nBGsR63Pe8KnRUqmbJNENAfGftF3yuXoMMoVJJcYeUw5eVkm9WBPjWYt6HMWYJNesB5HaNVBaFc1M6dRjWSYnmewUMYy").unwrap();
4508+
let wallet = Wallet::new(
4509+
Bip84(key, KeychainKind::External),
4510+
None,
4511+
Network::Regtest,
4512+
MemoryDatabase::default(),
4513+
)
4514+
.unwrap();
4515+
4516+
let mut used_set = HashSet::new();
4517+
4518+
(0..3).for_each(|_| {
4519+
let external_addr = wallet.get_address(AddressIndex::New).unwrap().address;
4520+
assert!(used_set.insert(external_addr));
4521+
4522+
let internal_addr = wallet
4523+
.get_internal_address(AddressIndex::New)
4524+
.unwrap()
4525+
.address;
4526+
assert!(used_set.insert(internal_addr));
4527+
});
4528+
}
4529+
45024530
#[test]
45034531
fn test_taproot_psbt_populate_tap_key_origins() {
45044532
let (wallet, _, _) = get_funded_wallet(get_test_tr_single_sig_xprv());

0 commit comments

Comments
 (0)