Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Cover 2 new cases with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
wigy committed Nov 17, 2021
1 parent 78093a0 commit cd353c8
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2939,6 +2939,40 @@ fn non_slashable_offence_doesnt_disable_validator() {
});
}

#[test]
fn slashing_independent_of_disabling_validator() {
ExtBuilder::default().build_and_execute(|| {
mock::start_active_era(1);
assert_eq_uvec!(Session::validators(), vec![11, 21]);

let exposure_11 = Staking::eras_stakers(Staking::active_era().unwrap().index, &11);
let exposure_21 = Staking::eras_stakers(Staking::active_era().unwrap().index, &21);

let now = Staking::active_era().unwrap().index;

// offence with no slash associated, BUT disabling
on_offence_in_era(
&[OffenceDetails { offender: (11, exposure_11.clone()), reporters: vec![] }],
&[Perbill::zero()],
now,
DisableStrategy::Always,
);

// offence that slashes 25% of the bond, BUT not disabling
on_offence_in_era(
&[OffenceDetails { offender: (21, exposure_21.clone()), reporters: vec![] }],
&[Perbill::from_percent(25)],
now,
DisableStrategy::Never,
);

// the offence for validator 10 was explicitly disabled
assert!(is_disabled(10));
// whereas validator 20 is explicitly not disabled
assert!(!is_disabled(20));
});
}

#[test]
fn offence_threshold_triggers_new_era() {
ExtBuilder::default()
Expand Down

0 comments on commit cd353c8

Please sign in to comment.