Removes ReportsByKindIndex (#13936)

* Removes ReportsByKind

* Minor build fixes

* adds migration

* Addresses review comment

* Uses clear but weight check fails

* Uses unique

* Updates test to commit the change before migration

* Uses reads_writes

* ".git/.scripts/commands/fmt/fmt.sh"

* Fixes build

* Addresses review comments

* ".git/.scripts/commands/fmt/fmt.sh"

* fixes typo

---------

Co-authored-by: command-bot <>
This commit is contained in:
gupnik
2023-04-25 20:50:58 +05:30
committed by GitHub
parent b06748e2ab
commit 6c8acaa5e2
4 changed files with 113 additions and 87 deletions
+2 -47
View File
@@ -21,8 +21,8 @@
use super::*;
use crate::mock::{
new_test_ext, offence_reports, report_id, with_on_offence_fractions, Offence, Offences,
RuntimeEvent, System, KIND,
new_test_ext, offence_reports, with_on_offence_fractions, Offence, Offences, RuntimeEvent,
System, KIND,
};
use frame_system::{EventRecord, Phase};
use sp_runtime::Perbill;
@@ -245,48 +245,3 @@ fn should_properly_count_offences() {
);
});
}
/// We insert offences in sorted order using the time slot in the `same_kind_reports`.
/// This test ensures that it works as expected.
#[test]
fn should_properly_sort_offences() {
new_test_ext().execute_with(|| {
// given
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] };
Offences::report_offence(vec![], offence1).unwrap();
with_on_offence_fractions(|f| {
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
f.clear();
});
// when
// report for the second time
Offences::report_offence(vec![], offence2).unwrap();
Offences::report_offence(vec![], offence3).unwrap();
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();
assert_eq!(
same_kind_reports,
vec![
(time_slot - 1, report_id(time_slot - 1, 3)),
(time_slot, report_id(time_slot, 5)),
(time_slot, report_id(time_slot, 4)),
(time_slot + 1, report_id(time_slot + 1, 6)),
(time_slot + 1, report_id(time_slot + 1, 7)),
]
);
});
}