Skip to content

Commit

Permalink
most changes (#241)
Browse files Browse the repository at this point in the history
Co-authored-by: tyshkor <[email protected]>
  • Loading branch information
tyshko5 and tyshkor authored Oct 27, 2022
1 parent bfd7e38 commit 69ee2c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 77 deletions.
76 changes: 10 additions & 66 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ripemd = ["ripemd-rs"]
[dependencies]
parity-scale-codec = { version = "3.0.0", default-features = false, features = ["derive"], optional = true }
quickcheck = { version = "1.0.3", optional = true }
rand = { version = "0.7.3", optional = true, features = ["small_rng"] }
rand = { version = "0.8.5", optional = true, features = ["small_rng"] }
serde = { version = "1.0.116", optional = true, default-features = false, features = ["derive"] }
serde-big-array = { version = "0.3.2", optional = true, features = ["const-generics"] }
multihash-derive = { version = "0.8.0", path = "derive", default-features = false, optional = true }
Expand All @@ -61,7 +61,7 @@ criterion = "0.3.3"
hex = "0.4.2"
serde_json = "1.0.58"
quickcheck = "1.0.3"
rand = "0.7.3"
rand = "0.8.5"
arbitrary = "1.1.0"
multihash = { path = ".", features = ["sha1", "strobe"] }

Expand Down
18 changes: 9 additions & 9 deletions src/arb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ impl<const S: usize> quickcheck::Arbitrary for MultihashGeneric<S> {
let dist = WeightedIndex::new(weights.iter()).unwrap();
let mut rng = rand::rngs::SmallRng::seed_from_u64(u64::arbitrary(g));
let code = match dist.sample(&mut rng) {
0 => rng.gen_range(0, u64::pow(2, 7)),
1 => rng.gen_range(u64::pow(2, 7), u64::pow(2, 14)),
2 => rng.gen_range(u64::pow(2, 14), u64::pow(2, 21)),
3 => rng.gen_range(u64::pow(2, 21), u64::pow(2, 28)),
4 => rng.gen_range(u64::pow(2, 28), u64::pow(2, 35)),
5 => rng.gen_range(u64::pow(2, 35), u64::pow(2, 42)),
6 => rng.gen_range(u64::pow(2, 42), u64::pow(2, 49)),
7 => rng.gen_range(u64::pow(2, 56), u64::pow(2, 63)),
0 => rng.gen_range(0..u64::pow(2, 7)),
1 => rng.gen_range(u64::pow(2, 7)..u64::pow(2, 14)),
2 => rng.gen_range(u64::pow(2, 14)..u64::pow(2, 21)),
3 => rng.gen_range(u64::pow(2, 21)..u64::pow(2, 28)),
4 => rng.gen_range(u64::pow(2, 28)..u64::pow(2, 35)),
5 => rng.gen_range(u64::pow(2, 35)..u64::pow(2, 42)),
6 => rng.gen_range(u64::pow(2, 42)..u64::pow(2, 49)),
7 => rng.gen_range(u64::pow(2, 56)..u64::pow(2, 63)),
_ => unreachable!(),
};

// Maximum size is S byte due to the generic.
let size = rng.gen_range(0, S);
let size = rng.gen_range(0..S);
let mut data = [0; S];
rng.fill_bytes(&mut data);
MultihashGeneric::wrap(code, &data[..size]).unwrap()
Expand Down

0 comments on commit 69ee2c5

Please sign in to comment.