*: update rand to v0.8.5 (#12962)

* *: update rand to v0.8.5

* *: remove useless deps from Cargo.toml

* fix pallet-session-benchmarking

* fix pallet-election-provider-support test

* remove useless rand from dev-dependencies
This commit is contained in:
Qinxuan Chen
2022-12-19 14:38:51 +08:00
committed by GitHub
parent 9a5f47962f
commit 40c04cf11d
55 changed files with 77 additions and 254 deletions
@@ -12,7 +12,6 @@ description = "PALLET two phase election providers"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
static_assertions = "1.1.0"
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
@@ -35,12 +34,12 @@ frame-election-provider-support = { version = "4.0.0-dev", default-features = fa
# Optional imports for benchmarking
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../benchmarking", optional = true }
pallet-election-provider-support-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../election-provider-support/benchmarking", optional = true }
rand = { version = "0.7.3", default-features = false, features = ["alloc", "small_rng"], optional = true }
rand = { version = "0.8.5", default-features = false, features = ["alloc", "small_rng"], optional = true }
strum = { version = "0.24.1", default-features = false, features = ["derive"], optional = true }
[dev-dependencies]
parking_lot = "0.12.1"
rand = { version = "0.7.3" }
rand = "0.8.5"
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
sp-npos-elections = { version = "4.0.0-dev", default-features = false, path = "../../primitives/npos-elections" }
@@ -24,7 +24,7 @@ sp-std = { version = "5.0.0", default-features = false, path = "../../primitives
sp-core = { version = "7.0.0", default-features = false, path = "../../primitives/core" }
[dev-dependencies]
rand = "0.7.3"
rand = { version = "0.8.5", features = ["small_rng"] }
sp-io = { version = "7.0.0", path = "../../primitives/io" }
sp-npos-elections = { version = "4.0.0-dev", path = "../../primitives/npos-elections" }
@@ -97,7 +97,7 @@ pub fn generate_random_votes(
// it's not interesting if a voter chooses 0 or all candidates, so rule those cases out.
// also, let's not generate any cases which result in a compact overflow.
let n_candidates_chosen =
rng.gen_range(1, candidates.len().min(<TestSolution as crate::NposSolution>::LIMIT));
rng.gen_range(1..candidates.len().min(<TestSolution as crate::NposSolution>::LIMIT));
let mut chosen_candidates = Vec::with_capacity(n_candidates_chosen);
chosen_candidates.extend(candidates.choose_multiple(&mut rng, n_candidates_chosen));
@@ -106,7 +106,7 @@ pub fn generate_random_votes(
// always generate a sensible number of winners: elections are uninteresting if nobody wins,
// or everybody wins
let num_winners = rng.gen_range(1, candidate_count);
let num_winners = rng.gen_range(1..candidate_count);
let mut winners: HashSet<AccountId> = HashSet::with_capacity(num_winners);
winners.extend(candidates.choose_multiple(&mut rng, num_winners));
assert_eq!(winners.len(), num_winners);
@@ -123,7 +123,7 @@ pub fn generate_random_votes(
let mut available_stake = 1000;
let mut stake_distribution = Vec::with_capacity(num_chosen_winners);
for _ in 0..num_chosen_winners - 1 {
let stake = rng.gen_range(0, available_stake).min(1);
let stake = rng.gen_range(0..available_stake).min(1);
stake_distribution.push(TestAccuracy::from_perthousand(stake));
available_stake -= stake;
}
@@ -92,7 +92,7 @@ mod solution_type {
#[test]
fn from_assignment_fail_too_many_voters() {
let rng = rand::rngs::SmallRng::seed_from_u64(0);
let rng = rand::rngs::SmallRng::seed_from_u64(1);
// This will produce 24 voters..
let (voters, assignments, candidates) = generate_random_votes(10, 25, rng);
@@ -13,7 +13,7 @@ readme = "README.md"
targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
rand = { version = "0.7.2", default-features = false }
rand = { version = "0.8.5", default-features = false, features = ["std_rng"] }
frame-benchmarking = { version = "4.0.0-dev", default-features = false, path = "../../benchmarking" }
frame-support = { version = "4.0.0-dev", default-features = false, path = "../../support" }
frame-system = { version = "4.0.0-dev", default-features = false, path = "../../system" }