Skip to content

Commit b6b767f

Browse files
committed
test(wallet): check keymaps can be set when loading wallet
1 parent 517fb53 commit b6b767f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

crates/wallet/tests/wallet.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use bitcoin::{
2626
absolute, transaction, Address, Amount, BlockHash, FeeRate, Network, OutPoint, ScriptBuf,
2727
Sequence, Transaction, TxIn, TxOut, Txid, Weight,
2828
};
29+
use miniscript::{descriptor::KeyMap, Descriptor, DescriptorPublicKey};
2930
use rand::rngs::StdRng;
3031
use rand::SeedableRng;
3132

@@ -99,6 +100,11 @@ fn insert_seen_at(wallet: &mut Wallet, txid: Txid, seen_at: u64) {
99100
.unwrap();
100101
}
101102

103+
fn parse_descriptor(s: &str) -> (Descriptor<DescriptorPublicKey>, KeyMap) {
104+
<Descriptor<DescriptorPublicKey>>::parse_descriptor(&Secp256k1::new(), s)
105+
.expect("failed to parse descriptor")
106+
}
107+
102108
// The satisfaction size of a P2WPKH is 112 WU =
103109
// 1 (elements in witness) + 1 (OP_PUSH) + 33 (pk) + 1 (OP_PUSH) + 72 (signature + sighash) + 1*4 (script len)
104110
// On the witness itself, we have to push once for the pk (33WU) and once for signature + sighash (72WU), for
@@ -251,7 +257,22 @@ fn wallet_load_checks() -> anyhow::Result<()> {
251257
))),
252258
"unexpected descriptors check result",
253259
);
254-
260+
// check setting keymaps
261+
let (_, external_keymap) = parse_descriptor(external_desc);
262+
let (_, internal_keymap) = parse_descriptor(internal_desc);
263+
let wallet = Wallet::load()
264+
.keymap(KeychainKind::External, external_keymap)
265+
.keymap(KeychainKind::Internal, internal_keymap)
266+
.load_wallet(&mut open_db(&file_path)?)
267+
.expect("db should not fail")
268+
.expect("wallet was persisted");
269+
for keychain in [KeychainKind::External, KeychainKind::Internal] {
270+
let keymap = wallet.get_signers(keychain).as_key_map(wallet.secp_ctx());
271+
assert!(
272+
!keymap.is_empty(),
273+
"load should populate keymap for keychain {keychain:?}"
274+
);
275+
}
255276
Ok(())
256277
}
257278

0 commit comments

Comments
 (0)