mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 00:31:07 +00:00
Offence reporting returns a result (#5082)
* Offence reporting returns a result * Bump spec_version * Use unwrap instead of assertions * Fix more review grumbles
This commit is contained in:
@@ -30,7 +30,7 @@ use frame_support::{
|
||||
};
|
||||
use sp_runtime::traits::Hash;
|
||||
use sp_staking::{
|
||||
offence::{Offence, ReportOffence, Kind, OnOffenceHandler, OffenceDetails},
|
||||
offence::{Offence, ReportOffence, Kind, OnOffenceHandler, OffenceDetails, OffenceError},
|
||||
};
|
||||
use codec::{Encode, Decode};
|
||||
use frame_system as system;
|
||||
@@ -90,7 +90,7 @@ impl<T: Trait, O: Offence<T::IdentificationTuple>>
|
||||
where
|
||||
T::IdentificationTuple: Clone,
|
||||
{
|
||||
fn report_offence(reporters: Vec<T::AccountId>, offence: O) {
|
||||
fn report_offence(reporters: Vec<T::AccountId>, offence: O) -> Result<(), OffenceError> {
|
||||
let offenders = offence.offenders();
|
||||
let time_slot = offence.time_slot();
|
||||
let validator_set_count = offence.validator_set_count();
|
||||
@@ -104,7 +104,7 @@ where
|
||||
) {
|
||||
Some(triage) => triage,
|
||||
// The report contained only duplicates, so there is no need to slash again.
|
||||
None => return,
|
||||
None => return Err(OffenceError::DuplicateReport),
|
||||
};
|
||||
|
||||
// Deposit the event.
|
||||
@@ -123,6 +123,8 @@ where
|
||||
&slash_perbill,
|
||||
offence.session_index(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ fn should_report_an_authority_and_trigger_on_offence() {
|
||||
};
|
||||
|
||||
// when
|
||||
Offences::report_offence(vec![], offence);
|
||||
Offences::report_offence(vec![], offence).unwrap();
|
||||
|
||||
// then
|
||||
with_on_offence_fractions(|f| {
|
||||
@@ -61,7 +61,7 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
Offences::report_offence(vec![], offence.clone());
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
f.clear();
|
||||
@@ -69,7 +69,7 @@ fn should_not_report_the_same_authority_twice_in_the_same_slot() {
|
||||
|
||||
// when
|
||||
// report for the second time
|
||||
Offences::report_offence(vec![], offence);
|
||||
assert_eq!(Offences::report_offence(vec![], offence), Err(OffenceError::DuplicateReport));
|
||||
|
||||
// then
|
||||
with_on_offence_fractions(|f| {
|
||||
@@ -91,7 +91,7 @@ fn should_report_in_different_time_slot() {
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
Offences::report_offence(vec![], offence.clone());
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
f.clear();
|
||||
@@ -100,7 +100,7 @@ fn should_report_in_different_time_slot() {
|
||||
// when
|
||||
// report for the second time
|
||||
offence.time_slot += 1;
|
||||
Offences::report_offence(vec![], offence);
|
||||
Offences::report_offence(vec![], offence).unwrap();
|
||||
|
||||
// then
|
||||
with_on_offence_fractions(|f| {
|
||||
@@ -123,7 +123,7 @@ fn should_deposit_event() {
|
||||
};
|
||||
|
||||
// when
|
||||
Offences::report_offence(vec![], offence);
|
||||
Offences::report_offence(vec![], offence).unwrap();
|
||||
|
||||
// then
|
||||
assert_eq!(
|
||||
@@ -149,7 +149,7 @@ fn doesnt_deposit_event_for_dups() {
|
||||
time_slot,
|
||||
offenders: vec![5],
|
||||
};
|
||||
Offences::report_offence(vec![], offence.clone());
|
||||
Offences::report_offence(vec![], offence.clone()).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
f.clear();
|
||||
@@ -157,7 +157,7 @@ fn doesnt_deposit_event_for_dups() {
|
||||
|
||||
// when
|
||||
// report for the second time
|
||||
Offences::report_offence(vec![], offence);
|
||||
assert_eq!(Offences::report_offence(vec![], offence), Err(OffenceError::DuplicateReport));
|
||||
|
||||
// then
|
||||
// there is only one event.
|
||||
@@ -191,7 +191,7 @@ fn should_properly_count_offences() {
|
||||
time_slot,
|
||||
offenders: vec![4],
|
||||
};
|
||||
Offences::report_offence(vec![], offence1);
|
||||
Offences::report_offence(vec![], offence1).unwrap();
|
||||
with_on_offence_fractions(|f| {
|
||||
assert_eq!(f.clone(), vec![Perbill::from_percent(25)]);
|
||||
f.clear();
|
||||
@@ -199,7 +199,7 @@ fn should_properly_count_offences() {
|
||||
|
||||
// when
|
||||
// report for the second time
|
||||
Offences::report_offence(vec![], offence2);
|
||||
Offences::report_offence(vec![], offence2).unwrap();
|
||||
|
||||
// then
|
||||
// the 1st authority should have count 2 and the 2nd one should be reported only once.
|
||||
|
||||
Reference in New Issue
Block a user