Skip to content

Commit 4fb160c

Browse files
committed
slashing_performed_according_exposure update(need discuss)
1 parent 9751511 commit 4fb160c

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

srml/staking/src/tests.rs

+30-28
Original file line numberDiff line numberDiff line change
@@ -2282,34 +2282,36 @@ fn offence_deselects_validator_when_slash_is_zero() {
22822282
});
22832283
}
22842284

2285-
// TODO
2286-
//#[test]
2287-
//fn slashing_performed_according_exposure() {
2288-
// // This test checks that slashing is performed according the exposure (or more precisely,
2289-
// // historical exposure), not the current balance.
2290-
// ExtBuilder::default().build().execute_with(|| {
2291-
// assert_eq!(Staking::stakers(&11).own, 1000);
2292-
//
2293-
// // Handle an offence with a historical exposure.
2294-
// Staking::on_offence(
2295-
// &[OffenceDetails {
2296-
// offender: (
2297-
// 11,
2298-
// Exposure {
2299-
// total: 500,
2300-
// own: 500,
2301-
// others: vec![],
2302-
// },
2303-
// ),
2304-
// reporters: vec![],
2305-
// }],
2306-
// &[Perbill::from_percent(50)],
2307-
// );
2308-
//
2309-
// // The stash account should be slashed for 250 (50% of 500).
2310-
// assert_eq!(Balances::free_balance(&11), 1000 - 250);
2311-
// });
2312-
//}
2285+
// Question: our slashing is performed according to the current balance, not the exposure, is this what we want?
2286+
#[test]
2287+
fn slashing_performed_according_exposure() {
2288+
// This test checks that slashing is performed according the exposure (or more precisely,
2289+
// historical exposure), not the current balance.
2290+
ExtBuilder::default().build().execute_with(|| {
2291+
assert_eq!(Staking::stakers(&11).own, compute_power(1000, 0));
2292+
2293+
//println!("{:#?}", compute_power(500, 0));
2294+
// Handle an offence with a historical exposure.
2295+
Staking::on_offence(
2296+
&[OffenceDetails {
2297+
offender: (
2298+
11,
2299+
Exposure {
2300+
total: compute_power(500, 0),
2301+
own: compute_power(500, 0),
2302+
others: vec![],
2303+
},
2304+
),
2305+
reporters: vec![],
2306+
}],
2307+
&[Perbill::from_percent(40)],
2308+
);
2309+
2310+
// The stash account should be slashed for 250 (50% of 500).
2311+
//assert_eq!(Ring::free_balance(&11), 1000 - 250);
2312+
assert_eq!(Ring::free_balance(&11), 1000 - Perbill::from_percent(40) * 1000);
2313+
});
2314+
}
23132315

23142316
#[test]
23152317
fn reporters_receive_their_slice() {

0 commit comments

Comments
 (0)