File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -310,6 +310,8 @@ mod tests {
310
310
use bitcoin:: TxOut ;
311
311
use bitcoin:: Weight ;
312
312
use core:: str:: FromStr ;
313
+ use std:: iter:: once;
314
+ use std:: iter:: zip;
313
315
314
316
fn create_weighted_utxos ( fee : Amount ) -> Vec < WeightedUtxo > {
315
317
let amts = [
@@ -719,4 +721,35 @@ mod tests {
719
721
assert_eq ! ( list[ 1 ] . utxo. value, Amount :: from_str( "6 cBTC" ) . unwrap( ) ) ;
720
722
assert_eq ! ( list[ 2 ] . utxo. value, Amount :: from_str( "2 cBTC" ) . unwrap( ) ) ;
721
723
}
724
+
725
+ #[ test]
726
+ fn select_coins_bnb_exhaust ( ) {
727
+ let base: usize = 2 ;
728
+ let alpha = ( 0 ..17 ) . enumerate ( ) . map ( |( i, _) | base. pow ( 17 + i as u32 ) ) ;
729
+ let target = Amount :: from_sat ( alpha. clone ( ) . sum :: < usize > ( ) as u64 ) ;
730
+
731
+ let beta = ( 0 ..17 ) . enumerate ( ) . map ( |( i, _) | {
732
+ let a = base. pow ( 17 + i as u32 ) ;
733
+ let b = base. pow ( 16 - i as u32 ) ;
734
+ a + b
735
+ } ) ;
736
+
737
+ let vals: Vec < _ > = zip ( alpha, beta)
738
+ // flatten requires iterable types.
739
+ // use once() to make tuple iterable.
740
+ . flat_map ( |tup| once ( tup. 0 ) . chain ( once ( tup. 1 ) ) )
741
+ . map ( |a| Amount :: from_sat ( a as u64 ) )
742
+ . collect ( ) ;
743
+
744
+ let weighted_utxos = create_weighted_utxos_from_values ( vals) ;
745
+ let list = select_coins_bnb (
746
+ target,
747
+ Amount :: ONE_SAT ,
748
+ FeeRate :: ZERO ,
749
+ FeeRate :: ZERO ,
750
+ & weighted_utxos,
751
+ ) ;
752
+
753
+ assert ! ( list. is_none( ) ) ;
754
+ }
722
755
}
You can’t perform that action at this time.
0 commit comments