@@ -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