@@ -690,44 +690,14 @@ impl std::error::Error for SelectionError {}
690690#[ cfg( test) ]
691691mod tests {
692692 use super :: * ;
693- use crate :: Utxo ;
694- use dashcore:: blockdata:: script:: ScriptBuf ;
695- use dashcore:: { Address , Network , OutPoint , TxOut , Txid } ;
696- use dashcore_hashes:: { sha256d, Hash } ;
697-
698- fn test_utxo ( value : u64 , confirmed : bool ) -> Utxo {
699- let outpoint = OutPoint {
700- txid : Txid :: from_raw_hash ( sha256d:: Hash :: from_slice ( & [ 1u8 ; 32 ] ) . unwrap ( ) ) ,
701- vout : 0 ,
702- } ;
703-
704- let txout = TxOut {
705- value,
706- script_pubkey : ScriptBuf :: new ( ) ,
707- } ;
708-
709- let address = Address :: p2pkh (
710- & dashcore:: PublicKey :: from_slice ( & [
711- 0x02 , 0x50 , 0x86 , 0x3a , 0xd6 , 0x4a , 0x87 , 0xae , 0x8a , 0x2f , 0xe8 , 0x3c , 0x1a , 0xf1 ,
712- 0xa8 , 0x40 , 0x3c , 0xb5 , 0x3f , 0x53 , 0xe4 , 0x86 , 0xd8 , 0x51 , 0x1d , 0xad , 0x8a , 0x04 ,
713- 0x88 , 0x7e , 0x5b , 0x23 , 0x52 ,
714- ] )
715- . unwrap ( ) ,
716- Network :: Testnet ,
717- ) ;
718-
719- let mut utxo = Utxo :: new ( outpoint, txout, address, 100 , false ) ;
720- utxo. is_confirmed = confirmed;
721- utxo
722- }
723693
724694 #[ test]
725695 fn test_smallest_first_selection ( ) {
726696 let utxos = vec ! [
727- test_utxo ( 10000 , true ) ,
728- test_utxo ( 20000 , true ) ,
729- test_utxo ( 30000 , true ) ,
730- test_utxo ( 40000 , true ) ,
697+ Utxo :: new_test ( 0 , 10000 , 100 , false , true ) ,
698+ Utxo :: new_test ( 0 , 20000 , 100 , false , true ) ,
699+ Utxo :: new_test ( 0 , 30000 , 100 , false , true ) ,
700+ Utxo :: new_test ( 0 , 40000 , 100 , false , true ) ,
731701 ] ;
732702
733703 let selector = CoinSelector :: new ( SelectionStrategy :: SmallestFirst ) ;
@@ -742,10 +712,10 @@ mod tests {
742712 #[ test]
743713 fn test_largest_first_selection ( ) {
744714 let utxos = vec ! [
745- test_utxo ( 10000 , true ) ,
746- test_utxo ( 20000 , true ) ,
747- test_utxo ( 30000 , true ) ,
748- test_utxo ( 40000 , true ) ,
715+ Utxo :: new_test ( 0 , 10000 , 100 , false , true ) ,
716+ Utxo :: new_test ( 0 , 20000 , 100 , false , true ) ,
717+ Utxo :: new_test ( 0 , 30000 , 100 , false , true ) ,
718+ Utxo :: new_test ( 0 , 40000 , 100 , false , true ) ,
749719 ] ;
750720
751721 let selector = CoinSelector :: new ( SelectionStrategy :: LargestFirst ) ;
@@ -758,7 +728,10 @@ mod tests {
758728
759729 #[ test]
760730 fn test_insufficient_funds ( ) {
761- let utxos = vec ! [ test_utxo( 10000 , true ) , test_utxo( 20000 , true ) ] ;
731+ let utxos = vec ! [
732+ Utxo :: new_test( 0 , 10000 , 100 , false , true ) ,
733+ Utxo :: new_test( 0 , 20000 , 100 , false , true ) ,
734+ ] ;
762735
763736 let selector = CoinSelector :: new ( SelectionStrategy :: LargestFirst ) ;
764737 let result = selector. select_coins ( & utxos, 50000 , FeeRate :: new ( 1000 ) , 200 ) ;
@@ -770,12 +743,12 @@ mod tests {
770743 fn test_optimal_consolidation_strategy ( ) {
771744 // Test that OptimalConsolidation strategy works correctly
772745 let utxos = vec ! [
773- test_utxo ( 100 , true ) ,
774- test_utxo ( 200 , true ) ,
775- test_utxo ( 300 , true ) ,
776- test_utxo ( 500 , true ) ,
777- test_utxo ( 1000 , true ) ,
778- test_utxo ( 2000 , true ) ,
746+ Utxo :: new_test ( 0 , 100 , 100 , false , true ) ,
747+ Utxo :: new_test ( 0 , 200 , 100 , false , true ) ,
748+ Utxo :: new_test ( 0 , 300 , 100 , false , true ) ,
749+ Utxo :: new_test ( 0 , 500 , 100 , false , true ) ,
750+ Utxo :: new_test ( 0 , 1000 , 100 , false , true ) ,
751+ Utxo :: new_test ( 0 , 2000 , 100 , false , true ) ,
779752 ] ;
780753
781754 let selector = CoinSelector :: new ( SelectionStrategy :: OptimalConsolidation ) ;
0 commit comments