Skip to content

Commit

Permalink
Change test thresholds
Browse files Browse the repository at this point in the history
rust-bitcoin changed Amount::MAX to 21 million BTC from u64::MAX.
Therefore adjust the tests to reflect this new range.
  • Loading branch information
yancyribbens committed Jan 7, 2025
1 parent 5c57f68 commit 0c6980e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 31 deletions.
16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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" }
8 changes: 4 additions & 4 deletions src/branch_and_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ pub fn select_coins_bnb<Utxo: WeightedUtxo>(
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)?;

Expand Down Expand Up @@ -564,7 +564,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(&params, None);
Expand All @@ -574,7 +574,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"],
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ pub trait WeightedUtxo {
/// see also:
/// <https://github.com/rust-bitcoin/rust-bitcoin/blob/59c806996ce18e88394eb4e2c265986c8d3a6620/bitcoin/src/blockdata/transaction.rs>
fn effective_value(&self, fee_rate: FeeRate) -> Option<SignedAmount> {
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`.
Expand All @@ -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<SignedAmount> {
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)
}
}
Expand Down
16 changes: 1 addition & 15 deletions src/single_random_draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(&params, 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(&params, Some(&["1 cBTC"]));
}
}

0 comments on commit 0c6980e

Please sign in to comment.