Skip to content

Commit 2fb04c5

Browse files
committed
found a bug while unbonding
1 parent 6bd5e2c commit 2fb04c5

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

substrate/frame/delegated-staking/src/mock.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl pallet_staking::Config for Runtime {
130130
type VoterList = pallet_staking::UseNominatorsAndValidatorsMap<Self>;
131131
type TargetList = pallet_staking::UseValidatorsMap<Self>;
132132
type NominationsQuota = pallet_staking::FixedNominationsQuota<16>;
133-
type MaxUnlockingChunks = ConstU32<32>;
133+
type MaxUnlockingChunks = ConstU32<10>;
134134
type MaxControllersInDeprecationBatch = ConstU32<100>;
135135
type EventListeners = DelegatedStaking;
136136
type BenchmarkingConfig = pallet_staking::TestBenchmarkingConfig;

substrate/frame/delegated-staking/src/tests.rs

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -432,19 +432,36 @@ mod staking_integration {
432432
#[test]
433433
fn withdraw_happens_with_unbonded_balance_first() {
434434
ExtBuilder::default().build_and_execute(|| {
435+
start_era(1);
435436
let agent = 200;
436-
setup_delegation_stake(agent, 201, (300..350).collect(), 100, 0);
437+
setup_delegation_stake(agent, 201, (300..350).collect(), 10, 10);
437438

438439
// verify withdraw not possible yet
439440
assert_noop!(
440441
DelegatedStaking::release_delegation(RawOrigin::Signed(agent).into(), 300, 100, 0),
441442
Error::<T>::NotEnoughFunds
442443
);
443444

444-
// add new delegation that is not staked
445+
// fill up unlocking chunks in core staking.
446+
// 10 is the max chunks
447+
for i in 2..=11 {
448+
start_era(i);
449+
assert_ok!(Staking::unbond(RawOrigin::Signed(agent).into(), 10));
450+
// no withdrawals from core staking yet.
451+
assert_eq!(get_agent(&agent).ledger.unclaimed_withdrawals, 0);
452+
}
453+
454+
// another unbond would trigger withdrawal
455+
start_era(12);
456+
assert_ok!(Staking::unbond(RawOrigin::Signed(agent).into(), 10));
457+
// 8 previous unbonds would be withdrawn as they were already unlocked. Unlocking period
458+
// is 3 eras.
459+
460+
// FIXME(ank4n): Since staking implicitly withdraws ledger, unclaimed withdrawals are
461+
// not updated. This is bad since it can lead those funds to be re-bonded.
462+
463+
// assert_eq!(get_agent(&agent).ledger.unclaimed_withdrawals, 8 * 10);
445464

446-
// FIXME(ank4n): add scenario where staked funds are withdrawn from ledger but not
447-
// withdrawn and test its claimed from there first.
448465

449466
// fund(&300, 1000);
450467
// assert_ok!(DelegatedStaking::delegate_to_agent(RawOrigin::Signed(300.into()),
@@ -531,15 +548,6 @@ mod staking_integration {
531548
});
532549
}
533550

534-
#[test]
535-
fn slash_works() {
536-
ExtBuilder::default().build_and_execute(|| {
537-
setup_delegation_stake(200, 201, (210..250).collect(), 100, 0);
538-
start_era(1);
539-
// fixme(ank4n): add tests for slashing
540-
});
541-
}
542-
543551
#[test]
544552
fn migration_works() {
545553
ExtBuilder::default().build_and_execute(|| {

0 commit comments

Comments
 (0)