mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 09:17:58 +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:
@@ -21,11 +21,11 @@
|
||||
|
||||
use super::*;
|
||||
use crate::mock::{
|
||||
Offences, System, Offence, Event, KIND, new_test_ext, with_on_offence_fractions,
|
||||
offence_reports, report_id,
|
||||
new_test_ext, offence_reports, report_id, with_on_offence_fractions, Event, Offence, Offences,
|
||||
System, KIND,
|
||||
};
|
||||
use sp_runtime::Perbill;
|
||||
use frame_system::{EventRecord, Phase};
|
||||
use sp_runtime::Perbill;
|
||||
|
||||
#[test]
|
||||
fn should_report_an_authority_and_trigger_on_offence() {
|
||||
@@ -34,11 +34,7 @@ fn should_report_an_authority_and_trigger_on_offence() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
|
||||
// when
|
||||
Offences::report_offence(vec![], offence).unwrap();
|
||||
@@ -57,11 +53,7 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
@@ -79,7 +71,6 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
#[test]
|
||||
fn should_report_in_different_time_slot() {
|
||||
new_test_ext().execute_with(|| {
|
||||
@@ -87,11 +78,7 @@ fn should_report_in_different_time_slot() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let mut offence = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let mut offence = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
@@ -117,11 +104,7 @@ fn should_deposit_event() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
|
||||
// when
|
||||
Offences::report_offence(vec![], offence).unwrap();
|
||||
@@ -145,11 +128,7 @@ fn doesnt_deposit_event_for_dups() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
@@ -181,33 +160,26 @@ fn reports_if_an_offence_is_dup() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence = |time_slot, offenders| TestOffence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders,
|
||||
};
|
||||
let offence =
|
||||
|time_slot, offenders| TestOffence { validator_set_count: 5, time_slot, offenders };
|
||||
|
||||
let mut test_offence = offence(time_slot, vec![0]);
|
||||
|
||||
// the report for authority 0 at time slot 42 should not be a known
|
||||
// offence
|
||||
assert!(
|
||||
!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
)
|
||||
);
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
|
||||
// we report an offence for authority 0 at time slot 42
|
||||
Offences::report_offence(vec![], test_offence.clone()).unwrap();
|
||||
|
||||
// the same report should be a known offence now
|
||||
assert!(
|
||||
<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
)
|
||||
);
|
||||
assert!(<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
|
||||
// and reporting it again should yield a duplicate report error
|
||||
assert_eq!(
|
||||
@@ -219,28 +191,21 @@ fn reports_if_an_offence_is_dup() {
|
||||
test_offence.offenders.push(1);
|
||||
|
||||
// it should not be a known offence anymore
|
||||
assert!(
|
||||
!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
)
|
||||
);
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence.offenders,
|
||||
&test_offence.time_slot
|
||||
));
|
||||
|
||||
// and reporting it again should work without any error
|
||||
assert_eq!(
|
||||
Offences::report_offence(vec![], test_offence.clone()),
|
||||
Ok(())
|
||||
);
|
||||
assert_eq!(Offences::report_offence(vec![], test_offence.clone()), Ok(()));
|
||||
|
||||
// creating a new offence for the same authorities on the next slot
|
||||
// should be considered a new offence and thefore not known
|
||||
let test_offence_next_slot = offence(time_slot + 1, vec![0, 1]);
|
||||
assert!(
|
||||
!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence_next_slot.offenders,
|
||||
&test_offence_next_slot.time_slot
|
||||
)
|
||||
);
|
||||
assert!(!<Offences as ReportOffence<_, _, TestOffence>>::is_known_offence(
|
||||
&test_offence_next_slot.offenders,
|
||||
&test_offence_next_slot.time_slot
|
||||
));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -253,16 +218,8 @@ fn should_properly_count_offences() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence1 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence2 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![4],
|
||||
};
|
||||
let offence1 = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
let offence2 = Offence { validator_set_count: 5, time_slot, offenders: vec![4] };
|
||||
Offences::report_offence(vec![], offence1).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
@@ -294,26 +251,12 @@ fn should_properly_sort_offences() {
|
||||
let time_slot = 42;
|
||||
assert_eq!(offence_reports(KIND, time_slot), vec![]);
|
||||
|
||||
let offence1 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
let offence2 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot,
|
||||
offenders: vec![4],
|
||||
};
|
||||
let offence3 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot: time_slot + 1,
|
||||
offenders: vec![6, 7],
|
||||
};
|
||||
let offence4 = Offence {
|
||||
validator_set_count: 5,
|
||||
time_slot: time_slot - 1,
|
||||
offenders: vec![3],
|
||||
};
|
||||
let offence1 = Offence { validator_set_count: 5, time_slot, offenders: vec![5] };
|
||||
let offence2 = Offence { validator_set_count: 5, time_slot, offenders: vec![4] };
|
||||
let offence3 =
|
||||
Offence { validator_set_count: 5, time_slot: time_slot + 1, offenders: vec![6, 7] };
|
||||
let offence4 =
|
||||
Offence { validator_set_count: 5, time_slot: time_slot - 1, offenders: vec![3] };
|
||||
Offences::report_offence(vec![], offence1).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
@@ -327,10 +270,10 @@ fn should_properly_sort_offences() {
|
||||
Offences::report_offence(vec![], offence4).unwrap();
|
||||
|
||||
// then
|
||||
let same_kind_reports =
|
||||
Vec::<(u128, sp_core::H256)>::decode(
|
||||
&mut &crate::ReportsByKindIndex::<crate::mock::Runtime>::get(KIND)[..],
|
||||
).unwrap();
|
||||
let same_kind_reports = Vec::<(u128, sp_core::H256)>::decode(
|
||||
&mut &crate::ReportsByKindIndex::<crate::mock::Runtime>::get(KIND)[..],
|
||||
)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
same_kind_reports,
|
||||
vec![
|
||||
|
||||
Reference in New Issue
Block a user