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:
Bastian Köcher
2021-07-21 16:32:32 +02:00
committed by GitHub
parent d451c38c1c
commit 7b56ab15b4
1010 changed files with 53339 additions and 51208 deletions
@@ -21,9 +21,9 @@
use super::*;
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite, whitelist};
use frame_support::{dispatch::DispatchResultWithPostInfo, traits::OnInitialize};
use frame_system::RawOrigin;
use frame_benchmarking::{benchmarks, account, whitelist, impl_benchmark_test_suite};
use frame_support::{traits::OnInitialize, dispatch::DispatchResultWithPostInfo};
use crate::Pallet as Elections;
@@ -62,28 +62,34 @@ fn candidate_count<T: Config>() -> u32 {
}
/// Add `c` new candidates.
fn submit_candidates<T: Config>(c: u32, prefix: &'static str)
-> Result<Vec<T::AccountId>, &'static str>
{
(0..c).map(|i| {
let account = endowed_account::<T>(prefix, i);
<Elections<T>>::submit_candidacy(
RawOrigin::Signed(account.clone()).into(),
candidate_count::<T>(),
).map_err(|_| "failed to submit candidacy")?;
Ok(account)
}).collect::<Result<_, _>>()
fn submit_candidates<T: Config>(
c: u32,
prefix: &'static str,
) -> Result<Vec<T::AccountId>, &'static str> {
(0..c)
.map(|i| {
let account = endowed_account::<T>(prefix, i);
<Elections<T>>::submit_candidacy(
RawOrigin::Signed(account.clone()).into(),
candidate_count::<T>(),
)
.map_err(|_| "failed to submit candidacy")?;
Ok(account)
})
.collect::<Result<_, _>>()
}
/// Add `c` new candidates with self vote.
fn submit_candidates_with_self_vote<T: Config>(c: u32, prefix: &'static str)
-> Result<Vec<T::AccountId>, &'static str>
{
fn submit_candidates_with_self_vote<T: Config>(
c: u32,
prefix: &'static str,
) -> Result<Vec<T::AccountId>, &'static str> {
let candidates = submit_candidates::<T>(c, prefix)?;
let stake = default_stake::<T>(BALANCE_FACTOR);
let _ = candidates.iter().map(|c|
submit_voter::<T>(c.clone(), vec![c.clone()], stake).map(|_| ())
).collect::<Result<_, _>>()?;
let _ = candidates
.iter()
.map(|c| submit_voter::<T>(c.clone(), vec![c.clone()], stake).map(|_| ()))
.collect::<Result<_, _>>()?;
Ok(candidates)
}
@@ -98,18 +104,16 @@ fn submit_voter<T: Config>(
/// create `num_voter` voters who randomly vote for at most `votes` of `all_candidates` if
/// available.
fn distribute_voters<T: Config>(mut all_candidates: Vec<T::AccountId>, num_voters: u32, votes: usize)
-> Result<(), &'static str>
{
fn distribute_voters<T: Config>(
mut all_candidates: Vec<T::AccountId>,
num_voters: u32,
votes: usize,
) -> Result<(), &'static str> {
let stake = default_stake::<T>(BALANCE_FACTOR);
for i in 0..num_voters {
// to ensure that votes are different
all_candidates.rotate_left(1);
let votes = all_candidates
.iter()
.cloned()
.take(votes)
.collect::<Vec<_>>();
let votes = all_candidates.iter().cloned().take(votes).collect::<Vec<_>>();
let voter = endowed_account::<T>("voter", i);
submit_voter::<T>(voter, votes, stake)?;
}
@@ -128,13 +132,11 @@ fn fill_seats_up_to<T: Config>(m: u32) -> Result<Vec<T::AccountId>, &'static str
m as usize,
"wrong number of members and runners-up",
);
Ok(
<Elections<T>>::members()
.into_iter()
.map(|m| m.who)
.chain(<Elections<T>>::runners_up().into_iter().map(|r| r.who))
.collect()
)
Ok(<Elections<T>>::members()
.into_iter()
.map(|m| m.who)
.chain(<Elections<T>>::runners_up().into_iter().map(|r| r.who))
.collect())
}
/// removes all the storage items to reverse any genesis state.
File diff suppressed because it is too large Load Diff
@@ -17,12 +17,13 @@
//! Migrations to version [`3.0.0`], as denoted by the changelog.
use codec::{Encode, Decode, FullCodec};
use sp_std::prelude::*;
use codec::{Decode, Encode, FullCodec};
use frame_support::{
RuntimeDebug, weights::Weight, Twox64Concat,
traits::{GetPalletVersion, PalletVersion},
weights::Weight,
RuntimeDebug, Twox64Concat,
};
use sp_std::prelude::*;
#[derive(Encode, Decode, Clone, Default, RuntimeDebug, PartialEq)]
struct SeatHolder<AccountId, Balance> {
@@ -89,7 +90,7 @@ pub fn apply<T: V2ToV3>(old_voter_bond: T::Balance, old_candidacy_bond: T::Balan
migrate_runners_up_to_recorded_deposit::<T>(old_candidacy_bond);
migrate_members_to_recorded_deposit::<T>(old_candidacy_bond);
Weight::max_value()
}
},
_ => {
log::warn!(
target: "runtime::elections-phragmen",
@@ -103,15 +104,9 @@ pub fn apply<T: V2ToV3>(old_voter_bond: T::Balance, old_candidacy_bond: T::Balan
/// Migrate from the old legacy voting bond (fixed) to the new one (per-vote dynamic).
pub fn migrate_voters_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
<Voting<T>>::translate::<(T::Balance, Vec<T::AccountId>), _>(
|_who, (stake, votes)| {
Some(Voter {
votes,
stake,
deposit: old_deposit,
})
},
);
<Voting<T>>::translate::<(T::Balance, Vec<T::AccountId>), _>(|_who, (stake, votes)| {
Some(Voter { votes, stake, deposit: old_deposit })
});
log::info!(
target: "runtime::elections-phragmen",
@@ -122,50 +117,39 @@ pub fn migrate_voters_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
/// Migrate all candidates to recorded deposit.
pub fn migrate_candidates_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
let _ = <Candidates<T>>::translate::<Vec<T::AccountId>, _>(
|maybe_old_candidates| {
maybe_old_candidates.map(|old_candidates| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} candidate accounts.",
old_candidates.len(),
);
old_candidates
.into_iter()
.map(|c| (c, old_deposit))
.collect::<Vec<_>>()
})
},
);
let _ = <Candidates<T>>::translate::<Vec<T::AccountId>, _>(|maybe_old_candidates| {
maybe_old_candidates.map(|old_candidates| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} candidate accounts.",
old_candidates.len(),
);
old_candidates.into_iter().map(|c| (c, old_deposit)).collect::<Vec<_>>()
})
});
}
/// Migrate all members to recorded deposit.
pub fn migrate_members_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
let _ = <Members<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(
|maybe_old_members| {
maybe_old_members.map(|old_members| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} member accounts.",
old_members.len(),
);
old_members
.into_iter()
.map(|(who, stake)| SeatHolder {
who,
stake,
deposit: old_deposit,
})
.collect::<Vec<_>>()
})
},
);
let _ = <Members<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(|maybe_old_members| {
maybe_old_members.map(|old_members| {
log::info!(
target: "runtime::elections-phragmen",
"migrated {} member accounts.",
old_members.len(),
);
old_members
.into_iter()
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
.collect::<Vec<_>>()
})
});
}
/// Migrate all runners-up to recorded deposit.
pub fn migrate_runners_up_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance) {
let _ = <RunnersUp<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(
|maybe_old_runners_up| {
let _ =
<RunnersUp<T>>::translate::<Vec<(T::AccountId, T::Balance)>, _>(|maybe_old_runners_up| {
maybe_old_runners_up.map(|old_runners_up| {
log::info!(
target: "runtime::elections-phragmen",
@@ -174,13 +158,8 @@ pub fn migrate_runners_up_to_recorded_deposit<T: V2ToV3>(old_deposit: T::Balance
);
old_runners_up
.into_iter()
.map(|(who, stake)| SeatHolder {
who,
stake,
deposit: old_deposit,
})
.map(|(who, stake)| SeatHolder { who, stake, deposit: old_deposit })
.collect::<Vec<_>>()
})
},
);
});
}
@@ -18,8 +18,8 @@
//! Migrations to version [`4.0.0`], as denoted by the changelog.
use frame_support::{
traits::{Get, GetPalletVersion, PalletVersion},
weights::Weight,
traits::{GetPalletVersion, PalletVersion, Get},
};
/// The old prefix.
@@ -32,17 +32,15 @@ pub const OLD_PREFIX: &[u8] = b"PhragmenElection";
/// `<Runtime as frame_system::Config>::PalletInfo::name::<ElectionsPhragmenPallet>`.
///
/// The old storage prefix, `PhragmenElection` is hardcoded in the migration code.
pub fn migrate<
T: frame_system::Config,
P: GetPalletVersion,
N: AsRef<str>,
>(new_pallet_name: N) -> Weight {
pub fn migrate<T: frame_system::Config, P: GetPalletVersion, N: AsRef<str>>(
new_pallet_name: N,
) -> Weight {
if new_pallet_name.as_ref().as_bytes() == OLD_PREFIX {
log::info!(
target: "runtime::elections-phragmen",
"New pallet name is equal to the old prefix. No migration needs to be done.",
);
return 0;
return 0
}
let maybe_storage_version = <P as GetPalletVersion>::storage_version();
log::info!(
@@ -59,7 +57,7 @@ pub fn migrate<
new_pallet_name.as_ref().as_bytes(),
);
<T as frame_system::Config>::BlockWeights::get().max_block
}
},
_ => {
log::warn!(
target: "runtime::elections-phragmen",
@@ -103,7 +101,7 @@ pub fn pre_migration<P: GetPalletVersion, N: AsRef<str>>(new: N) {
/// [`frame_support::traits::OnRuntimeUpgrade::post_upgrade`] for further testing.
///
/// Panics if anything goes wrong.
pub fn post_migration<P : GetPalletVersion>() {
pub fn post_migration<P: GetPalletVersion>() {
log::info!("post-migration elections-phragmen");
// ensure we've been updated to v4 by the automatic write of crate version -> storage version.
assert!(<P as GetPalletVersion>::storage_version().unwrap().major == 4);
@@ -36,6 +36,7 @@
// --template=./.maintain/frame-weight-template.hbs
#![cfg_attr(rustfmt, rustfmt_skip)]
#![allow(unused_parens)]
#![allow(unused_imports)]