@@ -390,9 +390,9 @@ fn rewards_should_work() {
390
390
) ;
391
391
assert_eq_error_rate ! (
392
392
asset:: total_balance:: <Test >( & 101 ) ,
393
- init_balance_101
394
- + part_for_101_from_11 * total_payout_0 * 2 / 3
395
- + part_for_101_from_21 * total_payout_0 * 1 / 3 ,
393
+ init_balance_101 +
394
+ part_for_101_from_11 * total_payout_0 * 2 / 3 +
395
+ part_for_101_from_21 * total_payout_0 * 1 / 3 ,
396
396
2
397
397
) ;
398
398
@@ -430,9 +430,9 @@ fn rewards_should_work() {
430
430
) ;
431
431
assert_eq_error_rate ! (
432
432
asset:: total_balance:: <Test >( & 101 ) ,
433
- init_balance_101
434
- + part_for_101_from_11 * ( total_payout_0 * 2 / 3 + total_payout_1)
435
- + part_for_101_from_21 * total_payout_0 * 1 / 3 ,
433
+ init_balance_101 +
434
+ part_for_101_from_11 * ( total_payout_0 * 2 / 3 + total_payout_1) +
435
+ part_for_101_from_21 * total_payout_0 * 1 / 3 ,
436
436
2
437
437
) ;
438
438
} ) ;
@@ -2863,11 +2863,7 @@ fn slashing_nominators_by_span_max() {
2863
2863
assert_eq ! ( get_span( 101 ) . iter( ) . collect:: <Vec <_>>( ) , expected_spans) ;
2864
2864
2865
2865
// second slash: higher era, higher value, same span.
2866
- on_offence_in_era (
2867
- & [ offence_from ( 21 , None ) ] ,
2868
- & [ Perbill :: from_percent ( 30 ) ] ,
2869
- 3 ,
2870
- ) ;
2866
+ on_offence_in_era ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 30 ) ] , 3 ) ;
2871
2867
2872
2868
// 11 was not further slashed, but 21 and 101 were.
2873
2869
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 11 ) , 900 ) ;
@@ -2908,10 +2904,7 @@ fn slashes_are_summed_across_spans() {
2908
2904
2909
2905
let get_span = |account| SlashingSpans :: < Test > :: get ( & account) . unwrap ( ) ;
2910
2906
2911
- on_offence_now (
2912
- & [ offence_from ( 21 , None ) ] ,
2913
- & [ Perbill :: from_percent ( 10 ) ] ,
2914
- ) ;
2907
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
2915
2908
2916
2909
let expected_spans = vec ! [
2917
2910
slashing:: SlashingSpan { index: 1 , start: 4 , length: None } ,
@@ -2928,10 +2921,7 @@ fn slashes_are_summed_across_spans() {
2928
2921
2929
2922
assert_eq ! ( Staking :: slashable_balance_of( & 21 ) , 900 ) ;
2930
2923
2931
- on_offence_now (
2932
- & [ offence_from ( 21 , None ) ] ,
2933
- & [ Perbill :: from_percent ( 10 ) ] ,
2934
- ) ;
2924
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
2935
2925
2936
2926
let expected_spans = vec ! [
2937
2927
slashing:: SlashingSpan { index: 2 , start: 5 , length: None } ,
@@ -3148,10 +3138,7 @@ fn remove_deferred() {
3148
3138
let nominated_value = exposure. others . iter ( ) . find ( |o| o. who == 101 ) . unwrap ( ) . value ;
3149
3139
3150
3140
// deferred to start of era 4.
3151
- on_offence_now (
3152
- & [ offence_from ( 11 , None ) ] ,
3153
- & [ Perbill :: from_percent ( 10 ) ] ,
3154
- ) ;
3141
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
3155
3142
3156
3143
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 11 ) , 1000 ) ;
3157
3144
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 101 ) , 2000 ) ;
@@ -3160,11 +3147,7 @@ fn remove_deferred() {
3160
3147
3161
3148
// reported later, but deferred to start of era 4 as well.
3162
3149
System :: reset_events ( ) ;
3163
- on_offence_in_era (
3164
- & [ offence_from ( 11 , None ) ] ,
3165
- & [ Perbill :: from_percent ( 15 ) ] ,
3166
- 1 ,
3167
- ) ;
3150
+ on_offence_in_era ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 15 ) ] , 1 ) ;
3168
3151
3169
3152
// fails if empty
3170
3153
assert_noop ! (
@@ -3219,30 +3202,15 @@ fn remove_multi_deferred() {
3219
3202
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 11 ) , 1000 ) ;
3220
3203
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 101 ) , 2000 ) ;
3221
3204
3222
- on_offence_now (
3223
- & [ offence_from ( 11 , None ) ] ,
3224
- & [ Perbill :: from_percent ( 10 ) ] ,
3225
- ) ;
3205
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
3226
3206
3227
- on_offence_now (
3228
- & [ offence_from ( 21 , None ) ] ,
3229
- & [ Perbill :: from_percent ( 10 ) ] ,
3230
- ) ;
3207
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
3231
3208
3232
- on_offence_now (
3233
- & [ offence_from ( 11 , None ) ] ,
3234
- & [ Perbill :: from_percent ( 25 ) ] ,
3235
- ) ;
3209
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3236
3210
3237
- on_offence_now (
3238
- & [ offence_from ( 42 , None ) ] ,
3239
- & [ Perbill :: from_percent ( 25 ) ] ,
3240
- ) ;
3211
+ on_offence_now ( & [ offence_from ( 42 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3241
3212
3242
- on_offence_now (
3243
- & [ offence_from ( 69 , None ) ] ,
3244
- & [ Perbill :: from_percent ( 25 ) ] ,
3245
- ) ;
3213
+ on_offence_now ( & [ offence_from ( 69 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3246
3214
3247
3215
assert_eq ! ( UnappliedSlashes :: <Test >:: get( & 4 ) . len( ) , 5 ) ;
3248
3216
@@ -3297,10 +3265,7 @@ fn slash_kicks_validators_not_nominators_and_disables_nominator_for_kicked_valid
3297
3265
assert_eq ! ( exposure_11. total, 1000 + 125 ) ;
3298
3266
assert_eq ! ( exposure_21. total, 1000 + 375 ) ;
3299
3267
3300
- on_offence_now (
3301
- & [ offence_from ( 11 , None ) ] ,
3302
- & [ Perbill :: from_percent ( 10 ) ] ,
3303
- ) ;
3268
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
3304
3269
3305
3270
assert_eq ! (
3306
3271
staking_events_since_last_call( ) ,
@@ -3359,19 +3324,13 @@ fn non_slashable_offence_disables_validator() {
3359
3324
assert_eq_uvec ! ( Session :: validators( ) , vec![ 11 , 21 , 31 , 41 , 51 , 201 , 202 ] ) ;
3360
3325
3361
3326
// offence with no slash associated
3362
- on_offence_now (
3363
- & [ offence_from ( 11 , None ) ] ,
3364
- & [ Perbill :: zero ( ) ] ,
3365
- ) ;
3327
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: zero ( ) ] ) ;
3366
3328
3367
3329
// it does NOT affect the nominator.
3368
3330
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
3369
3331
3370
3332
// offence that slashes 25% of the bond
3371
- on_offence_now (
3372
- & [ offence_from ( 21 , None ) ] ,
3373
- & [ Perbill :: from_percent ( 25 ) ] ,
3374
- ) ;
3333
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3375
3334
3376
3335
// it DOES NOT affect the nominator.
3377
3336
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -3426,11 +3385,7 @@ fn slashing_independent_of_disabling_validator() {
3426
3385
3427
3386
// --- Disable without a slash ---
3428
3387
// offence with no slash associated
3429
- on_offence_in_era (
3430
- & [ offence_from ( 11 , None ) ] ,
3431
- & [ Perbill :: zero ( ) ] ,
3432
- now,
3433
- ) ;
3388
+ on_offence_in_era ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: zero ( ) ] , now) ;
3434
3389
3435
3390
// nomination remains untouched.
3436
3391
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -3440,18 +3395,10 @@ fn slashing_independent_of_disabling_validator() {
3440
3395
3441
3396
// --- Slash without disabling ---
3442
3397
// offence that slashes 50% of the bond (setup for next slash)
3443
- on_offence_in_era (
3444
- & [ offence_from ( 11 , None ) ] ,
3445
- & [ Perbill :: from_percent ( 50 ) ] ,
3446
- now,
3447
- ) ;
3398
+ on_offence_in_era ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 50 ) ] , now) ;
3448
3399
3449
3400
// offence that slashes 25% of the bond but does not disable
3450
- on_offence_in_era (
3451
- & [ offence_from ( 21 , None ) ] ,
3452
- & [ Perbill :: from_percent ( 25 ) ] ,
3453
- now,
3454
- ) ;
3401
+ on_offence_in_era ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] , now) ;
3455
3402
3456
3403
// nomination remains untouched.
3457
3404
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -3517,31 +3464,22 @@ fn offence_threshold_doesnt_trigger_new_era() {
3517
3464
3518
3465
// we have 4 validators and an offending validator threshold of 1/3,
3519
3466
// even if the third validator commits an offence a new era should not be forced
3520
- on_offence_now (
3521
- & [ offence_from ( 11 , None ) ] ,
3522
- & [ Perbill :: from_percent ( 50 ) ] ,
3523
- ) ;
3467
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 50 ) ] ) ;
3524
3468
3525
3469
// 11 should be disabled because the byzantine threshold is 1
3526
3470
assert ! ( is_disabled( 11 ) ) ;
3527
3471
3528
3472
assert_eq ! ( ForceEra :: <Test >:: get( ) , Forcing :: NotForcing ) ;
3529
3473
3530
- on_offence_now (
3531
- & [ offence_from ( 21 , None ) ] ,
3532
- & [ Perbill :: zero ( ) ] ,
3533
- ) ;
3474
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: zero ( ) ] ) ;
3534
3475
3535
3476
// 21 should not be disabled because the number of disabled validators will be above the
3536
3477
// byzantine threshold
3537
3478
assert ! ( !is_disabled( 21 ) ) ;
3538
3479
3539
3480
assert_eq ! ( ForceEra :: <Test >:: get( ) , Forcing :: NotForcing ) ;
3540
3481
3541
- on_offence_now (
3542
- & [ offence_from ( 31 , None ) ] ,
3543
- & [ Perbill :: zero ( ) ] ,
3544
- ) ;
3482
+ on_offence_now ( & [ offence_from ( 31 , None ) ] , & [ Perbill :: zero ( ) ] ) ;
3545
3483
3546
3484
// same for 31
3547
3485
assert ! ( !is_disabled( 31 ) ) ;
@@ -3563,10 +3501,7 @@ fn disabled_validators_are_kept_disabled_for_whole_era() {
3563
3501
assert_eq_uvec ! ( Session :: validators( ) , vec![ 11 , 21 , 31 , 41 , 51 , 201 , 202 ] ) ;
3564
3502
assert_eq ! ( <Test as Config >:: SessionsPerEra :: get( ) , 3 ) ;
3565
3503
3566
- on_offence_now (
3567
- & [ offence_from ( 21 , None ) ] ,
3568
- & [ Perbill :: from_percent ( 25 ) ] ,
3569
- ) ;
3504
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3570
3505
3571
3506
// nominations are not updated.
3572
3507
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -3580,10 +3515,7 @@ fn disabled_validators_are_kept_disabled_for_whole_era() {
3580
3515
assert ! ( is_disabled( 21 ) ) ;
3581
3516
3582
3517
// validator 11 commits an offence
3583
- on_offence_now (
3584
- & [ offence_from ( 11 , None ) ] ,
3585
- & [ Perbill :: from_percent ( 25 ) ] ,
3586
- ) ;
3518
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 25 ) ] ) ;
3587
3519
3588
3520
// nominations are not updated.
3589
3521
assert_eq ! ( Nominators :: <Test >:: get( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -3701,10 +3633,7 @@ fn zero_slash_keeps_nominators() {
3701
3633
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 11 ) , 1000 ) ;
3702
3634
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 101 ) , 2000 ) ;
3703
3635
3704
- on_offence_now (
3705
- & [ offence_from ( 11 , None ) ] ,
3706
- & [ Perbill :: from_percent ( 0 ) ] ,
3707
- ) ;
3636
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 0 ) ] ) ;
3708
3637
3709
3638
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 11 ) , 1000 ) ;
3710
3639
assert_eq ! ( asset:: stakeable_balance:: <Test >( & 101 ) , 2000 ) ;
@@ -6890,8 +6819,8 @@ fn test_validator_exposure_is_backward_compatible_with_non_paged_rewards_payout(
6890
6819
let actual_exposure_page_1 = ErasStakersPaged :: < Test > :: get ( ( 1 , 11 , 1 ) ) . unwrap ( ) ;
6891
6820
expected_individual_exposures. iter ( ) . for_each ( |exposure| {
6892
6821
assert ! (
6893
- actual_exposure_page_0. others. contains( exposure)
6894
- || actual_exposure_page_1. others. contains( exposure)
6822
+ actual_exposure_page_0. others. contains( exposure) ||
6823
+ actual_exposure_page_1. others. contains( exposure)
6895
6824
) ;
6896
6825
} ) ;
6897
6826
assert_eq ! (
@@ -7394,10 +7323,7 @@ mod staking_unchecked {
7394
7323
let exposed_nominator = initial_exposure. others . first ( ) . unwrap ( ) . value ;
7395
7324
7396
7325
// 11 goes offline
7397
- on_offence_now (
7398
- & [ offence_from ( 11 , None ) ] ,
7399
- & [ slash_percent] ,
7400
- ) ;
7326
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ slash_percent] ) ;
7401
7327
7402
7328
let slash_amount = slash_percent * exposed_stake;
7403
7329
let validator_share =
@@ -7463,10 +7389,7 @@ mod staking_unchecked {
7463
7389
let nominator_stake = Staking :: ledger ( 101 . into ( ) ) . unwrap ( ) . total ;
7464
7390
7465
7391
// 11 goes offline
7466
- on_offence_now (
7467
- & [ offence_from ( 11 , None ) ] ,
7468
- & [ slash_percent] ,
7469
- ) ;
7392
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ slash_percent] ) ;
7470
7393
7471
7394
// both stakes must have been decreased to 0.
7472
7395
assert_eq ! ( Staking :: ledger( 101 . into( ) ) . unwrap( ) . active, 0 ) ;
@@ -8606,14 +8529,8 @@ fn reenable_lower_offenders_mock() {
8606
8529
assert_eq_uvec ! ( Session :: validators( ) , vec![ 11 , 21 , 31 , 41 , 51 , 201 , 202 ] ) ;
8607
8530
8608
8531
// offence with a low slash
8609
- on_offence_now (
8610
- & [ offence_from ( 11 , None ) ] ,
8611
- & [ Perbill :: from_percent ( 10 ) ] ,
8612
- ) ;
8613
- on_offence_now (
8614
- & [ offence_from ( 21 , None ) ] ,
8615
- & [ Perbill :: from_percent ( 20 ) ] ,
8616
- ) ;
8532
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
8533
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 20 ) ] ) ;
8617
8534
8618
8535
// it does NOT affect the nominator.
8619
8536
assert_eq ! ( Staking :: nominators( 101 ) . unwrap( ) . targets, vec![ 11 , 21 ] ) ;
@@ -8623,10 +8540,7 @@ fn reenable_lower_offenders_mock() {
8623
8540
assert ! ( is_disabled( 21 ) ) ;
8624
8541
8625
8542
// offence with a higher slash
8626
- on_offence_now (
8627
- & [ offence_from ( 31 , None ) ] ,
8628
- & [ Perbill :: from_percent ( 50 ) ] ,
8629
- ) ;
8543
+ on_offence_now ( & [ offence_from ( 31 , None ) ] , & [ Perbill :: from_percent ( 50 ) ] ) ;
8630
8544
8631
8545
// First offender is no longer disabled
8632
8546
assert ! ( !is_disabled( 11 ) ) ;
@@ -8689,24 +8603,15 @@ fn do_not_reenable_higher_offenders_mock() {
8689
8603
assert_eq_uvec ! ( Session :: validators( ) , vec![ 11 , 21 , 31 , 41 , 51 , 201 , 202 ] ) ;
8690
8604
8691
8605
// offence with a major slash
8692
- on_offence_now (
8693
- & [ offence_from ( 11 , None ) ] ,
8694
- & [ Perbill :: from_percent ( 50 ) ] ,
8695
- ) ;
8696
- on_offence_now (
8697
- & [ offence_from ( 21 , None ) ] ,
8698
- & [ Perbill :: from_percent ( 50 ) ] ,
8699
- ) ;
8606
+ on_offence_now ( & [ offence_from ( 11 , None ) ] , & [ Perbill :: from_percent ( 50 ) ] ) ;
8607
+ on_offence_now ( & [ offence_from ( 21 , None ) ] , & [ Perbill :: from_percent ( 50 ) ] ) ;
8700
8608
8701
8609
// both validators should be disabled
8702
8610
assert ! ( is_disabled( 11 ) ) ;
8703
8611
assert ! ( is_disabled( 21 ) ) ;
8704
8612
8705
8613
// offence with a minor slash
8706
- on_offence_now (
8707
- & [ offence_from ( 31 , None ) ] ,
8708
- & [ Perbill :: from_percent ( 10 ) ] ,
8709
- ) ;
8614
+ on_offence_now ( & [ offence_from ( 31 , None ) ] , & [ Perbill :: from_percent ( 10 ) ] ) ;
8710
8615
8711
8616
// First and second offenders are still disabled
8712
8617
assert ! ( is_disabled( 11 ) ) ;
@@ -9496,8 +9401,8 @@ fn manual_slashing_works() {
9496
9401
let expected_balance_1 = initial_balance - ( initial_balance / 4 ) ; // 25% slash
9497
9402
9498
9403
assert ! (
9499
- balance_after_first_slash <= expected_balance_1
9500
- && balance_after_first_slash >= expected_balance_1 - 5 ,
9404
+ balance_after_first_slash <= expected_balance_1 &&
9405
+ balance_after_first_slash >= expected_balance_1 - 5 ,
9501
9406
"First slash was not applied correctly. Expected around {}, got {}" ,
9502
9407
expected_balance_1,
9503
9408
balance_after_first_slash
@@ -9549,8 +9454,8 @@ fn manual_slashing_works() {
9549
9454
let expected_balance_3 = initial_balance / 2 ; // 50% of original
9550
9455
9551
9456
assert ! (
9552
- balance_after_third_slash <= expected_balance_3
9553
- && balance_after_third_slash >= expected_balance_3 - 5 ,
9457
+ balance_after_third_slash <= expected_balance_3 &&
9458
+ balance_after_third_slash >= expected_balance_3 - 5 ,
9554
9459
"Third slash was not applied correctly. Expected around {}, got {}" ,
9555
9460
expected_balance_3,
9556
9461
balance_after_third_slash
@@ -9592,8 +9497,8 @@ fn manual_slashing_works() {
9592
9497
let expected_balance_5 = initial_balance / 4 ; // 25% of original (75% slashed)
9593
9498
9594
9499
assert ! (
9595
- balance_after_fifth_slash <= expected_balance_5
9596
- && balance_after_fifth_slash >= expected_balance_5 - 5 ,
9500
+ balance_after_fifth_slash <= expected_balance_5 &&
9501
+ balance_after_fifth_slash >= expected_balance_5 - 5 ,
9597
9502
"Fifth slash was not applied correctly. Expected around {}, got {}" ,
9598
9503
expected_balance_5,
9599
9504
balance_after_fifth_slash
0 commit comments