@@ -341,39 +341,24 @@ mod tests {
341
341
weighted_utxos : Vec < & ' a str > ,
342
342
}
343
343
344
- fn build_pool ( fee : Amount ) -> Vec < Utxo > {
345
- let amts = [
346
- Amount :: from_str ( "1 cBTC" ) . unwrap ( ) + fee,
347
- Amount :: from_str ( "2 cBTC" ) . unwrap ( ) + fee,
348
- Amount :: from_str ( "3 cBTC" ) . unwrap ( ) + fee,
349
- Amount :: from_str ( "4 cBTC" ) . unwrap ( ) + fee,
350
- ] ;
351
-
352
- let mut pool = vec ! [ ] ;
353
-
354
- for a in amts {
355
- let utxo = Utxo :: new ( a, Weight :: ZERO ) ;
356
- pool. push ( utxo) ;
357
- }
358
-
359
- pool
344
+ fn build_pool ( ) -> UtxoPool {
345
+ let utxo_str_list = vec ! [ "1 cBTC" , "2 cBTC" , "3 cBTC" , "4 cBTC" ] ;
346
+ UtxoPool :: from_str_list ( & utxo_str_list)
360
347
}
361
348
362
349
fn assert_coin_select ( target_str : & str , expected_inputs_str : & [ & str ] ) {
363
- let fee = Amount :: ZERO ;
364
350
let target = Amount :: from_str ( target_str) . unwrap ( ) ;
365
- let utxos = build_pool ( fee ) ;
351
+ let pool = build_pool ( ) ;
366
352
let inputs: Vec < Utxo > =
367
- select_coins_bnb ( target, Amount :: ZERO , FeeRate :: ZERO , FeeRate :: ZERO , & utxos)
353
+ select_coins_bnb ( target, Amount :: ZERO , FeeRate :: ZERO , FeeRate :: ZERO , & pool . utxos )
368
354
. unwrap ( )
369
355
. cloned ( )
370
356
. collect ( ) ;
371
- let expected_inputs: Vec < Utxo > =
372
- expected_inputs_str. iter ( ) . map ( |s| Utxo :: from_str ( s) . unwrap ( ) ) . collect ( ) ;
373
- assert_eq ! ( expected_inputs, inputs) ;
357
+ let expected_inputs: UtxoPool = UtxoPool :: from_str_list ( expected_inputs_str) ;
358
+ assert_eq ! ( expected_inputs. utxos, inputs) ;
374
359
}
375
360
376
- fn assert_coin_select_params ( p : & ParamsStr , expected_inputs : Option < & [ & str ] > ) {
361
+ fn assert_coin_select_params ( p : & ParamsStr , expected_inputs_str : Option < & [ & str ] > ) {
377
362
let fee_rate = p. fee_rate . parse :: < u64 > ( ) . unwrap ( ) ; // would be nice if FeeRate had
378
363
// from_str like Amount::from_str()
379
364
let lt_fee_rate = p. lt_fee_rate . parse :: < u64 > ( ) . unwrap ( ) ;
@@ -383,20 +368,13 @@ mod tests {
383
368
let fee_rate = FeeRate :: from_sat_per_kwu ( fee_rate) ;
384
369
let lt_fee_rate = FeeRate :: from_sat_per_kwu ( lt_fee_rate) ;
385
370
386
- let w_utxos: Vec < _ > = p
387
- . weighted_utxos
388
- . iter ( )
389
- . map ( |s| Amount :: from_str ( s) . unwrap ( ) )
390
- . map ( |a| Utxo :: new ( a, Weight :: ZERO ) )
391
- . collect ( ) ;
392
-
393
- let iter = select_coins_bnb ( target, cost_of_change, fee_rate, lt_fee_rate, & w_utxos) ;
371
+ let pool: UtxoPool = UtxoPool :: from_str_list ( & p. weighted_utxos ) ;
372
+ let iter = select_coins_bnb ( target, cost_of_change, fee_rate, lt_fee_rate, & pool. utxos ) ;
394
373
395
374
if let Some ( i) = iter {
396
375
let inputs: Vec < Utxo > = i. cloned ( ) . collect ( ) ;
397
- let expected_inputs: Vec < Utxo > =
398
- expected_inputs. unwrap ( ) . iter ( ) . map ( |s| Utxo :: from_str ( s) . unwrap ( ) ) . collect ( ) ;
399
- assert_eq ! ( expected_inputs, inputs) ;
376
+ let expected_inputs: UtxoPool = UtxoPool :: from_str_list ( expected_inputs_str. unwrap ( ) ) ;
377
+ assert_eq ! ( expected_inputs. utxos, inputs) ;
400
378
}
401
379
}
402
380
0 commit comments