mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 11:07:56 +00:00
Fix fast-unstake for accounts with slashing (#12963)
* Fix fast-unstake for accounts with slashing * ".git/.scripts/fmt.sh" 1 * fmt * fix * fix weight tracking * Adds tests for withdraw_unbonded with slashing * Removes tests for withdraw_unbonded with slashing * ".git/.scripts/fmt.sh" * Adds slash spans calculation test for withdraw_unbonded Co-authored-by: command-bot <> Co-authored-by: gpestana <g6pestana@gmail.com>
This commit is contained in:
@@ -5725,3 +5725,54 @@ fn scale_validator_count_errors() {
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
mod staking_interface {
|
||||
use frame_support::storage::with_storage_layer;
|
||||
use sp_staking::StakingInterface;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn force_unstake_with_slash_works() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
// without slash
|
||||
let _ = with_storage_layer::<(), _, _>(|| {
|
||||
// bond an account, can unstake
|
||||
assert_eq!(Staking::bonded(&11), Some(10));
|
||||
assert_ok!(<Staking as StakingInterface>::force_unstake(11));
|
||||
Err(DispatchError::from("revert"))
|
||||
});
|
||||
|
||||
// bond again and add a slash, still can unstake.
|
||||
assert_eq!(Staking::bonded(&11), Some(10));
|
||||
add_slash(&11);
|
||||
assert_ok!(<Staking as StakingInterface>::force_unstake(11));
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn do_withdraw_unbonded_with_wrong_slash_spans_works_as_expected() {
|
||||
ExtBuilder::default().build_and_execute(|| {
|
||||
on_offence_now(
|
||||
&[OffenceDetails {
|
||||
offender: (11, Staking::eras_stakers(active_era(), 11)),
|
||||
reporters: vec![],
|
||||
}],
|
||||
&[Perbill::from_percent(100)],
|
||||
);
|
||||
|
||||
assert_eq!(Staking::bonded(&11), Some(10));
|
||||
|
||||
assert_noop!(
|
||||
Staking::withdraw_unbonded(RuntimeOrigin::signed(10), 0),
|
||||
Error::<Test>::IncorrectSlashingSpans
|
||||
);
|
||||
|
||||
let num_slashing_spans = Staking::slashing_spans(&11).map_or(0, |s| s.iter().count());
|
||||
assert_ok!(Staking::withdraw_unbonded(
|
||||
RuntimeOrigin::signed(10),
|
||||
num_slashing_spans as u32
|
||||
));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user