@@ -239,6 +239,40 @@ describe('Staking:Stakes', () => {
239
239
expect ( afterIndexerStake . tokensLockedUntil ) . eq ( expectedLockedUntil )
240
240
} )
241
241
242
+ it ( 'should always increase the thawing period on subsequent unstakes' , async function ( ) {
243
+ const tokensToUnstake = toGRT ( '10' )
244
+ const tokensToUnstakeSecondTime = toGRT ( '0.000001' )
245
+ const thawingPeriod = toBN ( await staking . thawingPeriod ( ) )
246
+
247
+ // Unstake (1)
248
+ const tx1 = await staking . connect ( indexer ) . unstake ( tokensToUnstake )
249
+ const receipt1 = await tx1 . wait ( )
250
+ const event1 : Event = receipt1 . events . pop ( )
251
+ const tokensLockedUntil1 = event1 . args [ 'until' ]
252
+
253
+ // Move forward before the tokens are unlocked for withdrawal
254
+ await helpers . mineUpTo ( tokensLockedUntil1 . sub ( 5 ) )
255
+
256
+ // Calculate locking time for tokens taking into account the previous unstake request
257
+ const currentBlock = await helpers . latestBlock ( )
258
+
259
+ // Ensure at least 1 block is added (i.e. the weighted average rounds up)
260
+ const expectedLockedUntil = tokensLockedUntil1 . add ( 1 )
261
+
262
+ // Unstake (2)
263
+ const tx2 = await staking . connect ( indexer ) . unstake ( tokensToUnstakeSecondTime )
264
+ const receipt2 = await tx2 . wait ( )
265
+
266
+ // Verify events
267
+ const event2 : Event = receipt2 . events . pop ( )
268
+ expect ( event2 . args [ 'until' ] ) . eq ( expectedLockedUntil )
269
+
270
+ // Verify state
271
+ const afterIndexerStake = await staking . stakes ( indexer . address )
272
+ expect ( afterIndexerStake . tokensLocked ) . eq ( tokensToUnstake . add ( tokensToUnstakeSecondTime ) ) // we unstaked two times
273
+ expect ( afterIndexerStake . tokensLockedUntil ) . eq ( expectedLockedUntil )
274
+ } )
275
+
242
276
it ( 'should unstake and withdraw if some tokens are unthawed' , async function ( ) {
243
277
const tokensToUnstake = toGRT ( '10' )
244
278
const thawingPeriod = toBN ( await staking . thawingPeriod ( ) )
0 commit comments