Skip to content

Commit

Permalink
fixup: Add test that both exhuasts and returns a result
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Mar 8, 2024
1 parent a5cbf1f commit 0114f2a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 0114f2a

Please sign in to comment.