Skip to content

Commit 755aacb

Browse files
committed
fmt
1 parent e6fc0c1 commit 755aacb

File tree

1 file changed

+44
-139
lines changed

1 file changed

+44
-139
lines changed

substrate/frame/staking/src/tests.rs

+44-139
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ fn rewards_should_work() {
390390
);
391391
assert_eq_error_rate!(
392392
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,
396396
2
397397
);
398398

@@ -430,9 +430,9 @@ fn rewards_should_work() {
430430
);
431431
assert_eq_error_rate!(
432432
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,
436436
2
437437
);
438438
});
@@ -2863,11 +2863,7 @@ fn slashing_nominators_by_span_max() {
28632863
assert_eq!(get_span(101).iter().collect::<Vec<_>>(), expected_spans);
28642864

28652865
// 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);
28712867

28722868
// 11 was not further slashed, but 21 and 101 were.
28732869
assert_eq!(asset::stakeable_balance::<Test>(&11), 900);
@@ -2908,10 +2904,7 @@ fn slashes_are_summed_across_spans() {
29082904

29092905
let get_span = |account| SlashingSpans::<Test>::get(&account).unwrap();
29102906

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)]);
29152908

29162909
let expected_spans = vec![
29172910
slashing::SlashingSpan { index: 1, start: 4, length: None },
@@ -2928,10 +2921,7 @@ fn slashes_are_summed_across_spans() {
29282921

29292922
assert_eq!(Staking::slashable_balance_of(&21), 900);
29302923

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)]);
29352925

29362926
let expected_spans = vec![
29372927
slashing::SlashingSpan { index: 2, start: 5, length: None },
@@ -3148,10 +3138,7 @@ fn remove_deferred() {
31483138
let nominated_value = exposure.others.iter().find(|o| o.who == 101).unwrap().value;
31493139

31503140
// 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)]);
31553142

31563143
assert_eq!(asset::stakeable_balance::<Test>(&11), 1000);
31573144
assert_eq!(asset::stakeable_balance::<Test>(&101), 2000);
@@ -3160,11 +3147,7 @@ fn remove_deferred() {
31603147

31613148
// reported later, but deferred to start of era 4 as well.
31623149
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);
31683151

31693152
// fails if empty
31703153
assert_noop!(
@@ -3219,30 +3202,15 @@ fn remove_multi_deferred() {
32193202
assert_eq!(asset::stakeable_balance::<Test>(&11), 1000);
32203203
assert_eq!(asset::stakeable_balance::<Test>(&101), 2000);
32213204

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)]);
32263206

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)]);
32313208

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)]);
32363210

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)]);
32413212

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)]);
32463214

32473215
assert_eq!(UnappliedSlashes::<Test>::get(&4).len(), 5);
32483216

@@ -3297,10 +3265,7 @@ fn slash_kicks_validators_not_nominators_and_disables_nominator_for_kicked_valid
32973265
assert_eq!(exposure_11.total, 1000 + 125);
32983266
assert_eq!(exposure_21.total, 1000 + 375);
32993267

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)]);
33043269

33053270
assert_eq!(
33063271
staking_events_since_last_call(),
@@ -3359,19 +3324,13 @@ fn non_slashable_offence_disables_validator() {
33593324
assert_eq_uvec!(Session::validators(), vec![11, 21, 31, 41, 51, 201, 202]);
33603325

33613326
// 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()]);
33663328

33673329
// it does NOT affect the nominator.
33683330
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
33693331

33703332
// 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)]);
33753334

33763335
// it DOES NOT affect the nominator.
33773336
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
@@ -3426,11 +3385,7 @@ fn slashing_independent_of_disabling_validator() {
34263385

34273386
// --- Disable without a slash ---
34283387
// 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);
34343389

34353390
// nomination remains untouched.
34363391
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
@@ -3440,18 +3395,10 @@ fn slashing_independent_of_disabling_validator() {
34403395

34413396
// --- Slash without disabling ---
34423397
// 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);
34483399

34493400
// 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);
34553402

34563403
// nomination remains untouched.
34573404
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
@@ -3517,31 +3464,22 @@ fn offence_threshold_doesnt_trigger_new_era() {
35173464

35183465
// we have 4 validators and an offending validator threshold of 1/3,
35193466
// 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)]);
35243468

35253469
// 11 should be disabled because the byzantine threshold is 1
35263470
assert!(is_disabled(11));
35273471

35283472
assert_eq!(ForceEra::<Test>::get(), Forcing::NotForcing);
35293473

3530-
on_offence_now(
3531-
&[offence_from(21, None)],
3532-
&[Perbill::zero()],
3533-
);
3474+
on_offence_now(&[offence_from(21, None)], &[Perbill::zero()]);
35343475

35353476
// 21 should not be disabled because the number of disabled validators will be above the
35363477
// byzantine threshold
35373478
assert!(!is_disabled(21));
35383479

35393480
assert_eq!(ForceEra::<Test>::get(), Forcing::NotForcing);
35403481

3541-
on_offence_now(
3542-
&[offence_from(31, None)],
3543-
&[Perbill::zero()],
3544-
);
3482+
on_offence_now(&[offence_from(31, None)], &[Perbill::zero()]);
35453483

35463484
// same for 31
35473485
assert!(!is_disabled(31));
@@ -3563,10 +3501,7 @@ fn disabled_validators_are_kept_disabled_for_whole_era() {
35633501
assert_eq_uvec!(Session::validators(), vec![11, 21, 31, 41, 51, 201, 202]);
35643502
assert_eq!(<Test as Config>::SessionsPerEra::get(), 3);
35653503

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)]);
35703505

35713506
// nominations are not updated.
35723507
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
@@ -3580,10 +3515,7 @@ fn disabled_validators_are_kept_disabled_for_whole_era() {
35803515
assert!(is_disabled(21));
35813516

35823517
// 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)]);
35873519

35883520
// nominations are not updated.
35893521
assert_eq!(Nominators::<Test>::get(101).unwrap().targets, vec![11, 21]);
@@ -3701,10 +3633,7 @@ fn zero_slash_keeps_nominators() {
37013633
assert_eq!(asset::stakeable_balance::<Test>(&11), 1000);
37023634
assert_eq!(asset::stakeable_balance::<Test>(&101), 2000);
37033635

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)]);
37083637

37093638
assert_eq!(asset::stakeable_balance::<Test>(&11), 1000);
37103639
assert_eq!(asset::stakeable_balance::<Test>(&101), 2000);
@@ -6890,8 +6819,8 @@ fn test_validator_exposure_is_backward_compatible_with_non_paged_rewards_payout(
68906819
let actual_exposure_page_1 = ErasStakersPaged::<Test>::get((1, 11, 1)).unwrap();
68916820
expected_individual_exposures.iter().for_each(|exposure| {
68926821
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)
68956824
);
68966825
});
68976826
assert_eq!(
@@ -7394,10 +7323,7 @@ mod staking_unchecked {
73947323
let exposed_nominator = initial_exposure.others.first().unwrap().value;
73957324

73967325
// 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]);
74017327

74027328
let slash_amount = slash_percent * exposed_stake;
74037329
let validator_share =
@@ -7463,10 +7389,7 @@ mod staking_unchecked {
74637389
let nominator_stake = Staking::ledger(101.into()).unwrap().total;
74647390

74657391
// 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]);
74707393

74717394
// both stakes must have been decreased to 0.
74727395
assert_eq!(Staking::ledger(101.into()).unwrap().active, 0);
@@ -8606,14 +8529,8 @@ fn reenable_lower_offenders_mock() {
86068529
assert_eq_uvec!(Session::validators(), vec![11, 21, 31, 41, 51, 201, 202]);
86078530

86088531
// 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)]);
86178534

86188535
// it does NOT affect the nominator.
86198536
assert_eq!(Staking::nominators(101).unwrap().targets, vec![11, 21]);
@@ -8623,10 +8540,7 @@ fn reenable_lower_offenders_mock() {
86238540
assert!(is_disabled(21));
86248541

86258542
// 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)]);
86308544

86318545
// First offender is no longer disabled
86328546
assert!(!is_disabled(11));
@@ -8689,24 +8603,15 @@ fn do_not_reenable_higher_offenders_mock() {
86898603
assert_eq_uvec!(Session::validators(), vec![11, 21, 31, 41, 51, 201, 202]);
86908604

86918605
// 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)]);
87008608

87018609
// both validators should be disabled
87028610
assert!(is_disabled(11));
87038611
assert!(is_disabled(21));
87048612

87058613
// 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)]);
87108615

87118616
// First and second offenders are still disabled
87128617
assert!(is_disabled(11));
@@ -9496,8 +9401,8 @@ fn manual_slashing_works() {
94969401
let expected_balance_1 = initial_balance - (initial_balance / 4); // 25% slash
94979402

94989403
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,
95019406
"First slash was not applied correctly. Expected around {}, got {}",
95029407
expected_balance_1,
95039408
balance_after_first_slash
@@ -9549,8 +9454,8 @@ fn manual_slashing_works() {
95499454
let expected_balance_3 = initial_balance / 2; // 50% of original
95509455

95519456
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,
95549459
"Third slash was not applied correctly. Expected around {}, got {}",
95559460
expected_balance_3,
95569461
balance_after_third_slash
@@ -9592,8 +9497,8 @@ fn manual_slashing_works() {
95929497
let expected_balance_5 = initial_balance / 4; // 25% of original (75% slashed)
95939498

95949499
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,
95979502
"Fifth slash was not applied correctly. Expected around {}, got {}",
95989503
expected_balance_5,
95999504
balance_after_fifth_slash

0 commit comments

Comments
 (0)