Skip to content

Commit

Permalink
Add proptest for arbitrary target
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Jul 29, 2024
1 parent 65cb350 commit 63ce925
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions prop/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,45 @@ proptest! {
let sum: Amount = selection.into_iter().sum();
assert_eq!(target, sum);
}

#[test]
fn test_bnb_arbitrary_target(t in any::<u64>()) {
let target_str = format!("{} cBTC", t % 10);
let target = Amount::from_str(&target_str).unwrap();

let pool: Vec<_> = (1..10)
.map(|i| format!("{} cBTC", i))
.map(|s| Amount::from_str(&s).unwrap())
.map(|a| {
let output = TxOut {
value: a,
script_pubkey: ScriptBuf::new()
};

let satisfaction_weight = Weight::ZERO;

Utxo {
output,
satisfaction_weight
}
})
.collect();

let selection_sum: Amount =
select_coins_bnb(
target,
Amount::ZERO,
FeeRate::ZERO,
FeeRate::ZERO,
&pool)
.unwrap()
.map(|i| i.value()).sum();

assert_eq!(selection_sum, target);
}
}

fn main() {
test_bnb_arbitrary_pool();
test_bnb_arbitrary_target();
}

0 comments on commit 63ce925

Please sign in to comment.