mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 10:17:57 +00:00
Prevent dust in staking by disallowing cheap bond_extra (#7718)
* prevent bond_extra to cause staking actve lower than ed * prevent bond_extra to cause staking actve lower than ed * Check in post conditions. * check rebond as well. * also change withdraw_unbonded. * Fix build * change check format. * Apply suggestions from code review Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com> Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
This commit is contained in:
@@ -4696,3 +4696,85 @@ fn payout_to_any_account_works() {
|
||||
assert!(Balances::free_balance(42) > 0);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_bond_extra_to_lower_than_ed() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(10)
|
||||
.build_and_execute(|| {
|
||||
// stash must have more balance than bonded for this to work.
|
||||
assert_eq!(Balances::free_balance(&21), 512_000);
|
||||
|
||||
// initial stuff.
|
||||
assert_eq!(
|
||||
Staking::ledger(&20).unwrap(),
|
||||
StakingLedger {
|
||||
stash: 21,
|
||||
total: 1000,
|
||||
active: 1000,
|
||||
unlocking: vec![],
|
||||
claimed_rewards: vec![]
|
||||
}
|
||||
);
|
||||
|
||||
// unbond all of it.
|
||||
assert_ok!(Staking::unbond(Origin::signed(20), 1000));
|
||||
assert_eq!(
|
||||
Staking::ledger(&20).unwrap(),
|
||||
StakingLedger {
|
||||
stash: 21,
|
||||
total: 1000,
|
||||
active: 0,
|
||||
unlocking: vec![UnlockChunk { value: 1000, era: 3 }],
|
||||
claimed_rewards: vec![]
|
||||
}
|
||||
);
|
||||
|
||||
// now bond a wee bit more
|
||||
assert_noop!(
|
||||
Staking::bond_extra(Origin::signed(21), 5),
|
||||
Error::<Test>::InsufficientValue,
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_rebond_to_lower_than_ed() {
|
||||
ExtBuilder::default()
|
||||
.existential_deposit(10)
|
||||
.build_and_execute(|| {
|
||||
// stash must have more balance than bonded for this to work.
|
||||
assert_eq!(Balances::free_balance(&21), 512_000);
|
||||
|
||||
// initial stuff.
|
||||
assert_eq!(
|
||||
Staking::ledger(&20).unwrap(),
|
||||
StakingLedger {
|
||||
stash: 21,
|
||||
total: 1000,
|
||||
active: 1000,
|
||||
unlocking: vec![],
|
||||
claimed_rewards: vec![]
|
||||
}
|
||||
);
|
||||
|
||||
// unbond all of it.
|
||||
assert_ok!(Staking::unbond(Origin::signed(20), 1000));
|
||||
assert_eq!(
|
||||
Staking::ledger(&20).unwrap(),
|
||||
StakingLedger {
|
||||
stash: 21,
|
||||
total: 1000,
|
||||
active: 0,
|
||||
unlocking: vec![UnlockChunk { value: 1000, era: 3 }],
|
||||
claimed_rewards: vec![]
|
||||
}
|
||||
);
|
||||
|
||||
// now bond a wee bit more
|
||||
assert_noop!(
|
||||
Staking::rebond(Origin::signed(20), 5),
|
||||
Error::<Test>::InsufficientValue,
|
||||
);
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user