Skip to content

Commit

Permalink
Add test to lib
Browse files Browse the repository at this point in the history
  • Loading branch information
yancyribbens committed Oct 3, 2024
1 parent 7033108 commit a33303a
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,71 @@ mod tests {
}
}

use std::iter::zip;
#[test]
fn select_coins_no_solution() {
let target = Amount::from_sat(255432);
let cost_of_change = Amount::ZERO;
let fee_rate = FeeRate::ZERO;
let lt_fee_rate = FeeRate::ZERO;

let amts = [
27336,
238,
9225,
20540,
35590,
49463,
6331,
35548,
50363,
28009,
];

let weights = [
25350,
106,
3311,
2633,
21081,
35260,
3896,
6377,
6851,
20236
];

let utxos: Vec<_> = zip(amts, weights)
.map(|(a, w)| {
let amt = Amount::from_sat(a);
let tx_out = TxOut {
value: amt,
script_pubkey: vec![].into()
};
let weight = Weight::from_wu(w);

let u = Utxo {
output: tx_out,
satisfaction_weight: weight
};

u
}).collect();

let result = select_coins(
target,
cost_of_change,
fee_rate,
lt_fee_rate,
&utxos,
);

// This yields no solution because:
// * BnB fails because the sum overage is greater than ost_of_change
// * SRD fails because the sum is greater the utxo sum + CHANGE_LOWER
assert!(result.is_none());
}

#[test]
fn select_coins_proptest() {
arbtest(|u| {
Expand Down

0 comments on commit a33303a

Please sign in to comment.