Skip to content

Commit a914f19

Browse files
committed
dependency: bump rand version
`StepRng` is now deprecated, so replace with `SmallRng` using `seed_from_u64(1)` to produce deterministic tests.
1 parent af5f8d6 commit a914f19

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ features = ["rand"]
1818

1919
[dependencies]
2020
bitcoin-units = "1.0.0-rc.0"
21-
rand = { version = "0.8.5", optional = true }
21+
rand = { version = "0.9.2", optional = true }
2222

2323
[dev-dependencies]
2424
bitcoin-units = { version = "1.0.0-rc.0", features = ["arbitrary"] }
2525
criterion = "0.6"
2626
bitcoin-coin-selection = {path = ".", features = ["rand"]}
27-
rand = "0.8.5"
27+
rand = "0.9.2"
2828
arbitrary = { version = "1", features = ["derive"] }
2929
arbtest = "0.3.1"
3030
exhaustigen = "0.1.0"

benches/srd_selection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use bitcoin_coin_selection::{single_random_draw, WeightedUtxo};
22
use bitcoin_units::{Amount, FeeRate, Weight};
33
use criterion::{criterion_group, criterion_main, Criterion};
4-
use rand::thread_rng;
4+
use rand::rng;
55

66
pub fn srd_benchmark(c: &mut Criterion) {
77
let fee_rate = FeeRate::from_sat_per_kwu(10);
@@ -16,7 +16,7 @@ pub fn srd_benchmark(c: &mut Criterion) {
1616
c.bench_function("srd", |b| {
1717
b.iter(|| {
1818
let (iteration_count, inputs) =
19-
single_random_draw(target, max_weight, &mut thread_rng(), &utxos).unwrap();
19+
single_random_draw(target, max_weight, &mut rng(), &utxos).unwrap();
2020
assert_eq!(iteration_count, 1_000);
2121
assert_eq!(inputs.len(), 1_000);
2222
})

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::cmp::Ordering;
2323
use bitcoin_units::{Amount, FeeRate, SignedAmount, Weight};
2424
#[cfg(feature = "rand")]
2525
#[cfg_attr(docsrs, doc(cfg(feature = "rand")))]
26-
use rand::thread_rng;
26+
use rand::rng;
2727

2828
pub use crate::branch_and_bound::branch_and_bound;
2929
pub use crate::coin_grinder::coin_grinder;
@@ -176,7 +176,7 @@ pub fn select_coins<'a, T: IntoIterator<Item = &'a WeightedUtxo> + std::marker::
176176
let bnb_result = branch_and_bound(target, cost_of_change, max_weight, weighted_utxos);
177177

178178
if bnb_result.is_err() {
179-
single_random_draw(target, max_weight, &mut thread_rng(), weighted_utxos)
179+
single_random_draw(target, max_weight, &mut rng(), weighted_utxos)
180180
} else {
181181
bnb_result
182182
}

src/single_random_draw.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,14 @@ mod tests {
108108
use arbitrary::Arbitrary;
109109
use arbtest::arbtest;
110110
use bitcoin_units::Amount;
111-
use rand::rngs::mock::StepRng;
112-
111+
113112
use super::*;
114113
use crate::single_random_draw::single_random_draw;
115114
use crate::tests::{assert_ref_eq, parse_fee_rate, Selection};
116115

116+
use rand::rngs::SmallRng;
117+
use rand::SeedableRng;
118+
117119
#[derive(Debug)]
118120
pub struct TestSRD<'a> {
119121
target: &'a str,
@@ -167,7 +169,7 @@ mod tests {
167169
.assert();
168170
}
169171

170-
fn get_rng() -> StepRng {
172+
fn get_rng() -> SmallRng {
171173
// [1, 2]
172174
// let mut vec: Vec<u32> = (1..3).collect();
173175
// let mut rng = StepRng::new(0, 0);
@@ -178,7 +180,7 @@ mod tests {
178180
// shuffle() will always result in the order described above when a constant
179181
// is used as the rng. The first is removed from the beginning and added to
180182
// the end while the remaining elements keep their order.
181-
StepRng::new(0, 0)
183+
SmallRng::seed_from_u64(1)
182184
}
183185

184186
#[test]

0 commit comments

Comments
 (0)