Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Test that era offset works correctly
  • Loading branch information
emostov committed Mar 21, 2022
commit 7c3ca1e916c6839fe0f91665d30a6e757f63cfaf
2 changes: 0 additions & 2 deletions frame/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,6 @@ impl<T: Config> StakingLedger<T> {
let pre_slash_total = self.total;

let era_after_slash = slash_era + 1;
// TODO: test to make sure chunks before the slash are never slashed.
// at this era onwards, the funds can be slashed.
let chunk_unlock_era_after_slash = era_after_slash + T::BondingDuration::get();

// Calculate the total balance of active funds and unlocking funds in the affected range.
Expand Down
13 changes: 13 additions & 0 deletions frame/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4850,6 +4850,19 @@ fn ledger_slash_works() {
assert_eq!(LedgerSlashPerEra::get().0, 0);
assert_eq!(LedgerSlashPerEra::get().1, BTreeMap::from([(4, 0), (5, 0)]));

// TODO test does not slash earlier eras
// Given
ledger.unlocking = bounded_vec![c(4, 100), c(5, 100), c(6, 100), c(7, 100)];
ledger.total = 4 * 100;
ledger.active = 0;
// When the first 2 chunks don't overlap with the affected range of unlock eras.
assert_eq!(ledger.slash(140, 0, 2), 140); // TODO
// Then
assert_eq!(ledger.unlocking, vec![c(4, 100), c(5, 100), c(6, 30), c(7, 30)]);
assert_eq!(ledger.total, 4 * 100 - 140);
assert_eq!(LedgerSlashPerEra::get().0, 0);
assert_eq!(LedgerSlashPerEra::get().1, BTreeMap::from([(6, 30), (7, 30)]));

// Given
ledger.unlocking = bounded_vec![c(4, 40), c(5, 100), c(6, 10), c(7, 250)];
ledger.active = 500;
Expand Down