Skip to content

Commit 2f83b45

Browse files
committed
test(wallet): check there are no duplicates across required and optional utxos
This test replaces the one used to test `coin_selection::filter_duplicates` introduced in 5299db3. As the code changed and there is not a single point to verificate the following properties: - there are no duplicates in required utxos - there are no duplicates in optional utxos - there are no duplicates across optional and required utxos anymore, test have been prefixed with `not_duplicated_utxos*` to allow its joint execution by using the following command: cargo test -- not_duplicated_utxos
1 parent 39df2b9 commit 2f83b45

File tree

1 file changed

+70
-0
lines changed
  • crates/wallet/src/wallet

1 file changed

+70
-0
lines changed

crates/wallet/src/wallet/mod.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2559,3 +2559,73 @@ macro_rules! doctest_wallet {
25592559
wallet
25602560
}}
25612561
}
2562+
2563+
#[cfg(test)]
2564+
mod test {
2565+
use super::*;
2566+
use crate::test_utils::get_test_tr_single_sig_xprv_and_change_desc;
2567+
use crate::test_utils::insert_tx;
2568+
2569+
#[test]
2570+
fn not_duplicated_utxos_across_optional_and_required() {
2571+
let (external_desc, internal_desc) = get_test_tr_single_sig_xprv_and_change_desc();
2572+
2573+
// create new wallet
2574+
let mut wallet = Wallet::create(external_desc, internal_desc)
2575+
.network(Network::Testnet)
2576+
.create_wallet_no_persist()
2577+
.unwrap();
2578+
2579+
let two_output_tx = Transaction {
2580+
input: vec![],
2581+
output: vec![
2582+
TxOut {
2583+
script_pubkey: wallet
2584+
.next_unused_address(KeychainKind::External)
2585+
.script_pubkey(),
2586+
value: Amount::from_sat(25_000),
2587+
},
2588+
TxOut {
2589+
script_pubkey: wallet
2590+
.next_unused_address(KeychainKind::External)
2591+
.script_pubkey(),
2592+
value: Amount::from_sat(75_000),
2593+
},
2594+
],
2595+
version: transaction::Version::non_standard(0),
2596+
lock_time: absolute::LockTime::ZERO,
2597+
};
2598+
2599+
let txid = two_output_tx.compute_txid();
2600+
insert_tx(&mut wallet, two_output_tx);
2601+
2602+
let mut params = TxParams::default();
2603+
let output = wallet.get_utxo(OutPoint { txid, vout: 0 }).unwrap();
2604+
params.utxos.insert(
2605+
output.outpoint,
2606+
WeightedUtxo {
2607+
satisfaction_weight: wallet
2608+
.public_descriptor(output.keychain)
2609+
.max_weight_to_satisfy()
2610+
.unwrap(),
2611+
utxo: Utxo::Local(output),
2612+
},
2613+
);
2614+
// enforce selection of first output in transaction
2615+
let received = wallet.filter_utxos(&params, wallet.latest_checkpoint().block_id().height);
2616+
// notice expected doesn't include the first output from two_output_tx as it should be
2617+
// filtered out
2618+
let expected = vec![wallet
2619+
.get_utxo(OutPoint { txid, vout: 1 })
2620+
.map(|utxo| WeightedUtxo {
2621+
satisfaction_weight: wallet
2622+
.public_descriptor(utxo.keychain)
2623+
.max_weight_to_satisfy()
2624+
.unwrap(),
2625+
utxo: Utxo::Local(utxo),
2626+
})
2627+
.unwrap()];
2628+
2629+
assert_eq!(expected, received);
2630+
}
2631+
}

0 commit comments

Comments
 (0)