From a33303a294dc12e03ee43c346242b3dc65b1bb1f Mon Sep 17 00:00:00 2001 From: yancy Date: Thu, 3 Oct 2024 12:12:59 -0500 Subject: [PATCH] Add test to lib --- src/lib.rs | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 289f9b5..a0bf2c3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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| {