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,29 +21,30 @@
mod mock;
use sp_std::prelude::*;
use sp_std::vec;
use sp_std::{prelude::*, vec};
use frame_system::{RawOrigin, Pallet as System, Config as SystemConfig};
use frame_benchmarking::{benchmarks, account, impl_benchmark_test_suite};
use frame_benchmarking::{account, benchmarks, impl_benchmark_test_suite};
use frame_support::traits::{Currency, ValidatorSet, ValidatorSetWithIdentification};
use frame_system::{Config as SystemConfig, Pallet as System, RawOrigin};
use sp_runtime::{
traits::{Convert, Saturating, StaticLookup, UniqueSaturatedInto},
Perbill,
traits::{Convert, StaticLookup, Saturating, UniqueSaturatedInto},
};
use sp_staking::offence::{ReportOffence, Offence};
use sp_staking::offence::{Offence, ReportOffence};
use pallet_balances::Config as BalancesConfig;
use pallet_babe::BabeEquivocationOffence;
use pallet_balances::Config as BalancesConfig;
use pallet_grandpa::{GrandpaEquivocationOffence, GrandpaTimeSlot};
use pallet_im_online::{Config as ImOnlineConfig, Pallet as ImOnline, UnresponsivenessOffence};
use pallet_offences::{Config as OffencesConfig, Pallet as Offences};
use pallet_session::historical::{Config as HistoricalConfig, IdentificationTuple};
use pallet_session::{Config as SessionConfig, SessionManager};
use pallet_session::{
historical::{Config as HistoricalConfig, IdentificationTuple},
Config as SessionConfig, SessionManager,
};
use pallet_staking::{
Pallet as Staking, Config as StakingConfig, RewardDestination, ValidatorPrefs, Exposure,
IndividualExposure, Event as StakingEvent,
Config as StakingConfig, Event as StakingEvent, Exposure, IndividualExposure,
Pallet as Staking, RewardDestination, ValidatorPrefs,
};
const SEED: u32 = 0;
@@ -62,7 +63,8 @@ pub trait Config:
+ HistoricalConfig
+ BalancesConfig
+ IdTupleConvert<Self>
{}
{
}
/// A helper trait to make sure we can convert `IdentificationTuple` coming from historical
/// and the one required by offences.
@@ -71,8 +73,9 @@ pub trait IdTupleConvert<T: HistoricalConfig + OffencesConfig> {
fn convert(id: IdentificationTuple<T>) -> <T as OffencesConfig>::IdentificationTuple;
}
impl<T: HistoricalConfig + OffencesConfig> IdTupleConvert<T> for T where
<T as OffencesConfig>::IdentificationTuple: From<IdentificationTuple<T>>
impl<T: HistoricalConfig + OffencesConfig> IdTupleConvert<T> for T
where
<T as OffencesConfig>::IdentificationTuple: From<IdentificationTuple<T>>,
{
fn convert(id: IdentificationTuple<T>) -> <T as OffencesConfig>::IdentificationTuple {
id.into()
@@ -80,7 +83,8 @@ impl<T: HistoricalConfig + OffencesConfig> IdTupleConvert<T> for T where
}
type LookupSourceOf<T> = <<T as SystemConfig>::Lookup as StaticLookup>::Source;
type BalanceOf<T> = <<T as StakingConfig>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
type BalanceOf<T> =
<<T as StakingConfig>::Currency as Currency<<T as SystemConfig>::AccountId>>::Balance;
struct Offender<T: Config> {
pub controller: T::AccountId,
@@ -109,19 +113,20 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
reward_destination.clone(),
)?;
let validator_prefs = ValidatorPrefs {
commission: Perbill::from_percent(50),
.. Default::default()
};
let validator_prefs =
ValidatorPrefs { commission: Perbill::from_percent(50), ..Default::default() };
Staking::<T>::validate(RawOrigin::Signed(controller.clone()).into(), validator_prefs)?;
let mut individual_exposures = vec![];
let mut nominator_stashes = vec![];
// Create n nominators
for i in 0 .. nominators {
let nominator_stash: T::AccountId = account("nominator stash", n * MAX_NOMINATORS + i, SEED);
let nominator_controller: T::AccountId = account("nominator controller", n * MAX_NOMINATORS + i, SEED);
let nominator_controller_lookup: LookupSourceOf<T> = T::Lookup::unlookup(nominator_controller.clone());
for i in 0..nominators {
let nominator_stash: T::AccountId =
account("nominator stash", n * MAX_NOMINATORS + i, SEED);
let nominator_controller: T::AccountId =
account("nominator controller", n * MAX_NOMINATORS + i, SEED);
let nominator_controller_lookup: LookupSourceOf<T> =
T::Lookup::unlookup(nominator_controller.clone());
T::Currency::make_free_balance_be(&nominator_stash, free_amount.into());
Staking::<T>::bond(
@@ -132,76 +137,82 @@ fn create_offender<T: Config>(n: u32, nominators: u32) -> Result<Offender<T>, &'
)?;
let selected_validators: Vec<LookupSourceOf<T>> = vec![controller_lookup.clone()];
Staking::<T>::nominate(RawOrigin::Signed(nominator_controller.clone()).into(), selected_validators)?;
Staking::<T>::nominate(
RawOrigin::Signed(nominator_controller.clone()).into(),
selected_validators,
)?;
individual_exposures.push(IndividualExposure {
who: nominator_stash.clone(),
value: amount.clone(),
});
individual_exposures
.push(IndividualExposure { who: nominator_stash.clone(), value: amount.clone() });
nominator_stashes.push(nominator_stash.clone());
}
let exposure = Exposure {
total: amount.clone() * n.into(),
own: amount,
others: individual_exposures,
};
let exposure =
Exposure { total: amount.clone() * n.into(), own: amount, others: individual_exposures };
let current_era = 0u32;
Staking::<T>::add_era_stakers(current_era.into(), stash.clone().into(), exposure);
Ok(Offender { controller, stash, nominator_stashes })
}
fn make_offenders<T: Config>(num_offenders: u32, num_nominators: u32) -> Result<
(Vec<IdentificationTuple<T>>, Vec<Offender<T>>),
&'static str
> {
fn make_offenders<T: Config>(
num_offenders: u32,
num_nominators: u32,
) -> Result<(Vec<IdentificationTuple<T>>, Vec<Offender<T>>), &'static str> {
Staking::<T>::new_session(0);
let mut offenders = vec![];
for i in 0 .. num_offenders {
for i in 0..num_offenders {
let offender = create_offender::<T>(i + 1, num_nominators)?;
offenders.push(offender);
}
Staking::<T>::start_session(0);
let id_tuples = offenders.iter()
.map(|offender|
let id_tuples = offenders
.iter()
.map(|offender| {
<T as SessionConfig>::ValidatorIdOf::convert(offender.controller.clone())
.expect("failed to get validator id from account id"))
.map(|validator_id|
.expect("failed to get validator id from account id")
})
.map(|validator_id| {
<T as HistoricalConfig>::FullIdentificationOf::convert(validator_id.clone())
.map(|full_id| (validator_id, full_id))
.expect("failed to convert validator id to full identification"))
.map(|full_id| (validator_id, full_id))
.expect("failed to convert validator id to full identification")
})
.collect::<Vec<IdentificationTuple<T>>>();
Ok((id_tuples, offenders))
}
fn make_offenders_im_online<T: Config>(num_offenders: u32, num_nominators: u32) -> Result<
(Vec<pallet_im_online::IdentificationTuple<T>>, Vec<Offender<T>>),
&'static str
> {
fn make_offenders_im_online<T: Config>(
num_offenders: u32,
num_nominators: u32,
) -> Result<(Vec<pallet_im_online::IdentificationTuple<T>>, Vec<Offender<T>>), &'static str> {
Staking::<T>::new_session(0);
let mut offenders = vec![];
for i in 0 .. num_offenders {
for i in 0..num_offenders {
let offender = create_offender::<T>(i + 1, num_nominators)?;
offenders.push(offender);
}
Staking::<T>::start_session(0);
let id_tuples = offenders.iter()
.map(|offender| <
let id_tuples = offenders
.iter()
.map(|offender| {
<
<T as ImOnlineConfig>::ValidatorSet as ValidatorSet<T::AccountId>
>::ValidatorIdOf::convert(offender.controller.clone())
.expect("failed to get validator id from account id"))
.map(|validator_id| <
.expect("failed to get validator id from account id")
})
.map(|validator_id| {
<
<T as ImOnlineConfig>::ValidatorSet as ValidatorSetWithIdentification<T::AccountId>
>::IdentificationOf::convert(validator_id.clone())
.map(|full_id| (validator_id, full_id))
.expect("failed to convert validator id to full identification"))
.expect("failed to convert validator id to full identification")
})
.collect::<Vec<pallet_im_online::IdentificationTuple<T>>>();
Ok((id_tuples, offenders))
}
@@ -224,7 +235,9 @@ fn check_events<T: Config, I: Iterator<Item = <T as SystemConfig>::Event>>(expec
pretty("--Got:", &events);
pretty("--Expected:", &expected);
format!("Mismatching length. Got: {}, expected: {}", lengths.0, lengths.1)
} else { Default::default() };
} else {
Default::default()
};
for (idx, (a, b)) in events.into_iter().zip(expected).enumerate() {
assert_eq!(a, b, "Mismatch at: {}. {}", idx, length_mismatch);
@@ -388,8 +401,4 @@ benchmarks! {
}
}
impl_benchmark_test_suite!(
Pallet,
crate::mock::new_test_ext(),
crate::mock::Test,
);
impl_benchmark_test_suite!(Pallet, crate::mock::new_test_ext(), crate::mock::Test,);
@@ -20,17 +20,14 @@
#![cfg(test)]
use super::*;
use frame_support::{
parameter_types,
weights::constants::WEIGHT_PER_SECOND,
};
use frame_system as system;
use sp_runtime::{
traits::IdentityLookup,
testing::{Header, UintAuthorityId},
};
use frame_election_provider_support::onchain;
use frame_support::{parameter_types, weights::constants::WEIGHT_PER_SECOND};
use frame_system as system;
use pallet_session::historical as pallet_session_historical;
use sp_runtime::{
testing::{Header, UintAuthorityId},
traits::IdentityLookup,
};
type AccountId = u64;
type AccountIndex = u32;
@@ -112,7 +109,8 @@ impl pallet_session::SessionHandler<AccountId> for TestSessionHandler {
_: bool,
_: &[(AccountId, Ks)],
_: &[(AccountId, Ks)],
) {}
) {
}
fn on_disabled(_: usize) {}
}
@@ -198,7 +196,10 @@ impl pallet_offences::Config for Test {
type OnOffenceHandler = Staking;
}
impl<T> frame_system::offchain::SendTransactionTypes<T> for Test where Call: From<T> {
impl<T> frame_system::offchain::SendTransactionTypes<T> for Test
where
Call: From<T>,
{
type Extrinsic = Extrinsic;
type OverarchingCall = Call;
}