@@ -84,6 +84,7 @@ describe('Staking::Delegation', () => {
84
84
? beforeShares . mul ( beforePool . tokens ) . div ( beforePool . shares )
85
85
: toBN ( 0 )
86
86
const beforeDelegatorBalance = await grt . balanceOf ( sender . address )
87
+ const tokensToWithdraw = await staking . getWithdraweableDelegatedTokens ( beforeDelegation )
87
88
88
89
// Calculate tokens to receive
89
90
const tokens = shares . mul ( beforePool . shares ) . div ( beforePool . tokens )
@@ -112,11 +113,14 @@ describe('Staking::Delegation', () => {
112
113
expect ( afterPool . shares ) . eq ( beforePool . shares . sub ( shares ) )
113
114
expect ( afterShares ) . eq ( beforeShares . sub ( shares ) )
114
115
expect ( afterTokens ) . eq ( beforeTokens . sub ( tokens ) )
116
+
115
117
// Undelegated funds must be put on lock
116
- expect ( afterDelegation . tokensLocked ) . eq ( beforeDelegation . tokensLocked . add ( tokens ) )
118
+ expect ( afterDelegation . tokensLocked ) . eq (
119
+ beforeDelegation . tokensLocked . add ( tokens ) . sub ( tokensToWithdraw ) ,
120
+ )
117
121
expect ( afterDelegation . tokensLockedUntil ) . eq ( tokensLockedUntil )
118
- // No funds must be transferred to the delegator
119
- expect ( afterDelegatorBalance ) . eq ( beforeDelegatorBalance )
122
+ // Delegator see balance increased only if there were tokens to withdraw
123
+ expect ( afterDelegatorBalance ) . eq ( beforeDelegatorBalance . add ( tokensToWithdraw ) )
120
124
}
121
125
122
126
async function shouldWithdrawDelegated ( sender : Account , redelegateTo : string , tokens : BigNumber ) {
@@ -383,8 +387,12 @@ describe('Staking::Delegation', () => {
383
387
} )
384
388
385
389
it ( 'should undelegate and withdraw freed tokens from unbonding period' , async function ( ) {
390
+ await staking . setDelegationUnbondingPeriod ( '2' )
386
391
await shouldDelegate ( delegator , toGRT ( '100' ) )
387
- await shouldUndelegate ( delegator2 , toGRT ( '50' ) )
392
+ await shouldUndelegate ( delegator , toGRT ( '50' ) )
393
+ await advanceToNextEpoch ( epochManager ) // epoch 1
394
+ await advanceToNextEpoch ( epochManager ) // epoch 2
395
+ await shouldUndelegate ( delegator , toGRT ( '10' ) )
388
396
} )
389
397
} )
390
398
0 commit comments