@@ -5789,6 +5789,21 @@ fn chill_other_works() {
5789
5789
//
5790
5790
// If any of these are missing, we do not have enough information to allow the
5791
5791
// `chill_other` to succeed from one user to another.
5792
+ //
5793
+ // Out of 8 possible cases, only one will allow the use of `chill_other`, which is
5794
+ // when all 3 conditions are met.
5795
+
5796
+ // 1. No limits whatsoever
5797
+ assert_ok ! ( Staking :: set_staking_configs(
5798
+ RuntimeOrigin :: root( ) ,
5799
+ ConfigOp :: Remove ,
5800
+ ConfigOp :: Remove ,
5801
+ ConfigOp :: Remove ,
5802
+ ConfigOp :: Remove ,
5803
+ ConfigOp :: Remove ,
5804
+ ConfigOp :: Remove ,
5805
+ ConfigOp :: Remove ,
5806
+ ) ) ;
5792
5807
5793
5808
// Can't chill these users
5794
5809
assert_noop ! (
@@ -5800,15 +5815,15 @@ fn chill_other_works() {
5800
5815
Error :: <Test >:: CannotChillOther
5801
5816
) ;
5802
5817
5803
- // Change the minimum bond... but no limits .
5818
+ // 2. Change only the minimum bonds .
5804
5819
assert_ok ! ( Staking :: set_staking_configs(
5805
5820
RuntimeOrigin :: root( ) ,
5806
5821
ConfigOp :: Set ( 1_500 ) ,
5807
5822
ConfigOp :: Set ( 2_000 ) ,
5808
- ConfigOp :: Remove ,
5809
- ConfigOp :: Remove ,
5810
- ConfigOp :: Remove ,
5811
- ConfigOp :: Remove ,
5823
+ ConfigOp :: Noop ,
5824
+ ConfigOp :: Noop ,
5825
+ ConfigOp :: Noop ,
5826
+ ConfigOp :: Noop ,
5812
5827
ConfigOp :: Noop ,
5813
5828
) ) ;
5814
5829
@@ -5822,11 +5837,11 @@ fn chill_other_works() {
5822
5837
Error :: <Test >:: CannotChillOther
5823
5838
) ;
5824
5839
5825
- // Add limits, but no threshold
5840
+ // 3. Add nominator/validator count limits, but no other threshold.
5826
5841
assert_ok ! ( Staking :: set_staking_configs(
5827
5842
RuntimeOrigin :: root( ) ,
5828
- ConfigOp :: Noop ,
5829
- ConfigOp :: Noop ,
5843
+ ConfigOp :: Remove ,
5844
+ ConfigOp :: Remove ,
5830
5845
ConfigOp :: Set ( 10 ) ,
5831
5846
ConfigOp :: Set ( 10 ) ,
5832
5847
ConfigOp :: Noop ,
@@ -5844,15 +5859,59 @@ fn chill_other_works() {
5844
5859
Error :: <Test >:: CannotChillOther
5845
5860
) ;
5846
5861
5847
- // Add threshold, but no limits
5862
+ // 4. Add chil threshold, but no other limits
5848
5863
assert_ok ! ( Staking :: set_staking_configs(
5849
5864
RuntimeOrigin :: root( ) ,
5850
5865
ConfigOp :: Noop ,
5851
5866
ConfigOp :: Noop ,
5852
5867
ConfigOp :: Remove ,
5853
5868
ConfigOp :: Remove ,
5869
+ ConfigOp :: Set ( Percent :: from_percent( 75 ) ) ,
5854
5870
ConfigOp :: Noop ,
5855
5871
ConfigOp :: Noop ,
5872
+ ) ) ;
5873
+
5874
+ // Still can't chill these users
5875
+ assert_noop ! (
5876
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 0 ) ,
5877
+ Error :: <Test >:: CannotChillOther
5878
+ ) ;
5879
+ assert_noop ! (
5880
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 2 ) ,
5881
+ Error :: <Test >:: CannotChillOther
5882
+ ) ;
5883
+
5884
+ // 5. Add bond and count limits, but no threshold
5885
+ assert_ok ! ( Staking :: set_staking_configs(
5886
+ RuntimeOrigin :: root( ) ,
5887
+ ConfigOp :: Set ( 1_500 ) ,
5888
+ ConfigOp :: Set ( 2_000 ) ,
5889
+ ConfigOp :: Set ( 10 ) ,
5890
+ ConfigOp :: Set ( 10 ) ,
5891
+ ConfigOp :: Remove ,
5892
+ ConfigOp :: Remove ,
5893
+ ConfigOp :: Remove ,
5894
+ ) ) ;
5895
+
5896
+ // Still can't chill these users
5897
+ assert_noop ! (
5898
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 0 ) ,
5899
+ Error :: <Test >:: CannotChillOther
5900
+ ) ;
5901
+ assert_noop ! (
5902
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 2 ) ,
5903
+ Error :: <Test >:: CannotChillOther
5904
+ ) ;
5905
+
5906
+ // 6. Add bond and threshold limits, but no count limits
5907
+ assert_ok ! ( Staking :: set_staking_configs(
5908
+ RuntimeOrigin :: root( ) ,
5909
+ ConfigOp :: Noop ,
5910
+ ConfigOp :: Noop ,
5911
+ ConfigOp :: Remove ,
5912
+ ConfigOp :: Remove ,
5913
+ ConfigOp :: Set ( Percent :: from_percent( 75 ) ) ,
5914
+ ConfigOp :: Noop ,
5856
5915
ConfigOp :: Noop ,
5857
5916
) ) ;
5858
5917
@@ -5866,11 +5925,33 @@ fn chill_other_works() {
5866
5925
Error :: <Test >:: CannotChillOther
5867
5926
) ;
5868
5927
5869
- // Add threshold and limits
5928
+ // 7. Add count limits and a chill threshold, but no bond limits
5870
5929
assert_ok ! ( Staking :: set_staking_configs(
5871
5930
RuntimeOrigin :: root( ) ,
5931
+ ConfigOp :: Remove ,
5932
+ ConfigOp :: Remove ,
5933
+ ConfigOp :: Set ( 10 ) ,
5934
+ ConfigOp :: Set ( 10 ) ,
5935
+ ConfigOp :: Set ( Percent :: from_percent( 75 ) ) ,
5872
5936
ConfigOp :: Noop ,
5873
5937
ConfigOp :: Noop ,
5938
+ ) ) ;
5939
+
5940
+ // Still can't chill these users
5941
+ assert_noop ! (
5942
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 0 ) ,
5943
+ Error :: <Test >:: CannotChillOther
5944
+ ) ;
5945
+ assert_noop ! (
5946
+ Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , 2 ) ,
5947
+ Error :: <Test >:: CannotChillOther
5948
+ ) ;
5949
+
5950
+ // 8. Add all limits
5951
+ assert_ok ! ( Staking :: set_staking_configs(
5952
+ RuntimeOrigin :: root( ) ,
5953
+ ConfigOp :: Set ( 1_500 ) ,
5954
+ ConfigOp :: Set ( 2_000 ) ,
5874
5955
ConfigOp :: Set ( 10 ) ,
5875
5956
ConfigOp :: Set ( 10 ) ,
5876
5957
ConfigOp :: Set ( Percent :: from_percent( 75 ) ) ,
@@ -5888,7 +5969,9 @@ fn chill_other_works() {
5888
5969
let b = 4 * i;
5889
5970
let d = 4 * i + 2 ;
5890
5971
assert_ok ! ( Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , b) ) ;
5972
+ assert_eq ! ( * staking_events( ) . last( ) . unwrap( ) , Event :: Chilled { stash: b } ) ;
5891
5973
assert_ok ! ( Staking :: chill_other( RuntimeOrigin :: signed( 1337 ) , d) ) ;
5974
+ assert_eq ! ( * staking_events( ) . last( ) . unwrap( ) , Event :: Chilled { stash: d } ) ;
5892
5975
}
5893
5976
5894
5977
// chill a nominator. Limit is not reached, not chill-able
@@ -6090,6 +6173,14 @@ fn change_of_absolute_max_nominations() {
6090
6173
) ;
6091
6174
assert_eq ! ( Staking :: electing_voters( bounds) . unwrap( ) . len( ) , 3 + 3 ) ;
6092
6175
6176
+ // No one can be chilled on account of non-decodable keys.
6177
+ for k in Nominators :: < Test > :: iter_keys ( ) {
6178
+ assert_noop ! (
6179
+ Staking :: chill_other( RuntimeOrigin :: signed( 1 ) , k) ,
6180
+ Error :: <Test >:: CannotChillOther
6181
+ ) ;
6182
+ }
6183
+
6093
6184
// abrupt change from 4 to 3, everyone should be fine.
6094
6185
AbsoluteMaxNominations :: set ( 3 ) ;
6095
6186
@@ -6101,8 +6192,16 @@ fn change_of_absolute_max_nominations() {
6101
6192
) ;
6102
6193
assert_eq ! ( Staking :: electing_voters( bounds) . unwrap( ) . len( ) , 3 + 3 ) ;
6103
6194
6195
+ // As before, no one can be chilled on account of non-decodable keys.
6196
+ for k in Nominators :: < Test > :: iter_keys ( ) {
6197
+ assert_noop ! (
6198
+ Staking :: chill_other( RuntimeOrigin :: signed( 1 ) , k) ,
6199
+ Error :: <Test >:: CannotChillOther
6200
+ ) ;
6201
+ }
6202
+
6104
6203
// abrupt change from 3 to 2, this should cause some nominators to be non-decodable, and
6105
- // thus non-existent unless if they update.
6204
+ // thus non-existent unless they update.
6106
6205
AbsoluteMaxNominations :: set ( 2 ) ;
6107
6206
6108
6207
assert_eq ! (
@@ -6111,7 +6210,16 @@ fn change_of_absolute_max_nominations() {
6111
6210
. collect:: <Vec <_>>( ) ,
6112
6211
vec![ ( 101 , 2 ) , ( 61 , 1 ) ]
6113
6212
) ;
6114
- // 70 is still in storage..
6213
+
6214
+ // 101 and 61 still cannot be chilled by someone else.
6215
+ for k in [ 101 , 61 ] . iter ( ) {
6216
+ assert_noop ! (
6217
+ Staking :: chill_other( RuntimeOrigin :: signed( 1 ) , * k) ,
6218
+ Error :: <Test >:: CannotChillOther
6219
+ ) ;
6220
+ }
6221
+
6222
+ // 71 is still in storage..
6115
6223
assert ! ( Nominators :: <Test >:: contains_key( 71 ) ) ;
6116
6224
// but its value cannot be decoded and default is returned.
6117
6225
assert ! ( Nominators :: <Test >:: get( 71 ) . is_none( ) ) ;
@@ -6120,7 +6228,7 @@ fn change_of_absolute_max_nominations() {
6120
6228
assert ! ( Nominators :: <Test >:: contains_key( 101 ) ) ;
6121
6229
6122
6230
// abrupt change from 2 to 1, this should cause some nominators to be non-decodable, and
6123
- // thus non-existent unless if they update.
6231
+ // thus non-existent unless they update.
6124
6232
AbsoluteMaxNominations :: set ( 1 ) ;
6125
6233
6126
6234
assert_eq ! (
@@ -6129,6 +6237,13 @@ fn change_of_absolute_max_nominations() {
6129
6237
. collect:: <Vec <_>>( ) ,
6130
6238
vec![ ( 61 , 1 ) ]
6131
6239
) ;
6240
+
6241
+ // 61 *still* cannot be chilled by someone else.
6242
+ assert_noop ! (
6243
+ Staking :: chill_other( RuntimeOrigin :: signed( 1 ) , 61 ) ,
6244
+ Error :: <Test >:: CannotChillOther
6245
+ ) ;
6246
+
6132
6247
assert ! ( Nominators :: <Test >:: contains_key( 71 ) ) ;
6133
6248
assert ! ( Nominators :: <Test >:: contains_key( 61 ) ) ;
6134
6249
assert ! ( Nominators :: <Test >:: get( 71 ) . is_none( ) ) ;
@@ -6148,6 +6263,7 @@ fn change_of_absolute_max_nominations() {
6148
6263
assert ! ( Nominators :: <Test >:: contains_key( 101 ) ) ;
6149
6264
assert ! ( Nominators :: <Test >:: get( 101 ) . is_none( ) ) ;
6150
6265
assert_ok ! ( Staking :: chill_other( RuntimeOrigin :: signed( 71 ) , 101 ) ) ;
6266
+ assert_eq ! ( * staking_events( ) . last( ) . unwrap( ) , Event :: Chilled { stash: 101 } ) ;
6151
6267
assert ! ( !Nominators :: <Test >:: contains_key( 101 ) ) ;
6152
6268
assert ! ( Nominators :: <Test >:: get( 101 ) . is_none( ) ) ;
6153
6269
} )
0 commit comments