diff --git a/src/branch_and_bound.rs b/src/branch_and_bound.rs index 2def678..915e4af 100644 --- a/src/branch_and_bound.rs +++ b/src/branch_and_bound.rs @@ -827,4 +827,35 @@ mod tests { assert!(list.is_none()); } + + #[test] + fn select_coins_bnb_exhaust_with_result() { + // This returns a result AND hits the iteration exhaust limit. + + // Takes 163,819 iterations (hits the iteration limit). + let base: usize = 2; + let mut target = 0; + let vals = (0..15).enumerate().flat_map(|(i, _)| { + let a = base.pow(15 + i as u32) as u64; + target += a; + vec![a, a + 2] + }); + + let mut vals: Vec<_> = vals.map(Amount::from_sat).collect(); + + // Add a value that will match the target before iteration exhaustion occurs. + vals.push(Amount::from_sat(target)); + let weighted_utxos = create_weighted_utxos_from_values(vals); + let mut list = select_coins_bnb( + Amount::from_sat(target), + Amount::ONE_SAT, + FeeRate::ZERO, + FeeRate::ZERO, + &weighted_utxos, + ) + .unwrap(); + + assert_eq!(list.len(), 1); + assert_eq!(list.next().unwrap().utxo.value, Amount::from_sat(target)); + } }