From 88f98b28a7b32e32509862776f0db6eec90fa893 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Sat, 3 Jan 2026 02:39:15 +0100 Subject: [PATCH 1/7] refactor: consolidate utxos helpers in `test_utils.rs` --- key-wallet/src/tests/mod.rs | 2 + key-wallet/src/tests/test_utils.rs | 37 ++++++++++++ key-wallet/src/utxo.rs | 39 ++---------- .../managed_wallet_info/coin_selection.rs | 59 ++++--------------- .../transaction_builder.rs | 41 +------------ .../transaction_building.rs | 41 +++---------- 6 files changed, 61 insertions(+), 158 deletions(-) create mode 100644 key-wallet/src/tests/test_utils.rs diff --git a/key-wallet/src/tests/mod.rs b/key-wallet/src/tests/mod.rs index fce02450e..fed4fab89 100644 --- a/key-wallet/src/tests/mod.rs +++ b/key-wallet/src/tests/mod.rs @@ -2,6 +2,8 @@ //! //! This module contains exhaustive tests for all functionality. +pub mod test_utils; + mod account_tests; mod address_pool_tests; diff --git a/key-wallet/src/tests/test_utils.rs b/key-wallet/src/tests/test_utils.rs new file mode 100644 index 000000000..e7c7a0b89 --- /dev/null +++ b/key-wallet/src/tests/test_utils.rs @@ -0,0 +1,37 @@ +//! Test utilities for key-wallet tests + +use crate::utxo::Utxo; +use crate::Network; +use dashcore::blockdata::transaction::txout::TxOut; +use dashcore::blockdata::transaction::OutPoint; +use dashcore::hashes::Hash; +use dashcore::{Address, ScriptBuf, Txid}; +use dashcore_hashes::sha256d; + +const TEST_PUBKEY_BYTES: [u8; 33] = [ + 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, 0xa8, 0x40, + 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, 0x88, 0x7e, 0x5b, 0x23, + 0x52, +]; + +pub fn test_address() -> Address { + Address::p2pkh(&dashcore::PublicKey::from_slice(&TEST_PUBKEY_BYTES).unwrap(), Network::Testnet) +} + +pub fn test_utxo(value: u64) -> Utxo { + test_utxo_full(value, 100, 0, true) +} + +pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Utxo { + let outpoint = OutPoint { + txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), + vout, + }; + let txout = TxOut { + value, + script_pubkey: ScriptBuf::new(), + }; + let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); + utxo.is_confirmed = confirmed; + utxo +} diff --git a/key-wallet/src/utxo.rs b/key-wallet/src/utxo.rs index ac607c922..162f22eb7 100644 --- a/key-wallet/src/utxo.rs +++ b/key-wallet/src/utxo.rs @@ -307,42 +307,11 @@ impl Default for UtxoSet { #[cfg(test)] mod tests { use super::*; - use crate::Network; - use dashcore::blockdata::script::ScriptBuf; - use dashcore::Txid; - use dashcore_hashes::{sha256d, Hash}; - - fn test_utxo(value: u64, height: u32) -> Utxo { - test_utxo_with_vout(value, height, 0) - } - - fn test_utxo_with_vout(value: u64, height: u32, vout: u32) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ); - - Utxo::new(outpoint, txout, address, height, false) - } + use crate::tests::test_utils::test_utxo_full; #[test] fn test_utxo_spendability() { - let mut utxo = test_utxo(100000, 100); + let mut utxo = test_utxo_full(100000, 100, 0, false); // Unconfirmed UTXO should not be spendable assert!(!utxo.is_spendable(200)); @@ -360,8 +329,8 @@ mod tests { fn test_utxo_set_operations() { let mut set = UtxoSet::new(); - let utxo1 = test_utxo_with_vout(100000, 100, 0); - let utxo2 = test_utxo_with_vout(200000, 150, 1); // Different vout to ensure unique OutPoint + let utxo1 = test_utxo_full(100000, 100, 0, false); + let utxo2 = test_utxo_full(200000, 150, 1, false); // Different vout to ensure unique OutPoint set.add(utxo1.clone()); set.add(utxo2.clone()); diff --git a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs index b83bfe5a7..cb55b288b 100644 --- a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs +++ b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs @@ -690,45 +690,11 @@ impl std::error::Error for SelectionError {} #[cfg(test)] mod tests { use super::*; - use crate::Utxo; - use dashcore::blockdata::script::ScriptBuf; - use dashcore::{Address, Network, OutPoint, TxOut, Txid}; - use dashcore_hashes::{sha256d, Hash}; - - fn test_utxo(value: u64, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout: 0, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ); - - let mut utxo = Utxo::new(outpoint, txout, address, 100, false); - utxo.is_confirmed = confirmed; - utxo - } + use crate::tests::test_utils::test_utxo; #[test] fn test_smallest_first_selection() { - let utxos = vec![ - test_utxo(10000, true), - test_utxo(20000, true), - test_utxo(30000, true), - test_utxo(40000, true), - ]; + let utxos = vec![test_utxo(10000), test_utxo(20000), test_utxo(30000), test_utxo(40000)]; let selector = CoinSelector::new(SelectionStrategy::SmallestFirst); let result = selector.select_coins(&utxos, 25000, FeeRate::new(1000), 200).unwrap(); @@ -741,12 +707,7 @@ mod tests { #[test] fn test_largest_first_selection() { - let utxos = vec![ - test_utxo(10000, true), - test_utxo(20000, true), - test_utxo(30000, true), - test_utxo(40000, true), - ]; + let utxos = vec![test_utxo(10000), test_utxo(20000), test_utxo(30000), test_utxo(40000)]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); let result = selector.select_coins(&utxos, 25000, FeeRate::new(1000), 200).unwrap(); @@ -758,7 +719,7 @@ mod tests { #[test] fn test_insufficient_funds() { - let utxos = vec![test_utxo(10000, true), test_utxo(20000, true)]; + let utxos = vec![test_utxo(10000), test_utxo(20000)]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); let result = selector.select_coins(&utxos, 50000, FeeRate::new(1000), 200); @@ -770,12 +731,12 @@ mod tests { fn test_optimal_consolidation_strategy() { // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - test_utxo(100, true), - test_utxo(200, true), - test_utxo(300, true), - test_utxo(500, true), - test_utxo(1000, true), - test_utxo(2000, true), + test_utxo(100), + test_utxo(200), + test_utxo(300), + test_utxo(500), + test_utxo(1000), + test_utxo(2000), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs index 9b56466d6..df4c1e6d9 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs @@ -835,51 +835,12 @@ impl std::error::Error for BuilderError {} #[cfg(test)] mod tests { use super::*; + use crate::tests::test_utils::{test_address, test_utxo}; use crate::Network; - use dashcore::blockdata::script::ScriptBuf; use dashcore::blockdata::transaction::special_transaction::asset_lock::AssetLockPayload; - use dashcore::{OutPoint, TxOut, Txid}; use dashcore_hashes::{sha256d, Hash}; use hex; - fn test_utxo(value: u64) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout: 0, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ); - - let mut utxo = Utxo::new(outpoint, txout, address, 100, false); - utxo.is_confirmed = true; - utxo - } - - fn test_address() -> Address { - Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x03, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ) - } - #[test] fn test_transaction_builder_basic() { let utxo = test_utxo(100000); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs index 512b330cc..20b214d38 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs @@ -177,44 +177,17 @@ impl ManagedWalletInfo { #[cfg(test)] mod tests { use super::*; + use crate::tests::test_utils::test_utxo; use crate::wallet::managed_wallet_info::transaction_builder::TransactionBuilder; - use crate::Utxo; - use dashcore::blockdata::script::ScriptBuf; use dashcore::blockdata::transaction::special_transaction::TransactionPayload; - use dashcore::{Address, Network, OutPoint, Transaction, TxOut, Txid}; + use dashcore::{Address, Network, Transaction, Txid}; use dashcore_hashes::{sha256d, Hash}; use std::str::FromStr; - fn test_utxo(value: u64, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout: 0, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ); - - let mut utxo = Utxo::new(outpoint, txout, address, 100, false); - utxo.is_confirmed = confirmed; - utxo - } - #[test] fn test_basic_transaction_creation() { // Test creating a basic transaction with inputs and outputs - let utxos = vec![test_utxo(100000, true), test_utxo(200000, true), test_utxo(300000, true)]; + let utxos = vec![test_utxo(100000), test_utxo(200000), test_utxo(300000)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -315,7 +288,7 @@ mod tests { #[test] fn test_transaction_size_estimation() { // Test that transaction size estimation is accurate - let utxos = vec![test_utxo(100000, true), test_utxo(200000, true)]; + let utxos = vec![test_utxo(100000), test_utxo(200000)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -350,7 +323,7 @@ mod tests { #[test] fn test_fee_calculation() { // Test that fees are calculated correctly - let utxos = vec![test_utxo(1000000, true)]; + let utxos = vec![test_utxo(1000000)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -384,7 +357,7 @@ mod tests { #[test] fn test_insufficient_funds() { // Test that insufficient funds returns an error - let utxos = vec![test_utxo(10000, true)]; + let utxos = vec![test_utxo(10000)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -408,7 +381,7 @@ mod tests { #[test] fn test_exact_change_no_change_output() { // Test when the exact amount is used (no change output needed) - let utxos = vec![test_utxo(150226, true)]; // Exact amount for output + fee + let utxos = vec![test_utxo(150226)]; // Exact amount for output + fee let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() From 6098c89c83b12f0d85195b35285455d5d3ab317e Mon Sep 17 00:00:00 2001 From: Borja Castellano Date: Tue, 6 Jan 2026 15:58:52 +0000 Subject: [PATCH 2/7] move test_util out of tests module --- key-wallet/Cargo.toml | 1 + key-wallet/src/lib.rs | 3 ++ key-wallet/src/test_utils/address.rs | 13 +++++++ key-wallet/src/test_utils/mod.rs | 5 +++ key-wallet/src/test_utils/utxo.rs | 24 ++++++++++++ key-wallet/src/tests/mod.rs | 2 - key-wallet/src/tests/test_utils.rs | 37 ------------------- key-wallet/src/utxo.rs | 2 +- .../managed_wallet_info/coin_selection.rs | 2 +- .../transaction_builder.rs | 2 +- .../transaction_building.rs | 2 +- 11 files changed, 50 insertions(+), 43 deletions(-) create mode 100644 key-wallet/src/test_utils/address.rs create mode 100644 key-wallet/src/test_utils/mod.rs create mode 100644 key-wallet/src/test_utils/utxo.rs delete mode 100644 key-wallet/src/tests/test_utils.rs diff --git a/key-wallet/Cargo.toml b/key-wallet/Cargo.toml index 9f2306c0e..9734c7e01 100644 --- a/key-wallet/Cargo.toml +++ b/key-wallet/Cargo.toml @@ -16,6 +16,7 @@ bincode = ["serde", "dep:bincode", "dep:bincode_derive", "dash-network/bincode", bip38 = ["scrypt", "aes", "bs58", "rand"] eddsa = ["dashcore/eddsa"] bls = ["dashcore/bls"] +test-utils = [] [dependencies] internals = { path = "../internals", package = "dashcore-private" } diff --git a/key-wallet/src/lib.rs b/key-wallet/src/lib.rs index 08e957229..f93661977 100644 --- a/key-wallet/src/lib.rs +++ b/key-wallet/src/lib.rs @@ -12,6 +12,9 @@ extern crate core; #[cfg(feature = "std")] extern crate std; +#[cfg(any(test, feature = "test-utils"))] +pub mod test_utils; + #[cfg(test)] #[macro_use] mod test_macros; diff --git a/key-wallet/src/test_utils/address.rs b/key-wallet/src/test_utils/address.rs new file mode 100644 index 000000000..3935dd413 --- /dev/null +++ b/key-wallet/src/test_utils/address.rs @@ -0,0 +1,13 @@ +// TODO: This module should be in the dashcore crate + +use dashcore::{Address, Network}; + +const TEST_PUBKEY_BYTES: [u8; 33] = [ + 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, 0xa8, 0x40, + 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, 0x88, 0x7e, 0x5b, 0x23, + 0x52, +]; + +pub fn test_address() -> Address { + Address::p2pkh(&dashcore::PublicKey::from_slice(&TEST_PUBKEY_BYTES).unwrap(), Network::Testnet) +} diff --git a/key-wallet/src/test_utils/mod.rs b/key-wallet/src/test_utils/mod.rs new file mode 100644 index 000000000..8be00515c --- /dev/null +++ b/key-wallet/src/test_utils/mod.rs @@ -0,0 +1,5 @@ +mod address; +mod utxo; + +pub use self::address::*; +pub use self::utxo::*; diff --git a/key-wallet/src/test_utils/utxo.rs b/key-wallet/src/test_utils/utxo.rs new file mode 100644 index 000000000..005d9e634 --- /dev/null +++ b/key-wallet/src/test_utils/utxo.rs @@ -0,0 +1,24 @@ +use dashcore::{OutPoint, ScriptBuf, TxOut, Txid}; +use dashcore_hashes::{sha256d, Hash}; + +use crate::{test_utils::test_address, Utxo}; + +pub fn test_utxo(value: u64) -> Utxo { + test_utxo_full(value, 100, 0, true) +} + +pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Utxo { + let outpoint = OutPoint { + txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), + vout, + }; + + let txout = TxOut { + value, + script_pubkey: ScriptBuf::new(), + }; + + let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); + utxo.is_confirmed = confirmed; + utxo +} diff --git a/key-wallet/src/tests/mod.rs b/key-wallet/src/tests/mod.rs index fed4fab89..fce02450e 100644 --- a/key-wallet/src/tests/mod.rs +++ b/key-wallet/src/tests/mod.rs @@ -2,8 +2,6 @@ //! //! This module contains exhaustive tests for all functionality. -pub mod test_utils; - mod account_tests; mod address_pool_tests; diff --git a/key-wallet/src/tests/test_utils.rs b/key-wallet/src/tests/test_utils.rs deleted file mode 100644 index e7c7a0b89..000000000 --- a/key-wallet/src/tests/test_utils.rs +++ /dev/null @@ -1,37 +0,0 @@ -//! Test utilities for key-wallet tests - -use crate::utxo::Utxo; -use crate::Network; -use dashcore::blockdata::transaction::txout::TxOut; -use dashcore::blockdata::transaction::OutPoint; -use dashcore::hashes::Hash; -use dashcore::{Address, ScriptBuf, Txid}; -use dashcore_hashes::sha256d; - -const TEST_PUBKEY_BYTES: [u8; 33] = [ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, 0xa8, 0x40, - 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, 0x88, 0x7e, 0x5b, 0x23, - 0x52, -]; - -pub fn test_address() -> Address { - Address::p2pkh(&dashcore::PublicKey::from_slice(&TEST_PUBKEY_BYTES).unwrap(), Network::Testnet) -} - -pub fn test_utxo(value: u64) -> Utxo { - test_utxo_full(value, 100, 0, true) -} - -pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout, - }; - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); - utxo.is_confirmed = confirmed; - utxo -} diff --git a/key-wallet/src/utxo.rs b/key-wallet/src/utxo.rs index 162f22eb7..5e4cb4922 100644 --- a/key-wallet/src/utxo.rs +++ b/key-wallet/src/utxo.rs @@ -307,7 +307,7 @@ impl Default for UtxoSet { #[cfg(test)] mod tests { use super::*; - use crate::tests::test_utils::test_utxo_full; + use crate::test_utils::test_utxo_full; #[test] fn test_utxo_spendability() { diff --git a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs index cb55b288b..a58ef452f 100644 --- a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs +++ b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs @@ -690,7 +690,7 @@ impl std::error::Error for SelectionError {} #[cfg(test)] mod tests { use super::*; - use crate::tests::test_utils::test_utxo; + use crate::test_utils::test_utxo; #[test] fn test_smallest_first_selection() { diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs index df4c1e6d9..134cf482f 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs @@ -835,7 +835,7 @@ impl std::error::Error for BuilderError {} #[cfg(test)] mod tests { use super::*; - use crate::tests::test_utils::{test_address, test_utxo}; + use crate::test_utils::{test_address, test_utxo}; use crate::Network; use dashcore::blockdata::transaction::special_transaction::asset_lock::AssetLockPayload; use dashcore_hashes::{sha256d, Hash}; diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs index 20b214d38..da1a386bf 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs @@ -177,7 +177,7 @@ impl ManagedWalletInfo { #[cfg(test)] mod tests { use super::*; - use crate::tests::test_utils::test_utxo; + use crate::test_utils::test_utxo; use crate::wallet::managed_wallet_info::transaction_builder::TransactionBuilder; use dashcore::blockdata::transaction::special_transaction::TransactionPayload; use dashcore::{Address, Network, Transaction, Txid}; From 1a099887601326bb7eaef0ab82b2dd79fdb1fa94 Mon Sep 17 00:00:00 2001 From: Borja Castellano Date: Tue, 6 Jan 2026 16:13:16 +0000 Subject: [PATCH 3/7] expose and used test_utils in itegration tests --- key-wallet/Cargo.toml | 2 +- key-wallet/src/test_utils/utxo.rs | 16 +++++++ .../tests/test_optimal_consolidation.rs | 44 ++++--------------- 3 files changed, 25 insertions(+), 37 deletions(-) diff --git a/key-wallet/Cargo.toml b/key-wallet/Cargo.toml index 9734c7e01..520f2bcdd 100644 --- a/key-wallet/Cargo.toml +++ b/key-wallet/Cargo.toml @@ -48,5 +48,5 @@ async-trait = "0.1" [dev-dependencies] hex = "0.4" -key-wallet = { path = ".", features = ["bip38", "serde", "bincode", "eddsa", "bls"] } +key-wallet = { path = ".", features = ["test-utils", "bip38", "serde", "bincode", "eddsa", "bls"] } tokio = { version = "1", features = ["macros", "rt"] } diff --git a/key-wallet/src/test_utils/utxo.rs b/key-wallet/src/test_utils/utxo.rs index 005d9e634..05d2eee83 100644 --- a/key-wallet/src/test_utils/utxo.rs +++ b/key-wallet/src/test_utils/utxo.rs @@ -7,6 +7,22 @@ pub fn test_utxo(value: u64) -> Utxo { test_utxo_full(value, 100, 0, true) } +pub fn test_utxo2(value: u64, confirmed: bool) -> Utxo { + let outpoint = OutPoint { + txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), + vout: 0, + }; + + let txout = TxOut { + value, + script_pubkey: ScriptBuf::new(), + }; + + let mut utxo = Utxo::new(outpoint, txout, test_address(), 100, false); + utxo.is_confirmed = confirmed; + utxo +} + pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Utxo { let outpoint = OutPoint { txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), diff --git a/key-wallet/tests/test_optimal_consolidation.rs b/key-wallet/tests/test_optimal_consolidation.rs index ca9845b42..02b6afd10 100644 --- a/key-wallet/tests/test_optimal_consolidation.rs +++ b/key-wallet/tests/test_optimal_consolidation.rs @@ -1,47 +1,19 @@ +use key_wallet::test_utils::test_utxo2; + // Test for OptimalConsolidation coin selection strategy #[test] fn test_optimal_consolidation_strategy() { - use dashcore::blockdata::script::ScriptBuf; - use dashcore::{Address, Network, OutPoint, TxOut, Txid}; - use dashcore_hashes::{sha256d, Hash}; - use key_wallet::utxo::Utxo; use key_wallet::wallet::managed_wallet_info::coin_selection::*; use key_wallet::wallet::managed_wallet_info::fee::FeeRate; - fn test_utxo(value: u64, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout: 0, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let address = Address::p2pkh( - &dashcore::PublicKey::from_slice(&[ - 0x02, 0x50, 0x86, 0x3a, 0xd6, 0x4a, 0x87, 0xae, 0x8a, 0x2f, 0xe8, 0x3c, 0x1a, 0xf1, - 0xa8, 0x40, 0x3c, 0xb5, 0x3f, 0x53, 0xe4, 0x86, 0xd8, 0x51, 0x1d, 0xad, 0x8a, 0x04, - 0x88, 0x7e, 0x5b, 0x23, 0x52, - ]) - .unwrap(), - Network::Testnet, - ); - - let mut utxo = Utxo::new(outpoint, txout, address, 100, false); - utxo.is_confirmed = confirmed; - utxo - } - // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - test_utxo(100, true), - test_utxo(200, true), - test_utxo(300, true), - test_utxo(500, true), - test_utxo(1000, true), - test_utxo(2000, true), + test_utxo2(100, true), + test_utxo2(200, true), + test_utxo2(300, true), + test_utxo2(500, true), + test_utxo2(1000, true), + test_utxo2(2000, true), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation); From c085d78ce386797015624192545bd7f598963841 Mon Sep 17 00:00:00 2001 From: Borja Castellano Date: Tue, 6 Jan 2026 17:17:39 +0000 Subject: [PATCH 4/7] utxo constructor using range --- key-wallet-ffi/Cargo.toml | 1 + key-wallet-ffi/src/utxo_tests.rs | 87 ++++++++----------------------- key-wallet/src/test_utils/utxo.rs | 45 +++++++++++++++- 3 files changed, 68 insertions(+), 65 deletions(-) diff --git a/key-wallet-ffi/Cargo.toml b/key-wallet-ffi/Cargo.toml index 5148da999..23edb7c31 100644 --- a/key-wallet-ffi/Cargo.toml +++ b/key-wallet-ffi/Cargo.toml @@ -33,5 +33,6 @@ hex = "0.4" cbindgen = "0.29" [dev-dependencies] +key-wallet = { path = "../key-wallet", default-features = false, features = ["std", "test-utils"] } tempfile = "3.0" hex = "0.4" diff --git a/key-wallet-ffi/src/utxo_tests.rs b/key-wallet-ffi/src/utxo_tests.rs index 66d9f5288..e3b1adc9c 100644 --- a/key-wallet-ffi/src/utxo_tests.rs +++ b/key-wallet-ffi/src/utxo_tests.rs @@ -3,6 +3,7 @@ mod utxo_tests { use super::super::*; use crate::error::{FFIError, FFIErrorCode}; use key_wallet::managed_account::managed_account_type::ManagedAccountType; + use key_wallet::test_utils::{test_utxo_range, test_utxo_range_with_value}; use std::ffi::CStr; use std::ptr; @@ -278,11 +279,8 @@ mod utxo_tests { #[test] fn test_managed_wallet_get_utxos_multiple_accounts() { use crate::managed_wallet::FFIManagedWalletInfo; - use dashcore::blockdata::script::ScriptBuf; - use dashcore::{Address, OutPoint, TxOut, Txid}; use key_wallet::account::account_type::StandardAccountType; use key_wallet::managed_account::ManagedAccount; - use key_wallet::utxo::Utxo; use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo; use key_wallet::Network; @@ -313,22 +311,12 @@ mod utxo_tests { false, ); - for i in 0..2 { - let outpoint = OutPoint { - txid: Txid::from([i as u8; 32]), - vout: i as u32, - }; - let txout = TxOut { - value: 10000, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - let utxo = Utxo::new(outpoint, txout, address, 100, false); - bip44_account.utxos.insert(outpoint, utxo); + let utxos = test_utxo_range(0..2); + + for utxo in utxos { + bip44_account.utxos.insert(utxo.outpoint, utxo); } + managed_info.accounts.insert(bip44_account); // Create BIP32 account with 1 UTXO @@ -351,20 +339,12 @@ mod utxo_tests { false, ); - let outpoint = OutPoint { - txid: Txid::from([10u8; 32]), - vout: 0, - }; - let txout = TxOut { - value: 20000, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - let utxo = Utxo::new(outpoint, txout, address, 200, false); - bip32_account.utxos.insert(outpoint, utxo); + let utxos = test_utxo_range_with_value(10..11, 20000, 200); + + for utxo in utxos { + bip32_account.utxos.insert(utxo.outpoint, utxo); + } + managed_info.accounts.insert(bip32_account); // Create CoinJoin account with 2 UTXOs @@ -380,22 +360,12 @@ mod utxo_tests { false, ); - for i in 0..2 { - let outpoint = OutPoint { - txid: Txid::from([(20 + i) as u8; 32]), - vout: i as u32, - }; - let txout = TxOut { - value: 30000, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - let utxo = Utxo::new(outpoint, txout, address, 300, false); - coinjoin_account.utxos.insert(outpoint, utxo); + let utxos = test_utxo_range_with_value(20..22, 30000, 300); + + for utxo in utxos { + coinjoin_account.utxos.insert(utxo.outpoint, utxo); } + managed_info.accounts.insert(coinjoin_account); let ffi_managed_info = Box::into_raw(Box::new(FFIManagedWalletInfo::new(managed_info))); @@ -418,11 +388,8 @@ mod utxo_tests { #[test] fn test_managed_wallet_get_utxos() { use crate::managed_wallet::FFIManagedWalletInfo; - use dashcore::blockdata::script::ScriptBuf; - use dashcore::{Address, OutPoint, TxOut, Txid}; use key_wallet::account::account_type::StandardAccountType; use key_wallet::managed_account::ManagedAccount; - use key_wallet::utxo::Utxo; use key_wallet::wallet::managed_wallet_info::ManagedWalletInfo; use key_wallet::Network; @@ -454,20 +421,12 @@ mod utxo_tests { false, ); - let outpoint = OutPoint { - txid: Txid::from([1u8; 32]), - vout: 0, - }; - let txout = TxOut { - value: 10000, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - let utxo = Utxo::new(outpoint, txout, address, 100, false); - testnet_account.utxos.insert(outpoint, utxo); + let utxos = test_utxo_range_with_value(1..2, 10000, 100); + + for utxo in utxos { + testnet_account.utxos.insert(utxo.outpoint, utxo); + } + managed_info.accounts.insert(testnet_account); let ffi_managed_info = Box::into_raw(Box::new(FFIManagedWalletInfo::new(managed_info))); diff --git a/key-wallet/src/test_utils/utxo.rs b/key-wallet/src/test_utils/utxo.rs index 05d2eee83..bcb657b6d 100644 --- a/key-wallet/src/test_utils/utxo.rs +++ b/key-wallet/src/test_utils/utxo.rs @@ -1,4 +1,6 @@ -use dashcore::{OutPoint, ScriptBuf, TxOut, Txid}; +use std::ops::Range; + +use dashcore::{Address, Network, OutPoint, ScriptBuf, TxOut, Txid}; use dashcore_hashes::{sha256d, Hash}; use crate::{test_utils::test_address, Utxo}; @@ -38,3 +40,44 @@ pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Ut utxo.is_confirmed = confirmed; utxo } + +pub fn test_utxo_range(range: Range) -> Vec { + range + .enumerate() + .map(|(i, value)| { + let outpoint = OutPoint { + txid: Txid::from([value as u8; 32]), + vout: i as u32, + }; + let txout = TxOut { + value: 10000, + script_pubkey: ScriptBuf::from(vec![]), + }; + // Create a dummy P2PKH address + let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); + let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); + let address = Address::from_script(&script, Network::Testnet).unwrap(); + Utxo::new(outpoint, txout, address, 100, false) + }) + .collect() +} + +pub fn test_utxo_range_with_value(range: Range, value: u64, height: u32) -> Vec { + range + .map(|i| { + let outpoint = OutPoint { + txid: Txid::from([i as u8; 32]), + vout: i as u32, + }; + let txout = TxOut { + value, + script_pubkey: ScriptBuf::from(vec![]), + }; + // Create a dummy P2PKH address + let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); + let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); + let address = Address::from_script(&script, Network::Testnet).unwrap(); + Utxo::new(outpoint, txout, address, height, false) + }) + .collect() +} From 9fdf96e57ba9db60ae8db7560c81331cea140588 Mon Sep 17 00:00:00 2001 From: Borja Castellano Date: Tue, 6 Jan 2026 17:20:57 +0000 Subject: [PATCH 5/7] cleanup --- key-wallet-ffi/src/utxo_tests.rs | 10 +- key-wallet/src/test_utils/address.rs | 2 - key-wallet/src/test_utils/mod.rs | 3 +- key-wallet/src/test_utils/utxo.rs | 105 +++++------------- key-wallet/src/utxo.rs | 7 +- .../managed_wallet_info/coin_selection.rs | 29 +++-- .../transaction_builder.rs | 25 +++-- .../transaction_building.rs | 17 ++- .../tests/test_optimal_consolidation.rs | 14 +-- 9 files changed, 89 insertions(+), 123 deletions(-) diff --git a/key-wallet-ffi/src/utxo_tests.rs b/key-wallet-ffi/src/utxo_tests.rs index e3b1adc9c..77d2a5d1a 100644 --- a/key-wallet-ffi/src/utxo_tests.rs +++ b/key-wallet-ffi/src/utxo_tests.rs @@ -3,7 +3,7 @@ mod utxo_tests { use super::super::*; use crate::error::{FFIError, FFIErrorCode}; use key_wallet::managed_account::managed_account_type::ManagedAccountType; - use key_wallet::test_utils::{test_utxo_range, test_utxo_range_with_value}; + use key_wallet::Utxo; use std::ffi::CStr; use std::ptr; @@ -311,7 +311,7 @@ mod utxo_tests { false, ); - let utxos = test_utxo_range(0..2); + let utxos = Utxo::new_test_batch(0..2, 10000, 100, false); for utxo in utxos { bip44_account.utxos.insert(utxo.outpoint, utxo); @@ -339,7 +339,7 @@ mod utxo_tests { false, ); - let utxos = test_utxo_range_with_value(10..11, 20000, 200); + let utxos = Utxo::new_test_batch(10..11, 20000, 200, false); for utxo in utxos { bip32_account.utxos.insert(utxo.outpoint, utxo); @@ -360,7 +360,7 @@ mod utxo_tests { false, ); - let utxos = test_utxo_range_with_value(20..22, 30000, 300); + let utxos = Utxo::new_test_batch(20..22, 30000, 300, false); for utxo in utxos { coinjoin_account.utxos.insert(utxo.outpoint, utxo); @@ -421,7 +421,7 @@ mod utxo_tests { false, ); - let utxos = test_utxo_range_with_value(1..2, 10000, 100); + let utxos = Utxo::new_test_batch(1..2, 10000, 100, false); for utxo in utxos { testnet_account.utxos.insert(utxo.outpoint, utxo); diff --git a/key-wallet/src/test_utils/address.rs b/key-wallet/src/test_utils/address.rs index 3935dd413..aa14eff0e 100644 --- a/key-wallet/src/test_utils/address.rs +++ b/key-wallet/src/test_utils/address.rs @@ -1,5 +1,3 @@ -// TODO: This module should be in the dashcore crate - use dashcore::{Address, Network}; const TEST_PUBKEY_BYTES: [u8; 33] = [ diff --git a/key-wallet/src/test_utils/mod.rs b/key-wallet/src/test_utils/mod.rs index 8be00515c..ad2592879 100644 --- a/key-wallet/src/test_utils/mod.rs +++ b/key-wallet/src/test_utils/mod.rs @@ -1,5 +1,4 @@ mod address; mod utxo; -pub use self::address::*; -pub use self::utxo::*; +pub use address::*; diff --git a/key-wallet/src/test_utils/utxo.rs b/key-wallet/src/test_utils/utxo.rs index bcb657b6d..e4080bfc1 100644 --- a/key-wallet/src/test_utils/utxo.rs +++ b/key-wallet/src/test_utils/utxo.rs @@ -1,83 +1,34 @@ use std::ops::Range; -use dashcore::{Address, Network, OutPoint, ScriptBuf, TxOut, Txid}; -use dashcore_hashes::{sha256d, Hash}; +use dashcore::{OutPoint, ScriptBuf, TxOut, Txid}; use crate::{test_utils::test_address, Utxo}; -pub fn test_utxo(value: u64) -> Utxo { - test_utxo_full(value, 100, 0, true) -} - -pub fn test_utxo2(value: u64, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout: 0, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let mut utxo = Utxo::new(outpoint, txout, test_address(), 100, false); - utxo.is_confirmed = confirmed; - utxo -} - -pub fn test_utxo_full(value: u64, height: u32, vout: u32, confirmed: bool) -> Utxo { - let outpoint = OutPoint { - txid: Txid::from_raw_hash(sha256d::Hash::from_slice(&[1u8; 32]).unwrap()), - vout, - }; - - let txout = TxOut { - value, - script_pubkey: ScriptBuf::new(), - }; - - let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); - utxo.is_confirmed = confirmed; - utxo -} - -pub fn test_utxo_range(range: Range) -> Vec { - range - .enumerate() - .map(|(i, value)| { - let outpoint = OutPoint { - txid: Txid::from([value as u8; 32]), - vout: i as u32, - }; - let txout = TxOut { - value: 10000, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - Utxo::new(outpoint, txout, address, 100, false) - }) - .collect() -} - -pub fn test_utxo_range_with_value(range: Range, value: u64, height: u32) -> Vec { - range - .map(|i| { - let outpoint = OutPoint { - txid: Txid::from([i as u8; 32]), - vout: i as u32, - }; - let txout = TxOut { - value, - script_pubkey: ScriptBuf::from(vec![]), - }; - // Create a dummy P2PKH address - let dummy_pubkey_hash = dashcore::PubkeyHash::from([0u8; 20]); - let script = ScriptBuf::new_p2pkh(&dummy_pubkey_hash); - let address = Address::from_script(&script, Network::Testnet).unwrap(); - Utxo::new(outpoint, txout, address, height, false) - }) - .collect() +impl Utxo { + pub fn new_test(id: u8, value: u64, height: u32, confirmed: bool) -> Self { + Self::new_test_batch(id..id + 1, value, height, confirmed).remove(0) + } + + pub fn new_test_batch( + ids_range: Range, + value: u64, + height: u32, + confirmed: bool, + ) -> Vec { + ids_range + .enumerate() + .map(|(i, id)| { + let outpoint = OutPoint::new(Txid::from([id; 32]), i as u32); + + let txout = TxOut { + value, + script_pubkey: ScriptBuf::new(), + }; + + let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); + utxo.is_confirmed = confirmed; + utxo + }) + .collect() + } } diff --git a/key-wallet/src/utxo.rs b/key-wallet/src/utxo.rs index 5e4cb4922..58849fdae 100644 --- a/key-wallet/src/utxo.rs +++ b/key-wallet/src/utxo.rs @@ -307,11 +307,10 @@ impl Default for UtxoSet { #[cfg(test)] mod tests { use super::*; - use crate::test_utils::test_utxo_full; #[test] fn test_utxo_spendability() { - let mut utxo = test_utxo_full(100000, 100, 0, false); + let mut utxo = Utxo::new_test(0, 100000, 100, false); // Unconfirmed UTXO should not be spendable assert!(!utxo.is_spendable(200)); @@ -329,8 +328,8 @@ mod tests { fn test_utxo_set_operations() { let mut set = UtxoSet::new(); - let utxo1 = test_utxo_full(100000, 100, 0, false); - let utxo2 = test_utxo_full(200000, 150, 1, false); // Different vout to ensure unique OutPoint + let utxo1 = Utxo::new_test(0, 100000, 100, false); + let utxo2 = Utxo::new_test(1, 200000, 150, false); set.add(utxo1.clone()); set.add(utxo2.clone()); diff --git a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs index a58ef452f..e51a417f5 100644 --- a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs +++ b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs @@ -690,11 +690,15 @@ impl std::error::Error for SelectionError {} #[cfg(test)] mod tests { use super::*; - use crate::test_utils::test_utxo; #[test] fn test_smallest_first_selection() { - let utxos = vec![test_utxo(10000), test_utxo(20000), test_utxo(30000), test_utxo(40000)]; + let utxos = vec![ + Utxo::new_test(0, 10000, 100, true), + Utxo::new_test(0, 20000, 100, true), + Utxo::new_test(0, 30000, 100, true), + Utxo::new_test(0, 40000, 100, true), + ]; let selector = CoinSelector::new(SelectionStrategy::SmallestFirst); let result = selector.select_coins(&utxos, 25000, FeeRate::new(1000), 200).unwrap(); @@ -707,7 +711,12 @@ mod tests { #[test] fn test_largest_first_selection() { - let utxos = vec![test_utxo(10000), test_utxo(20000), test_utxo(30000), test_utxo(40000)]; + let utxos = vec![ + Utxo::new_test(0, 10000, 100, true), + Utxo::new_test(0, 20000, 100, true), + Utxo::new_test(0, 30000, 100, true), + Utxo::new_test(0, 40000, 100, true), + ]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); let result = selector.select_coins(&utxos, 25000, FeeRate::new(1000), 200).unwrap(); @@ -719,7 +728,7 @@ mod tests { #[test] fn test_insufficient_funds() { - let utxos = vec![test_utxo(10000), test_utxo(20000)]; + let utxos = vec![Utxo::new_test(0, 10000, 100, true), Utxo::new_test(0, 20000, 100, true)]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); let result = selector.select_coins(&utxos, 50000, FeeRate::new(1000), 200); @@ -731,12 +740,12 @@ mod tests { fn test_optimal_consolidation_strategy() { // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - test_utxo(100), - test_utxo(200), - test_utxo(300), - test_utxo(500), - test_utxo(1000), - test_utxo(2000), + Utxo::new_test(0, 100, 100, true), + Utxo::new_test(0, 200, 100, true), + Utxo::new_test(0, 300, 100, true), + Utxo::new_test(0, 500, 100, true), + Utxo::new_test(0, 1000, 100, true), + Utxo::new_test(0, 2000, 100, true), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs index 134cf482f..d66010fee 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs @@ -835,7 +835,7 @@ impl std::error::Error for BuilderError {} #[cfg(test)] mod tests { use super::*; - use crate::test_utils::{test_address, test_utxo}; + use crate::test_utils::test_address; use crate::Network; use dashcore::blockdata::transaction::special_transaction::asset_lock::AssetLockPayload; use dashcore_hashes::{sha256d, Hash}; @@ -843,7 +843,7 @@ mod tests { #[test] fn test_transaction_builder_basic() { - let utxo = test_utxo(100000); + let utxo = Utxo::new_test(0, 100000, 100, true); let destination = test_address(); let change = test_address(); @@ -862,7 +862,7 @@ mod tests { #[test] fn test_insufficient_funds() { - let utxo = test_utxo(10000); + let utxo = Utxo::new_test(0, 10000, 100, true); let destination = test_address(); let result = TransactionBuilder::new() @@ -928,7 +928,8 @@ mod tests { #[test] fn test_transaction_size_estimation() { // Test that transaction size estimation is accurate - let utxos = vec![test_utxo(100000), test_utxo(200000)]; + let utxos = + vec![Utxo::new_test(0, 100000, 100, true), Utxo::new_test(0, 200000, 100, true)]; let recipient_address = test_address(); let change_address = test_address(); @@ -962,7 +963,7 @@ mod tests { #[test] fn test_fee_calculation() { // Test that fees are calculated correctly - let utxos = vec![test_utxo(1000000)]; + let utxos = vec![Utxo::new_test(0, 1000000, 100, true)]; let recipient_address = test_address(); let change_address = test_address(); @@ -989,7 +990,7 @@ mod tests { #[test] fn test_exact_change_no_change_output() { // Test when the exact amount is used (no change output needed) - let utxos = vec![test_utxo(150226)]; // Exact amount for output + fee + let utxos = vec![Utxo::new_test(0, 150226, 100, true)]; // Exact amount for output + fee let recipient_address = test_address(); let change_address = test_address(); @@ -1011,7 +1012,7 @@ mod tests { #[test] fn test_special_payload_size_calculations() { // Test that special payload sizes are calculated correctly - let utxo = test_utxo(100000); + let utxo = Utxo::new_test(0, 100000, 100, true); let destination = test_address(); let change = test_address(); @@ -1076,7 +1077,7 @@ mod tests { #[test] fn test_build_with_payload_override() { // Test that build_with_payload overrides set_special_payload - let utxo = test_utxo(100000); + let utxo = Utxo::new_test(0, 100000, 100, true); let destination = test_address(); let change = test_address(); @@ -1122,7 +1123,7 @@ mod tests { #[test] fn test_bip69_output_ordering() { // Test that outputs are sorted according to BIP-69 - let utxo = test_utxo(1000000); + let utxo = Utxo::new_test(0, 1000000, 100, true); let address1 = test_address(); let address2 = Address::p2pkh( &dashcore::PublicKey::from_slice(&[ @@ -1241,7 +1242,11 @@ mod tests { #[test] fn test_coin_selection_with_special_payload() { // Test that coin selection considers special payload size - let utxos = vec![test_utxo(50000), test_utxo(60000), test_utxo(70000)]; + let utxos = vec![ + Utxo::new_test(0, 50000, 100, true), + Utxo::new_test(0, 60000, 100, true), + Utxo::new_test(0, 70000, 100, true), + ]; let recipient_address = test_address(); let change_address = test_address(); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs index da1a386bf..d4e816c28 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs @@ -177,8 +177,8 @@ impl ManagedWalletInfo { #[cfg(test)] mod tests { use super::*; - use crate::test_utils::test_utxo; use crate::wallet::managed_wallet_info::transaction_builder::TransactionBuilder; + use crate::Utxo; use dashcore::blockdata::transaction::special_transaction::TransactionPayload; use dashcore::{Address, Network, Transaction, Txid}; use dashcore_hashes::{sha256d, Hash}; @@ -187,7 +187,11 @@ mod tests { #[test] fn test_basic_transaction_creation() { // Test creating a basic transaction with inputs and outputs - let utxos = vec![test_utxo(100000), test_utxo(200000), test_utxo(300000)]; + let utxos = vec![ + Utxo::new_test(0, 100000, 100, true), + Utxo::new_test(0, 200000, 100, true), + Utxo::new_test(0, 300000, 100, true), + ]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -288,7 +292,8 @@ mod tests { #[test] fn test_transaction_size_estimation() { // Test that transaction size estimation is accurate - let utxos = vec![test_utxo(100000), test_utxo(200000)]; + let utxos = + vec![Utxo::new_test(0, 100000, 100, true), Utxo::new_test(0, 200000, 100, true)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -323,7 +328,7 @@ mod tests { #[test] fn test_fee_calculation() { // Test that fees are calculated correctly - let utxos = vec![test_utxo(1000000)]; + let utxos = vec![Utxo::new_test(0, 1000000, 100, true)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -357,7 +362,7 @@ mod tests { #[test] fn test_insufficient_funds() { // Test that insufficient funds returns an error - let utxos = vec![test_utxo(10000)]; + let utxos = vec![Utxo::new_test(0, 100000, 100, true)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -381,7 +386,7 @@ mod tests { #[test] fn test_exact_change_no_change_output() { // Test when the exact amount is used (no change output needed) - let utxos = vec![test_utxo(150226)]; // Exact amount for output + fee + let utxos = vec![Utxo::new_test(0, 150226, 100, true)]; // Exact amount for output + fee let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() diff --git a/key-wallet/tests/test_optimal_consolidation.rs b/key-wallet/tests/test_optimal_consolidation.rs index 02b6afd10..c05eb17eb 100644 --- a/key-wallet/tests/test_optimal_consolidation.rs +++ b/key-wallet/tests/test_optimal_consolidation.rs @@ -1,4 +1,4 @@ -use key_wallet::test_utils::test_utxo2; +use key_wallet::Utxo; // Test for OptimalConsolidation coin selection strategy #[test] @@ -8,12 +8,12 @@ fn test_optimal_consolidation_strategy() { // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - test_utxo2(100, true), - test_utxo2(200, true), - test_utxo2(300, true), - test_utxo2(500, true), - test_utxo2(1000, true), - test_utxo2(2000, true), + Utxo::new_test(0, 100, 100, true), + Utxo::new_test(0, 200, 100, true), + Utxo::new_test(0, 300, 100, true), + Utxo::new_test(0, 500, 100, true), + Utxo::new_test(0, 1000, 100, true), + Utxo::new_test(0, 2000, 100, true), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation); From 234db8db9766ddca6768eea2cd76d64e69deb242 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Wed, 7 Jan 2026 00:22:42 +0100 Subject: [PATCH 6/7] Just some formatting --- key-wallet-ffi/src/utxo_tests.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/key-wallet-ffi/src/utxo_tests.rs b/key-wallet-ffi/src/utxo_tests.rs index 77d2a5d1a..4e89694d2 100644 --- a/key-wallet-ffi/src/utxo_tests.rs +++ b/key-wallet-ffi/src/utxo_tests.rs @@ -312,11 +312,9 @@ mod utxo_tests { ); let utxos = Utxo::new_test_batch(0..2, 10000, 100, false); - for utxo in utxos { bip44_account.utxos.insert(utxo.outpoint, utxo); } - managed_info.accounts.insert(bip44_account); // Create BIP32 account with 1 UTXO @@ -340,11 +338,9 @@ mod utxo_tests { ); let utxos = Utxo::new_test_batch(10..11, 20000, 200, false); - for utxo in utxos { bip32_account.utxos.insert(utxo.outpoint, utxo); } - managed_info.accounts.insert(bip32_account); // Create CoinJoin account with 2 UTXOs @@ -361,11 +357,9 @@ mod utxo_tests { ); let utxos = Utxo::new_test_batch(20..22, 30000, 300, false); - for utxo in utxos { coinjoin_account.utxos.insert(utxo.outpoint, utxo); } - managed_info.accounts.insert(coinjoin_account); let ffi_managed_info = Box::into_raw(Box::new(FFIManagedWalletInfo::new(managed_info))); @@ -422,11 +416,9 @@ mod utxo_tests { ); let utxos = Utxo::new_test_batch(1..2, 10000, 100, false); - for utxo in utxos { testnet_account.utxos.insert(utxo.outpoint, utxo); } - managed_info.accounts.insert(testnet_account); let ffi_managed_info = Box::into_raw(Box::new(FFIManagedWalletInfo::new(managed_info))); From 4e232172e742bc6ff35c8fafa3cbd5e807e81d63 Mon Sep 17 00:00:00 2001 From: xdustinface Date: Wed, 7 Jan 2026 01:17:49 +0100 Subject: [PATCH 7/7] Make `is_coinbase` also part of the constructors --- key-wallet-ffi/src/utxo_tests.rs | 8 ++--- key-wallet/src/test_utils/utxo.rs | 7 ++-- key-wallet/src/utxo.rs | 6 ++-- .../managed_wallet_info/coin_selection.rs | 33 ++++++++++--------- .../transaction_builder.rs | 26 ++++++++------- .../transaction_building.rs | 18 +++++----- .../tests/test_optimal_consolidation.rs | 12 +++---- 7 files changed, 59 insertions(+), 51 deletions(-) diff --git a/key-wallet-ffi/src/utxo_tests.rs b/key-wallet-ffi/src/utxo_tests.rs index 4e89694d2..422c71b4a 100644 --- a/key-wallet-ffi/src/utxo_tests.rs +++ b/key-wallet-ffi/src/utxo_tests.rs @@ -311,7 +311,7 @@ mod utxo_tests { false, ); - let utxos = Utxo::new_test_batch(0..2, 10000, 100, false); + let utxos = Utxo::new_test_batch(0..2, 10000, 100, false, false); for utxo in utxos { bip44_account.utxos.insert(utxo.outpoint, utxo); } @@ -337,7 +337,7 @@ mod utxo_tests { false, ); - let utxos = Utxo::new_test_batch(10..11, 20000, 200, false); + let utxos = Utxo::new_test_batch(10..11, 20000, 200, false, false); for utxo in utxos { bip32_account.utxos.insert(utxo.outpoint, utxo); } @@ -356,7 +356,7 @@ mod utxo_tests { false, ); - let utxos = Utxo::new_test_batch(20..22, 30000, 300, false); + let utxos = Utxo::new_test_batch(20..22, 30000, 300, false, false); for utxo in utxos { coinjoin_account.utxos.insert(utxo.outpoint, utxo); } @@ -415,7 +415,7 @@ mod utxo_tests { false, ); - let utxos = Utxo::new_test_batch(1..2, 10000, 100, false); + let utxos = Utxo::new_test_batch(1..2, 10000, 100, false, false); for utxo in utxos { testnet_account.utxos.insert(utxo.outpoint, utxo); } diff --git a/key-wallet/src/test_utils/utxo.rs b/key-wallet/src/test_utils/utxo.rs index e4080bfc1..1a6faa2f7 100644 --- a/key-wallet/src/test_utils/utxo.rs +++ b/key-wallet/src/test_utils/utxo.rs @@ -5,14 +5,15 @@ use dashcore::{OutPoint, ScriptBuf, TxOut, Txid}; use crate::{test_utils::test_address, Utxo}; impl Utxo { - pub fn new_test(id: u8, value: u64, height: u32, confirmed: bool) -> Self { - Self::new_test_batch(id..id + 1, value, height, confirmed).remove(0) + pub fn new_test(id: u8, value: u64, height: u32, coinbase: bool, confirmed: bool) -> Self { + Self::new_test_batch(id..id + 1, value, height, coinbase, confirmed).remove(0) } pub fn new_test_batch( ids_range: Range, value: u64, height: u32, + coinbase: bool, confirmed: bool, ) -> Vec { ids_range @@ -25,7 +26,7 @@ impl Utxo { script_pubkey: ScriptBuf::new(), }; - let mut utxo = Utxo::new(outpoint, txout, test_address(), height, false); + let mut utxo = Utxo::new(outpoint, txout, test_address(), height, coinbase); utxo.is_confirmed = confirmed; utxo }) diff --git a/key-wallet/src/utxo.rs b/key-wallet/src/utxo.rs index 58849fdae..8b187aca7 100644 --- a/key-wallet/src/utxo.rs +++ b/key-wallet/src/utxo.rs @@ -310,7 +310,7 @@ mod tests { #[test] fn test_utxo_spendability() { - let mut utxo = Utxo::new_test(0, 100000, 100, false); + let mut utxo = Utxo::new_test(0, 100000, 100, false, false); // Unconfirmed UTXO should not be spendable assert!(!utxo.is_spendable(200)); @@ -328,8 +328,8 @@ mod tests { fn test_utxo_set_operations() { let mut set = UtxoSet::new(); - let utxo1 = Utxo::new_test(0, 100000, 100, false); - let utxo2 = Utxo::new_test(1, 200000, 150, false); + let utxo1 = Utxo::new_test(0, 100000, 100, false, false); + let utxo2 = Utxo::new_test(1, 200000, 150, false, false); set.add(utxo1.clone()); set.add(utxo2.clone()); diff --git a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs index e51a417f5..4432cf8e6 100644 --- a/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs +++ b/key-wallet/src/wallet/managed_wallet_info/coin_selection.rs @@ -694,10 +694,10 @@ mod tests { #[test] fn test_smallest_first_selection() { let utxos = vec![ - Utxo::new_test(0, 10000, 100, true), - Utxo::new_test(0, 20000, 100, true), - Utxo::new_test(0, 30000, 100, true), - Utxo::new_test(0, 40000, 100, true), + Utxo::new_test(0, 10000, 100, false, true), + Utxo::new_test(0, 20000, 100, false, true), + Utxo::new_test(0, 30000, 100, false, true), + Utxo::new_test(0, 40000, 100, false, true), ]; let selector = CoinSelector::new(SelectionStrategy::SmallestFirst); @@ -712,10 +712,10 @@ mod tests { #[test] fn test_largest_first_selection() { let utxos = vec![ - Utxo::new_test(0, 10000, 100, true), - Utxo::new_test(0, 20000, 100, true), - Utxo::new_test(0, 30000, 100, true), - Utxo::new_test(0, 40000, 100, true), + Utxo::new_test(0, 10000, 100, false, true), + Utxo::new_test(0, 20000, 100, false, true), + Utxo::new_test(0, 30000, 100, false, true), + Utxo::new_test(0, 40000, 100, false, true), ]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); @@ -728,7 +728,10 @@ mod tests { #[test] fn test_insufficient_funds() { - let utxos = vec![Utxo::new_test(0, 10000, 100, true), Utxo::new_test(0, 20000, 100, true)]; + let utxos = vec![ + Utxo::new_test(0, 10000, 100, false, true), + Utxo::new_test(0, 20000, 100, false, true), + ]; let selector = CoinSelector::new(SelectionStrategy::LargestFirst); let result = selector.select_coins(&utxos, 50000, FeeRate::new(1000), 200); @@ -740,12 +743,12 @@ mod tests { fn test_optimal_consolidation_strategy() { // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - Utxo::new_test(0, 100, 100, true), - Utxo::new_test(0, 200, 100, true), - Utxo::new_test(0, 300, 100, true), - Utxo::new_test(0, 500, 100, true), - Utxo::new_test(0, 1000, 100, true), - Utxo::new_test(0, 2000, 100, true), + Utxo::new_test(0, 100, 100, false, true), + Utxo::new_test(0, 200, 100, false, true), + Utxo::new_test(0, 300, 100, false, true), + Utxo::new_test(0, 500, 100, false, true), + Utxo::new_test(0, 1000, 100, false, true), + Utxo::new_test(0, 2000, 100, false, true), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs index d66010fee..c2c497732 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_builder.rs @@ -843,7 +843,7 @@ mod tests { #[test] fn test_transaction_builder_basic() { - let utxo = Utxo::new_test(0, 100000, 100, true); + let utxo = Utxo::new_test(0, 100000, 100, false, true); let destination = test_address(); let change = test_address(); @@ -862,7 +862,7 @@ mod tests { #[test] fn test_insufficient_funds() { - let utxo = Utxo::new_test(0, 10000, 100, true); + let utxo = Utxo::new_test(0, 10000, 100, false, true); let destination = test_address(); let result = TransactionBuilder::new() @@ -928,8 +928,10 @@ mod tests { #[test] fn test_transaction_size_estimation() { // Test that transaction size estimation is accurate - let utxos = - vec![Utxo::new_test(0, 100000, 100, true), Utxo::new_test(0, 200000, 100, true)]; + let utxos = vec![ + Utxo::new_test(0, 100000, 100, false, true), + Utxo::new_test(0, 200000, 100, false, true), + ]; let recipient_address = test_address(); let change_address = test_address(); @@ -963,7 +965,7 @@ mod tests { #[test] fn test_fee_calculation() { // Test that fees are calculated correctly - let utxos = vec![Utxo::new_test(0, 1000000, 100, true)]; + let utxos = vec![Utxo::new_test(0, 1000000, 100, false, true)]; let recipient_address = test_address(); let change_address = test_address(); @@ -990,7 +992,7 @@ mod tests { #[test] fn test_exact_change_no_change_output() { // Test when the exact amount is used (no change output needed) - let utxos = vec![Utxo::new_test(0, 150226, 100, true)]; // Exact amount for output + fee + let utxos = vec![Utxo::new_test(0, 150226, 100, false, true)]; // Exact amount for output + fee let recipient_address = test_address(); let change_address = test_address(); @@ -1012,7 +1014,7 @@ mod tests { #[test] fn test_special_payload_size_calculations() { // Test that special payload sizes are calculated correctly - let utxo = Utxo::new_test(0, 100000, 100, true); + let utxo = Utxo::new_test(0, 100000, 100, false, true); let destination = test_address(); let change = test_address(); @@ -1077,7 +1079,7 @@ mod tests { #[test] fn test_build_with_payload_override() { // Test that build_with_payload overrides set_special_payload - let utxo = Utxo::new_test(0, 100000, 100, true); + let utxo = Utxo::new_test(0, 100000, 100, false, true); let destination = test_address(); let change = test_address(); @@ -1123,7 +1125,7 @@ mod tests { #[test] fn test_bip69_output_ordering() { // Test that outputs are sorted according to BIP-69 - let utxo = Utxo::new_test(0, 1000000, 100, true); + let utxo = Utxo::new_test(0, 1000000, 100, false, true); let address1 = test_address(); let address2 = Address::p2pkh( &dashcore::PublicKey::from_slice(&[ @@ -1243,9 +1245,9 @@ mod tests { fn test_coin_selection_with_special_payload() { // Test that coin selection considers special payload size let utxos = vec![ - Utxo::new_test(0, 50000, 100, true), - Utxo::new_test(0, 60000, 100, true), - Utxo::new_test(0, 70000, 100, true), + Utxo::new_test(0, 50000, 100, false, true), + Utxo::new_test(0, 60000, 100, false, true), + Utxo::new_test(0, 70000, 100, false, true), ]; let recipient_address = test_address(); diff --git a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs index d4e816c28..b87b5d41a 100644 --- a/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs +++ b/key-wallet/src/wallet/managed_wallet_info/transaction_building.rs @@ -188,9 +188,9 @@ mod tests { fn test_basic_transaction_creation() { // Test creating a basic transaction with inputs and outputs let utxos = vec![ - Utxo::new_test(0, 100000, 100, true), - Utxo::new_test(0, 200000, 100, true), - Utxo::new_test(0, 300000, 100, true), + Utxo::new_test(0, 100000, 100, false, true), + Utxo::new_test(0, 200000, 100, false, true), + Utxo::new_test(0, 300000, 100, false, true), ]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") @@ -292,8 +292,10 @@ mod tests { #[test] fn test_transaction_size_estimation() { // Test that transaction size estimation is accurate - let utxos = - vec![Utxo::new_test(0, 100000, 100, true), Utxo::new_test(0, 200000, 100, true)]; + let utxos = vec![ + Utxo::new_test(0, 100000, 100, false, true), + Utxo::new_test(0, 200000, 100, false, true), + ]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -328,7 +330,7 @@ mod tests { #[test] fn test_fee_calculation() { // Test that fees are calculated correctly - let utxos = vec![Utxo::new_test(0, 1000000, 100, true)]; + let utxos = vec![Utxo::new_test(0, 1000000, 100, false, true)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -362,7 +364,7 @@ mod tests { #[test] fn test_insufficient_funds() { // Test that insufficient funds returns an error - let utxos = vec![Utxo::new_test(0, 100000, 100, true)]; + let utxos = vec![Utxo::new_test(0, 100000, 100, false, true)]; let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() @@ -386,7 +388,7 @@ mod tests { #[test] fn test_exact_change_no_change_output() { // Test when the exact amount is used (no change output needed) - let utxos = vec![Utxo::new_test(0, 150226, 100, true)]; // Exact amount for output + fee + let utxos = vec![Utxo::new_test(0, 150226, 100, false, true)]; // Exact amount for output + fee let recipient_address = Address::from_str("yTb47qEBpNmgXvYYsHEN4nh8yJwa5iC4Cs") .unwrap() diff --git a/key-wallet/tests/test_optimal_consolidation.rs b/key-wallet/tests/test_optimal_consolidation.rs index c05eb17eb..aa5a1945f 100644 --- a/key-wallet/tests/test_optimal_consolidation.rs +++ b/key-wallet/tests/test_optimal_consolidation.rs @@ -8,12 +8,12 @@ fn test_optimal_consolidation_strategy() { // Test that OptimalConsolidation strategy works correctly let utxos = vec![ - Utxo::new_test(0, 100, 100, true), - Utxo::new_test(0, 200, 100, true), - Utxo::new_test(0, 300, 100, true), - Utxo::new_test(0, 500, 100, true), - Utxo::new_test(0, 1000, 100, true), - Utxo::new_test(0, 2000, 100, true), + Utxo::new_test(0, 100, 100, false, true), + Utxo::new_test(0, 200, 100, false, true), + Utxo::new_test(0, 300, 100, false, true), + Utxo::new_test(0, 500, 100, false, true), + Utxo::new_test(0, 1000, 100, false, true), + Utxo::new_test(0, 2000, 100, false, true), ]; let selector = CoinSelector::new(SelectionStrategy::OptimalConsolidation);