From 7b24ab6c97ac75c5de9ef3864acb3b0ae8f1d52b Mon Sep 17 00:00:00 2001 From: yancy Date: Sat, 14 Dec 2024 16:56:05 -0600 Subject: [PATCH] Change test thresholds rust-bitcoin changed Amount::MAX to 21 million BTC from u64::MAX. Therefore adjust the tests to reflect this new range. --- Cargo.toml | 16 ++++++++-------- src/branch_and_bound.rs | 8 ++++---- src/lib.rs | 8 ++++---- src/single_random_draw.rs | 18 ++---------------- 4 files changed, 18 insertions(+), 32 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3d103bc..2ea7675 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ readme = "README.md" rust-version = "1.63.0" [dependencies] -bitcoin = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } +bitcoin = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } rand = {version = "0.8.5", default-features = false, optional = true} [dev-dependencies] @@ -29,10 +29,10 @@ harness = false [patch.crates-io] -bitcoin_hashes = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -base58ck = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -bitcoin-internals = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -bitcoin-io = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -bitcoin-primitives = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -bitcoin-addresses = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } -bitcoin-units = { git = "https://github.com/rust-bitcoin/rust-bitcoin.git" } +bitcoin_hashes = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +base58ck = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +bitcoin-internals = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +bitcoin-io = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +bitcoin-primitives = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +bitcoin-addresses = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } +bitcoin-units = { git = "https://github.com/yancyribbens/rust-bitcoin", rev = "ad123dadcd5980e2e88db6afdf5ab40602240f1b" } diff --git a/src/branch_and_bound.rs b/src/branch_and_bound.rs index e7e9f4f..9caf52a 100644 --- a/src/branch_and_bound.rs +++ b/src/branch_and_bound.rs @@ -234,8 +234,8 @@ pub fn select_coins_bnb( else if value >= target { backtrack = true; - let v = value.to_signed().ok()?; - let t = target.to_signed().ok()?; + let v = value.to_signed(); + let t = target.to_signed(); let waste: SignedAmount = v.checked_sub(t)?; current_waste = current_waste.checked_add(waste)?; @@ -565,7 +565,7 @@ mod tests { cost_of_change: "0", fee_rate: "0", lt_fee_rate: "0", - weighted_utxos: vec!["18446744073709551615 sats", "1 sats"], // [u64::MAX, 1 sat] + weighted_utxos: vec!["2100000000000000 sat", "1 sats"], // Amount::MAX }; assert_coin_select_params(¶ms, None); @@ -575,7 +575,7 @@ mod tests { fn select_coins_bnb_upper_bound_overflow() { let params = ParamsStr { target: "1 sats", - cost_of_change: "18446744073709551615 sats", // u64::MAX + cost_of_change: "2100000000000000 sat", // u64::MAX fee_rate: "0", lt_fee_rate: "0", weighted_utxos: vec!["1 sats"], diff --git a/src/lib.rs b/src/lib.rs index 5f5867d..8c93a0f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,8 +61,8 @@ pub trait WeightedUtxo { /// see also: /// fn effective_value(&self, fee_rate: FeeRate) -> Option { - let signed_input_fee = self.calculate_fee(fee_rate)?.to_signed().ok()?; - self.value().to_signed().ok()?.checked_sub(signed_input_fee) + let signed_input_fee = self.calculate_fee(fee_rate)?.to_signed(); + self.value().to_signed().checked_sub(signed_input_fee) } /// Computes the fee to spend this `Utxo`. @@ -78,8 +78,8 @@ pub trait WeightedUtxo { /// The waste is the difference of the fee to spend this `Utxo` now compared with the expected /// fee to spend in the future (long_term_fee_rate). fn waste(&self, fee_rate: FeeRate, long_term_fee_rate: FeeRate) -> Option { - let fee: SignedAmount = self.calculate_fee(fee_rate)?.to_signed().ok()?; - let lt_fee: SignedAmount = self.calculate_fee(long_term_fee_rate)?.to_signed().ok()?; + let fee: SignedAmount = self.calculate_fee(fee_rate)?.to_signed(); + let lt_fee: SignedAmount = self.calculate_fee(long_term_fee_rate)?.to_signed(); fee.checked_sub(lt_fee) } } diff --git a/src/single_random_draw.rs b/src/single_random_draw.rs index c6a3dac..416aa1c 100644 --- a/src/single_random_draw.rs +++ b/src/single_random_draw.rs @@ -56,7 +56,7 @@ pub fn select_coins_srd<'a, R: rand::Rng + ?Sized, Utxo: WeightedUtxo>( result.clear(); - let threshold = target + CHANGE_LOWER; + let threshold = target.checked_add(CHANGE_LOWER)?; let mut value = Amount::ZERO; for w_utxo in origin { @@ -265,25 +265,11 @@ mod tests { #[test] fn select_coins_srd_threshold_overflow() { let params = ParamsStr { - target: "18446744073709551615 sat", // u64::MAX + target: "2100000000000000 sat", // Amount::MAX fee_rate: "10", weighted_utxos: vec!["1 cBTC/18446744073709551615"], }; assert_coin_select_params(¶ms, None); } - - #[test] - fn select_coins_srd_none_effective_value() { - let params = ParamsStr { - target: ".95 cBTC", - fee_rate: "0", - weighted_utxos: vec![ - "1 cBTC", - "9223372036854775808 sat", //i64::MAX + 1 - ], - }; - - assert_coin_select_params(¶ms, Some(&["1 cBTC"])); - } }