test(wallet): Test wallet addresses
Adds test coverage for Wallet methods `reveal_addresses_to`, `mark_used`, and `unmark_used`
This commit is contained in:
parent
a266b4718f
commit
d39b319ddf
@ -2705,6 +2705,7 @@ fn test_next_unused_address() {
|
|||||||
"tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a"
|
"tb1q6yn66vajcctph75pvylgkksgpp6nq04ppwct9a"
|
||||||
);
|
);
|
||||||
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(0));
|
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(0));
|
||||||
|
// calling next_unused again gives same address
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
wallet
|
wallet
|
||||||
.next_unused_address(KeychainKind::External)
|
.next_unused_address(KeychainKind::External)
|
||||||
@ -2714,6 +2715,15 @@ fn test_next_unused_address() {
|
|||||||
);
|
);
|
||||||
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(0));
|
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(0));
|
||||||
|
|
||||||
|
// test mark used / unused
|
||||||
|
assert!(wallet.mark_used(KeychainKind::External, 0));
|
||||||
|
let next_unused_addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||||
|
assert_eq!(next_unused_addr.index, 1);
|
||||||
|
|
||||||
|
assert!(wallet.unmark_used(KeychainKind::External, 0));
|
||||||
|
let next_unused_addr = wallet.next_unused_address(KeychainKind::External).unwrap();
|
||||||
|
assert_eq!(next_unused_addr.index, 0);
|
||||||
|
|
||||||
// use the above address
|
// use the above address
|
||||||
receive_output_in_latest_block(&mut wallet, 25_000);
|
receive_output_in_latest_block(&mut wallet, 25_000);
|
||||||
|
|
||||||
@ -2725,6 +2735,9 @@ fn test_next_unused_address() {
|
|||||||
"tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7"
|
"tb1q4er7kxx6sssz3q7qp7zsqsdx4erceahhax77d7"
|
||||||
);
|
);
|
||||||
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(1));
|
assert_eq!(wallet.derivation_index(KeychainKind::External), Some(1));
|
||||||
|
|
||||||
|
// trying to mark index 0 unused should return false
|
||||||
|
assert!(!wallet.unmark_used(KeychainKind::External, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -2900,6 +2913,28 @@ fn test_get_address() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_reveal_addresses() {
|
||||||
|
let desc = get_test_tr_single_sig_xprv();
|
||||||
|
let mut wallet = Wallet::new_no_persist(desc, None, Network::Signet).unwrap();
|
||||||
|
let keychain = KeychainKind::External;
|
||||||
|
|
||||||
|
let last_revealed_addr = wallet
|
||||||
|
.reveal_addresses_to(keychain, 9)
|
||||||
|
.unwrap()
|
||||||
|
.last()
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(wallet.derivation_index(keychain), Some(9));
|
||||||
|
|
||||||
|
let unused_addrs = wallet.list_unused_addresses(keychain).collect::<Vec<_>>();
|
||||||
|
assert_eq!(unused_addrs.len(), 10);
|
||||||
|
assert_eq!(unused_addrs.last().unwrap(), &last_revealed_addr);
|
||||||
|
|
||||||
|
// revealing to an already revealed index returns nothing
|
||||||
|
let mut already_revealed = wallet.reveal_addresses_to(keychain, 9).unwrap();
|
||||||
|
assert!(already_revealed.next().is_none());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_address_no_reuse_single_descriptor() {
|
fn test_get_address_no_reuse_single_descriptor() {
|
||||||
use bdk::descriptor::template::Bip84;
|
use bdk::descriptor::template::Bip84;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user