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
+86 -152
View File
@@ -24,7 +24,7 @@ use crate::mock::*;
use codec::Encode;
use fg_primitives::ScheduledChange;
use frame_support::{
assert_err, assert_ok, assert_noop,
assert_err, assert_noop, assert_ok,
traits::{Currency, OnFinalize, OneSessionHandler},
weights::{GetDispatchInfo, Pays},
};
@@ -43,21 +43,24 @@ fn authorities_change_logged() {
Grandpa::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, Digest {
logs: vec![
grandpa_log(ConsensusLog::ScheduledChange(
ScheduledChange { delay: 0, next_authorities: to_authorities(vec![(4, 1), (5, 1), (6, 1)]) }
)),
],
});
assert_eq!(
header.digest,
Digest {
logs: vec![grandpa_log(ConsensusLog::ScheduledChange(ScheduledChange {
delay: 0,
next_authorities: to_authorities(vec![(4, 1), (5, 1), (6, 1)])
})),],
}
);
assert_eq!(System::events(), vec![
EventRecord {
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::Finalization,
event: Event::NewAuthorities(to_authorities(vec![(4, 1), (5, 1), (6, 1)])).into(),
topics: vec![],
},
]);
},]
);
});
}
@@ -68,13 +71,15 @@ fn authorities_change_logged_after_delay() {
Grandpa::schedule_change(to_authorities(vec![(4, 1), (5, 1), (6, 1)]), 1, None).unwrap();
Grandpa::on_finalize(1);
let header = System::finalize();
assert_eq!(header.digest, Digest {
logs: vec![
grandpa_log(ConsensusLog::ScheduledChange(
ScheduledChange { delay: 1, next_authorities: to_authorities(vec![(4, 1), (5, 1), (6, 1)]) }
)),
],
});
assert_eq!(
header.digest,
Digest {
logs: vec![grandpa_log(ConsensusLog::ScheduledChange(ScheduledChange {
delay: 1,
next_authorities: to_authorities(vec![(4, 1), (5, 1), (6, 1)])
})),],
}
);
// no change at this height.
assert_eq!(System::events(), vec![]);
@@ -84,13 +89,14 @@ fn authorities_change_logged_after_delay() {
Grandpa::on_finalize(2);
let _header = System::finalize();
assert_eq!(System::events(), vec![
EventRecord {
assert_eq!(
System::events(),
vec![EventRecord {
phase: Phase::Finalization,
event: Event::NewAuthorities(to_authorities(vec![(4, 1), (5, 1), (6, 1)])).into(),
topics: vec![],
},
]);
},]
);
});
}
@@ -131,11 +137,7 @@ fn cannot_schedule_change_when_one_pending() {
fn dispatch_forced_change() {
new_test_ext(vec![(1, 1), (2, 1), (3, 1)]).execute_with(|| {
initialize_block(1, Default::default());
Grandpa::schedule_change(
to_authorities(vec![(4, 1), (5, 1), (6, 1)]),
5,
Some(0),
).unwrap();
Grandpa::schedule_change(to_authorities(vec![(4, 1), (5, 1), (6, 1)]), 5, Some(0)).unwrap();
assert!(<PendingChange<Test>>::exists());
assert_noop!(
@@ -168,7 +170,10 @@ fn dispatch_forced_change() {
{
initialize_block(7, header.hash());
assert!(!<PendingChange<Test>>::exists());
assert_eq!(Grandpa::grandpa_authorities(), to_authorities(vec![(4, 1), (5, 1), (6, 1)]));
assert_eq!(
Grandpa::grandpa_authorities(),
to_authorities(vec![(4, 1), (5, 1), (6, 1)])
);
assert_ok!(Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None));
Grandpa::on_finalize(7);
header = System::finalize();
@@ -178,7 +183,10 @@ fn dispatch_forced_change() {
{
initialize_block(8, header.hash());
assert!(<PendingChange<Test>>::exists());
assert_eq!(Grandpa::grandpa_authorities(), to_authorities(vec![(4, 1), (5, 1), (6, 1)]));
assert_eq!(
Grandpa::grandpa_authorities(),
to_authorities(vec![(4, 1), (5, 1), (6, 1)])
);
assert_noop!(
Grandpa::schedule_change(to_authorities(vec![(5, 1)]), 1, None),
Error::<Test>::ChangePending
@@ -205,7 +213,11 @@ fn dispatch_forced_change() {
{
initialize_block(11, header.hash());
assert!(!<PendingChange<Test>>::exists());
assert_ok!(Grandpa::schedule_change(to_authorities(vec![(5, 1), (6, 1), (7, 1)]), 5, Some(0)));
assert_ok!(Grandpa::schedule_change(
to_authorities(vec![(5, 1), (6, 1), (7, 1)]),
5,
Some(0)
));
assert_eq!(Grandpa::next_forced(), Some(21));
Grandpa::on_finalize(11);
header = System::finalize();
@@ -222,13 +234,7 @@ fn schedule_pause_only_when_live() {
Grandpa::schedule_pause(1).unwrap();
// we've switched to the pending pause state
assert_eq!(
Grandpa::state(),
StoredState::PendingPause {
scheduled_at: 1u64,
delay: 1,
},
);
assert_eq!(Grandpa::state(), StoredState::PendingPause { scheduled_at: 1u64, delay: 1 },);
Grandpa::on_finalize(1);
let _ = System::finalize();
@@ -242,10 +248,7 @@ fn schedule_pause_only_when_live() {
let _ = System::finalize();
// after finalizing block 2 the set should have switched to paused state
assert_eq!(
Grandpa::state(),
StoredState::Paused,
);
assert_eq!(Grandpa::state(), StoredState::Paused,);
});
}
@@ -257,20 +260,14 @@ fn schedule_resume_only_when_paused() {
// the set is currently live, resuming it is an error
assert_noop!(Grandpa::schedule_resume(1), Error::<Test>::ResumeFailed);
assert_eq!(
Grandpa::state(),
StoredState::Live,
);
assert_eq!(Grandpa::state(), StoredState::Live,);
// we schedule a pause to be applied instantly
Grandpa::schedule_pause(0).unwrap();
Grandpa::on_finalize(1);
let _ = System::finalize();
assert_eq!(
Grandpa::state(),
StoredState::Paused,
);
assert_eq!(Grandpa::state(), StoredState::Paused,);
// we schedule the set to go back live in 2 blocks
initialize_block(2, Default::default());
@@ -287,10 +284,7 @@ fn schedule_resume_only_when_paused() {
let _ = System::finalize();
// it should be live at block 4
assert_eq!(
Grandpa::state(),
StoredState::Live,
);
assert_eq!(Grandpa::state(), StoredState::Live,);
});
}
@@ -298,26 +292,11 @@ fn schedule_resume_only_when_paused() {
fn time_slot_have_sane_ord() {
// Ensure that `Ord` implementation is sane.
const FIXTURE: &[GrandpaTimeSlot] = &[
GrandpaTimeSlot {
set_id: 0,
round: 0,
},
GrandpaTimeSlot {
set_id: 0,
round: 1,
},
GrandpaTimeSlot {
set_id: 1,
round: 0,
},
GrandpaTimeSlot {
set_id: 1,
round: 1,
},
GrandpaTimeSlot {
set_id: 1,
round: 2,
}
GrandpaTimeSlot { set_id: 0, round: 0 },
GrandpaTimeSlot { set_id: 0, round: 1 },
GrandpaTimeSlot { set_id: 1, round: 0 },
GrandpaTimeSlot { set_id: 1, round: 1 },
GrandpaTimeSlot { set_id: 1, round: 2 },
];
assert!(FIXTURE.windows(2).all(|f| f[0] < f[1]));
}
@@ -325,16 +304,9 @@ fn time_slot_have_sane_ord() {
/// Returns a list with 3 authorities with known keys:
/// Alice, Bob and Charlie.
pub fn test_authorities() -> AuthorityList {
let authorities = vec![
Ed25519Keyring::Alice,
Ed25519Keyring::Bob,
Ed25519Keyring::Charlie,
];
let authorities = vec![Ed25519Keyring::Alice, Ed25519Keyring::Bob, Ed25519Keyring::Charlie];
authorities
.into_iter()
.map(|id| (id.public().into(), 1u64))
.collect()
authorities.into_iter().map(|id| (id.public().into(), 1u64)).collect()
}
#[test]
@@ -357,11 +329,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(
Staking::eras_stakers(1, validator),
pallet_staking::Exposure {
total: 10_000,
own: 10_000,
others: vec![],
},
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
@@ -384,13 +352,11 @@ fn report_equivocation_current_set_works() {
Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap();
// report the equivocation and the tx should be dispatched successfully
assert_ok!(
Grandpa::report_equivocation_unsigned(
Origin::none(),
equivocation_proof,
key_owner_proof,
),
);
assert_ok!(Grandpa::report_equivocation_unsigned(
Origin::none(),
equivocation_proof,
key_owner_proof,
),);
start_era(2);
@@ -401,17 +367,13 @@ fn report_equivocation_current_set_works() {
assert_eq!(Staking::slashable_balance_of(&equivocation_validator_id), 0);
assert_eq!(
Staking::eras_stakers(2, equivocation_validator_id),
pallet_staking::Exposure {
total: 0,
own: 0,
others: vec![],
},
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);
// check that the balances of all other validators are left intact.
for validator in &validators {
if *validator == equivocation_validator_id {
continue;
continue
}
assert_eq!(Balances::total_balance(validator), 10_000_000);
@@ -419,11 +381,7 @@ fn report_equivocation_current_set_works() {
assert_eq!(
Staking::eras_stakers(2, validator),
pallet_staking::Exposure {
total: 10_000,
own: 10_000,
others: vec![],
},
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
});
@@ -455,11 +413,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(
Staking::eras_stakers(2, validator),
pallet_staking::Exposure {
total: 10_000,
own: 10_000,
others: vec![],
},
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
@@ -476,13 +430,11 @@ fn report_equivocation_old_set_works() {
// report the equivocation using the key ownership proof generated on
// the old set, the tx should be dispatched successfully
assert_ok!(
Grandpa::report_equivocation_unsigned(
Origin::none(),
equivocation_proof,
key_owner_proof,
),
);
assert_ok!(Grandpa::report_equivocation_unsigned(
Origin::none(),
equivocation_proof,
key_owner_proof,
),);
start_era(3);
@@ -494,17 +446,13 @@ fn report_equivocation_old_set_works() {
assert_eq!(
Staking::eras_stakers(3, equivocation_validator_id),
pallet_staking::Exposure {
total: 0,
own: 0,
others: vec![],
},
pallet_staking::Exposure { total: 0, own: 0, others: vec![] },
);
// check that the balances of all other validators are left intact.
for validator in &validators {
if *validator == equivocation_validator_id {
continue;
continue
}
assert_eq!(Balances::total_balance(validator), 10_000_000);
@@ -512,11 +460,7 @@ fn report_equivocation_old_set_works() {
assert_eq!(
Staking::eras_stakers(3, validator),
pallet_staking::Exposure {
total: 10_000,
own: 10_000,
others: vec![],
},
pallet_staking::Exposure { total: 10_000, own: 10_000, others: vec![] },
);
}
});
@@ -737,10 +681,8 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
let key_owner_proof =
Historical::prove((sp_finality_grandpa::KEY_TYPE, &equivocation_key)).unwrap();
let call = Call::report_equivocation_unsigned(
equivocation_proof.clone(),
key_owner_proof.clone(),
);
let call =
Call::report_equivocation_unsigned(equivocation_proof.clone(), key_owner_proof.clone());
// only local/inblock reports are allowed
assert_eq!(
@@ -752,11 +694,7 @@ fn report_equivocation_validate_unsigned_prevents_duplicates() {
);
// the transaction is valid when passed as local
let tx_tag = (
equivocation_key,
set_id,
1u64,
);
let tx_tag = (equivocation_key, set_id, 1u64);
assert_eq!(
<Grandpa as sp_runtime::traits::ValidateUnsigned>::validate_unsigned(
@@ -861,23 +799,19 @@ fn always_schedules_a_change_on_new_session_when_stalled() {
fn report_equivocation_has_valid_weight() {
// the weight depends on the size of the validator set,
// but there's a lower bound of 100 validators.
assert!(
(1..=100)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] == w[1])
);
assert!((1..=100)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] == w[1]));
// after 100 validators the weight should keep increasing
// with every extra validator.
assert!(
(100..=1000)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] < w[1])
);
assert!((100..=1000)
.map(<Test as Config>::WeightInfo::report_equivocation)
.collect::<Vec<_>>()
.windows(2)
.all(|w| w[0] < w[1]));
}
#[test]