@@ -22,8 +22,12 @@ use super::mock::{
2222 active_validators, new_test_ext, next_session, AccountId , RuntimeOrigin , Session , System , Test ,
2323 ValidatorSet ,
2424} ;
25- use frame_support:: { assert_noop, assert_ok, traits:: ValidatorRegistration } ;
26- use sp_runtime:: { traits:: Zero , DispatchError } ;
25+ use frame_support:: {
26+ assert_noop, assert_ok,
27+ traits:: { DisabledValidators , ValidatorRegistration } ,
28+ } ;
29+ use sp_runtime:: { traits:: Zero , DispatchError , Perbill } ;
30+ use sp_staking:: offence:: { DisableStrategy , OffenceDetails , OnOffenceHandler } ;
2731use std:: collections:: HashSet ;
2832
2933type Error = super :: Error < Test > ;
@@ -132,3 +136,31 @@ fn remove_purges_keys_and_decs_providers() {
132136 assert ! ( System :: providers( & 3 ) . is_zero( ) ) ;
133137 } ) ;
134138}
139+
140+ #[ test]
141+ fn offender_disabled_and_removed ( ) {
142+ new_test_ext ( ) . execute_with ( || {
143+ assert_eq ! ( validators( ) , HashSet :: from( [ 1 , 2 , 3 ] ) ) ;
144+ ValidatorSet :: on_offence (
145+ & [ OffenceDetails { offender : ( 3 , 3 ) , reporters : vec ! [ ] } ] ,
146+ & [ Perbill :: from_rational ( 1u32 , 2u32 ) ] ,
147+ 0 ,
148+ DisableStrategy :: WhenSlashed ,
149+ ) ;
150+ assert_eq ! ( validators( ) , HashSet :: from( [ 1 , 2 ] ) ) ;
151+
152+ // The offender should be disabled for the rest of this session and the next session. The
153+ // removal should take effect by the session after next.
154+ assert_eq ! ( active_validators( ) , HashSet :: from( [ 1 , 2 , 3 ] ) ) ;
155+ assert ! ( Session :: is_disabled(
156+ Session :: validators( ) . iter( ) . position( |who| * who == 3 ) . unwrap( ) as u32
157+ ) ) ;
158+ next_session ( ) ;
159+ assert_eq ! ( active_validators( ) , HashSet :: from( [ 1 , 2 , 3 ] ) ) ;
160+ assert ! ( Session :: is_disabled(
161+ Session :: validators( ) . iter( ) . position( |who| * who == 3 ) . unwrap( ) as u32
162+ ) ) ;
163+ next_session ( ) ;
164+ assert_eq ! ( active_validators( ) , HashSet :: from( [ 1 , 2 ] ) ) ;
165+ } ) ;
166+ }
0 commit comments