From a6433a12e96ee142136809186a53b70455c0dc67 Mon Sep 17 00:00:00 2001 From: Vladimir Fomene Date: Thu, 9 Nov 2023 10:19:59 +0300 Subject: [PATCH] test: test getting keychain for a script --- crates/bdk/tests/wallet.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/crates/bdk/tests/wallet.rs b/crates/bdk/tests/wallet.rs index aad8c2db25..387e8cf506 100644 --- a/crates/bdk/tests/wallet.rs +++ b/crates/bdk/tests/wallet.rs @@ -60,6 +60,23 @@ fn receive_output_in_latest_block(wallet: &mut Wallet, value: u64) -> OutPoint { // OP_PUSH. const P2WPKH_FAKE_WITNESS_SIZE: usize = 106; +#[test] +fn test_which_keychain_derived_script() { + let (segwit_wallet, _) = get_funded_wallet(get_test_wpkh()); + let addr = segwit_wallet.get_address(New); + let script = addr.script_pubkey(); + let keychain = segwit_wallet + .which_keychain_derived_script(&script) + .unwrap(); + assert_eq!(keychain.0, KeychainKind::External); + + let (taproot_wallet, _) = get_funded_wallet(get_test_tr_single_sig()); + let addr = segwit_wallet.get_address(New); + let script = addr.script_pubkey(); + let keychain = segwit_wallet.which_keychain_derived_script(&script); + assert!(keychain.is_none()); +} + #[test] fn test_descriptor_checksum() { let (wallet, _) = get_funded_wallet(get_test_wpkh());