@@ -14,10 +14,11 @@ import {
1414 latestBlock ,
1515 toBN ,
1616 toGRT ,
17+ provider ,
1718 Account ,
1819} from '../lib/testHelpers'
1920
20- const { AddressZero } = constants
21+ const { AddressZero, MaxUint256 } = constants
2122
2223function weightedAverage (
2324 valueA : BigNumber ,
@@ -269,14 +270,18 @@ describe('Staking:Stakes', () => {
269270 expect ( afterIndexerBalance ) . eq ( beforeIndexerBalance . add ( tokensToUnstake ) )
270271 } )
271272
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 )
275281 } )
276282
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' ) )
280285 await expect ( tx ) . revertedWith ( '!stake-avail' )
281286 } )
282287
@@ -305,6 +310,28 @@ describe('Staking:Stakes', () => {
305310 await staking . connect ( indexer . signer ) . unstake ( tokensToStake )
306311 expect ( await staking . getIndexerCapacity ( indexer . address ) ) . eq ( 0 )
307312 } )
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+ } )
308335 } )
309336
310337 describe ( 'withdraw' , function ( ) {
0 commit comments