mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-07-17 06:35:42 +00:00
Run cargo fmt on the whole code base (#9394)
* Run cargo fmt on the whole code base * Second run * Add CI check * Fix compilation * More unnecessary braces * Handle weights * Use --all * Use correct attributes... * Fix UI tests * AHHHHHHHHH * 🤦 * Docs * Fix compilation * 🤷 * Please stop * 🤦 x 2 * More * make rustfmt.toml consistent with polkadot Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -34,8 +34,8 @@ use honggfuzz::fuzz;
|
||||
|
||||
mod common;
|
||||
use common::to_range;
|
||||
use sp_npos_elections::{reduce, to_support_map, ExtendedBalance, StakedAssignment};
|
||||
use rand::{self, Rng, RngCore, SeedableRng};
|
||||
use sp_npos_elections::{reduce, to_support_map, ExtendedBalance, StakedAssignment};
|
||||
|
||||
type Balance = u128;
|
||||
type AccountId = u64;
|
||||
@@ -50,13 +50,8 @@ fn main() {
|
||||
let rng = rand::rngs::SmallRng::seed_from_u64(seed);
|
||||
target_count = to_range(target_count, 100, 1000);
|
||||
voter_count = to_range(voter_count, 100, 2000);
|
||||
let (assignments, winners) = generate_random_phragmen_assignment(
|
||||
voter_count,
|
||||
target_count,
|
||||
8,
|
||||
8,
|
||||
rng
|
||||
);
|
||||
let (assignments, winners) =
|
||||
generate_random_phragmen_assignment(voter_count, target_count, 8, 8, rng);
|
||||
reduce_and_compare(&assignments, &winners);
|
||||
});
|
||||
}
|
||||
@@ -82,23 +77,27 @@ fn generate_random_phragmen_assignment(
|
||||
|
||||
(1..=voter_count).for_each(|acc| {
|
||||
let mut targets_to_chose_from = all_targets.clone();
|
||||
let targets_to_chose = if edge_per_voter_var > 0 { rng.gen_range(
|
||||
avg_edge_per_voter - edge_per_voter_var,
|
||||
avg_edge_per_voter + edge_per_voter_var,
|
||||
) } else { avg_edge_per_voter };
|
||||
let targets_to_chose = if edge_per_voter_var > 0 {
|
||||
rng.gen_range(
|
||||
avg_edge_per_voter - edge_per_voter_var,
|
||||
avg_edge_per_voter + edge_per_voter_var,
|
||||
)
|
||||
} else {
|
||||
avg_edge_per_voter
|
||||
};
|
||||
|
||||
let distribution = (0..targets_to_chose).map(|_| {
|
||||
let target = targets_to_chose_from.remove(rng.gen_range(0, targets_to_chose_from.len()));
|
||||
if winners.iter().find(|w| **w == target).is_none() {
|
||||
winners.push(target.clone());
|
||||
}
|
||||
(target, rng.gen_range(1 * KSM, 100 * KSM))
|
||||
}).collect::<Vec<(AccountId, ExtendedBalance)>>();
|
||||
let distribution = (0..targets_to_chose)
|
||||
.map(|_| {
|
||||
let target =
|
||||
targets_to_chose_from.remove(rng.gen_range(0, targets_to_chose_from.len()));
|
||||
if winners.iter().find(|w| **w == target).is_none() {
|
||||
winners.push(target.clone());
|
||||
}
|
||||
(target, rng.gen_range(1 * KSM, 100 * KSM))
|
||||
})
|
||||
.collect::<Vec<(AccountId, ExtendedBalance)>>();
|
||||
|
||||
assignments.push(StakedAssignment {
|
||||
who: (acc as AccountId),
|
||||
distribution,
|
||||
});
|
||||
assignments.push(StakedAssignment { who: (acc as AccountId), distribution });
|
||||
});
|
||||
|
||||
(assignments, winners)
|
||||
@@ -117,10 +116,7 @@ fn assert_assignments_equal(
|
||||
}
|
||||
}
|
||||
|
||||
fn reduce_and_compare(
|
||||
assignment: &Vec<StakedAssignment<AccountId>>,
|
||||
winners: &Vec<AccountId>,
|
||||
) {
|
||||
fn reduce_and_compare(assignment: &Vec<StakedAssignment<AccountId>>, winners: &Vec<AccountId>) {
|
||||
let mut altered_assignment = assignment.clone();
|
||||
let n = assignment.len() as u32;
|
||||
let m = winners.len() as u32;
|
||||
@@ -138,15 +134,13 @@ fn reduce_and_compare(
|
||||
num_changed,
|
||||
);
|
||||
|
||||
assert_assignments_equal(
|
||||
winners,
|
||||
&assignment,
|
||||
&altered_assignment,
|
||||
);
|
||||
assert_assignments_equal(winners, &assignment, &altered_assignment);
|
||||
}
|
||||
|
||||
fn assignment_len(assignments: &[StakedAssignment<AccountId>]) -> u32 {
|
||||
let mut counter = 0;
|
||||
assignments.iter().for_each(|x| x.distribution.iter().for_each(|_| counter += 1));
|
||||
assignments
|
||||
.iter()
|
||||
.for_each(|x| x.distribution.iter().for_each(|_| counter += 1));
|
||||
counter
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user