Skip to content

Commit ee63a7b

Browse files
committed
delegation: fix delegation withdrawal tests
1 parent 502fa51 commit ee63a7b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

test/staking/delegation.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe('Staking::Delegation', () => {
8484
? beforeShares.mul(beforePool.tokens).div(beforePool.shares)
8585
: toBN(0)
8686
const beforeDelegatorBalance = await grt.balanceOf(sender.address)
87+
const tokensToWithdraw = await staking.getWithdraweableDelegatedTokens(beforeDelegation)
8788

8889
// Calculate tokens to receive
8990
const tokens = shares.mul(beforePool.shares).div(beforePool.tokens)
@@ -112,11 +113,14 @@ describe('Staking::Delegation', () => {
112113
expect(afterPool.shares).eq(beforePool.shares.sub(shares))
113114
expect(afterShares).eq(beforeShares.sub(shares))
114115
expect(afterTokens).eq(beforeTokens.sub(tokens))
116+
115117
// 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+
)
117121
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))
120124
}
121125

122126
async function shouldWithdrawDelegated(sender: Account, redelegateTo: string, tokens: BigNumber) {
@@ -383,8 +387,12 @@ describe('Staking::Delegation', () => {
383387
})
384388

385389
it('should undelegate and withdraw freed tokens from unbonding period', async function () {
390+
await staking.setDelegationUnbondingPeriod('2')
386391
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'))
388396
})
389397
})
390398

0 commit comments

Comments
 (0)