@@ -14,10 +14,11 @@ import {
14
14
latestBlock ,
15
15
toBN ,
16
16
toGRT ,
17
+ provider ,
17
18
Account ,
18
19
} from '../lib/testHelpers'
19
20
20
- const { AddressZero } = constants
21
+ const { AddressZero, MaxUint256 } = constants
21
22
22
23
function weightedAverage (
23
24
valueA : BigNumber ,
@@ -269,14 +270,18 @@ describe('Staking:Stakes', () => {
269
270
expect ( afterIndexerBalance ) . eq ( beforeIndexerBalance . add ( tokensToUnstake ) )
270
271
} )
271
272
272
- it ( 'reject unstake zero tokens' , async function ( ) {
273
- const tx = staking . connect ( indexer . signer ) . unstake ( toGRT ( '0' ) )
274
- await expect ( tx ) . revertedWith ( '!tokens' )
273
+ it ( 'should unstake available tokens even if passed a higher amount' , async function ( ) {
274
+ // Try to unstake a bit more than currently staked
275
+ const tokensOverCapacity = tokensToStake . add ( toGRT ( '1' ) )
276
+ await staking . connect ( indexer . signer ) . unstake ( tokensOverCapacity )
277
+
278
+ // Check state
279
+ const tokensLocked = ( await staking . stakes ( indexer . address ) ) . tokensLocked
280
+ expect ( tokensLocked ) . eq ( tokensToStake )
275
281
} )
276
282
277
- it ( 'reject unstake more than available tokens' , async function ( ) {
278
- const tokensOverCapacity = tokensToStake . add ( toGRT ( '1' ) )
279
- const tx = staking . connect ( indexer . signer ) . unstake ( tokensOverCapacity )
283
+ it ( 'reject unstake zero tokens' , async function ( ) {
284
+ const tx = staking . connect ( indexer . signer ) . unstake ( toGRT ( '0' ) )
280
285
await expect ( tx ) . revertedWith ( '!stake-avail' )
281
286
} )
282
287
@@ -305,6 +310,28 @@ describe('Staking:Stakes', () => {
305
310
await staking . connect ( indexer . signer ) . unstake ( tokensToStake )
306
311
expect ( await staking . getIndexerCapacity ( indexer . address ) ) . eq ( 0 )
307
312
} )
313
+
314
+ it ( 'should allow unstake of full amount with no upper limits' , async function ( ) {
315
+ // Use manual mining
316
+ await provider ( ) . send ( 'evm_setAutomine' , [ false ] )
317
+
318
+ // Setup
319
+ const newTokens = toGRT ( '2' )
320
+ const stakedTokens = await staking . getIndexerStakedTokens ( indexer . address )
321
+ const tokensToUnstake = stakedTokens . add ( newTokens )
322
+
323
+ // StakeTo & Unstake
324
+ await staking . connect ( indexer . signer ) . stakeTo ( indexer . address , newTokens )
325
+ await staking . connect ( indexer . signer ) . unstake ( MaxUint256 )
326
+ await provider ( ) . send ( 'evm_mine' , [ ] )
327
+
328
+ // Check state
329
+ const tokensLocked = ( await staking . stakes ( indexer . address ) ) . tokensLocked
330
+ expect ( tokensLocked ) . eq ( tokensToUnstake )
331
+
332
+ // Restore automine
333
+ await provider ( ) . send ( 'evm_setAutomine' , [ true ] )
334
+ } )
308
335
} )
309
336
310
337
describe ( 'withdraw' , function ( ) {
0 commit comments