@@ -20,6 +20,7 @@ import {
20
20
21
21
const { AddressZero, HashZero } = constants
22
22
const MAX_PPM = toBN ( '1000000' )
23
+ const tokensToCollect = toGRT ( '50000000000000000000' )
23
24
24
25
describe ( 'Staking::Delegation' , ( ) => {
25
26
let me : Account
@@ -190,10 +191,12 @@ describe('Staking::Delegation', () => {
190
191
}
191
192
192
193
// Distribute test funds
193
- for ( const wallet of [ me , indexer , indexer2 , assetHolder ] ) {
194
+ for ( const wallet of [ me , indexer , indexer2 ] ) {
194
195
await grt . connect ( governor . signer ) . mint ( wallet . address , toGRT ( '1000000' ) )
195
196
await grt . connect ( wallet . signer ) . approve ( staking . address , toGRT ( '1000000' ) )
196
197
}
198
+ await grt . connect ( governor . signer ) . mint ( assetHolder . address , tokensToCollect )
199
+ await grt . connect ( assetHolder . signer ) . approve ( staking . address , tokensToCollect )
197
200
} )
198
201
199
202
beforeEach ( async function ( ) {
@@ -369,7 +372,7 @@ describe('Staking::Delegation', () => {
369
372
it ( 'reject delegate with zero tokens' , async function ( ) {
370
373
const tokensToDelegate = toGRT ( '0' )
371
374
const tx = staking . connect ( delegator . signer ) . delegate ( indexer . address , tokensToDelegate )
372
- await expect ( tx ) . revertedWith ( '!tokens ' )
375
+ await expect ( tx ) . revertedWith ( '!minimum-delegation ' )
373
376
} )
374
377
375
378
it ( 'reject delegate with less than 1 GRT when the pool is not initialized' , async function ( ) {
@@ -378,9 +381,11 @@ describe('Staking::Delegation', () => {
378
381
await expect ( tx ) . revertedWith ( '!minimum-delegation' )
379
382
} )
380
383
381
- it ( 'allows delegating under 1 GRT when the pool is initialized' , async function ( ) {
384
+ it ( 'reject delegating under 1 GRT when the pool is initialized' , async function ( ) {
382
385
await shouldDelegate ( delegator , toGRT ( '1' ) )
383
- await shouldDelegate ( delegator , toGRT ( '0.01' ) )
386
+ const tokensToDelegate = toGRT ( '0.5' )
387
+ const tx = staking . connect ( delegator . signer ) . delegate ( indexer . address , tokensToDelegate )
388
+ await expect ( tx ) . revertedWith ( '!minimum-delegation' )
384
389
} )
385
390
386
391
it ( 'reject delegate to empty address' , async function ( ) {
@@ -479,6 +484,12 @@ describe('Staking::Delegation', () => {
479
484
await advanceToNextEpoch ( epochManager ) // epoch 2
480
485
await shouldUndelegate ( delegator , toGRT ( '10' ) )
481
486
} )
487
+
488
+ it ( 'reject undelegate if remaining tokens are less than the minimum' , async function ( ) {
489
+ await shouldDelegate ( delegator , toGRT ( '100' ) )
490
+ const tx = staking . connect ( delegator . signer ) . undelegate ( indexer . address , toGRT ( '99.5' ) )
491
+ await expect ( tx ) . revertedWith ( '!minimum-delegation' )
492
+ } )
482
493
} )
483
494
484
495
describe ( 'withdraw' , function ( ) {
@@ -534,7 +545,6 @@ describe('Staking::Delegation', () => {
534
545
// Test values
535
546
const tokensToStake = toGRT ( '200' )
536
547
const tokensToAllocate = toGRT ( '2000' )
537
- const tokensToCollect = toGRT ( '500' )
538
548
const tokensToDelegate = toGRT ( '1800' )
539
549
const subgraphDeploymentID = randomHexBytes ( )
540
550
const channelKey = deriveChannelKey ( )
@@ -604,20 +614,24 @@ describe('Staking::Delegation', () => {
604
614
605
615
it ( 'revert if it cannot assign the smallest amount of shares' , async function ( ) {
606
616
// Init the delegation pool
607
- await shouldDelegate ( delegator , tokensToDelegate )
608
-
617
+ await shouldDelegate ( delegator , toGRT ( '1' ) )
618
+ const tokensToAllocate = toGRT ( '1' )
609
619
// Collect funds thru full allocation cycle
620
+ // Set rebate alpha to 0 to ensure all fees are collected
621
+ await staking . connect ( governor . signer ) . setRebateParameters ( 0 , 1 , 1 , 1 )
610
622
await staking . connect ( governor . signer ) . setDelegationRatio ( 10 )
611
623
await staking . connect ( indexer . signer ) . setDelegationParameters ( 0 , 0 , 0 )
612
624
await setupAllocation ( tokensToAllocate )
613
625
await advanceToNextEpoch ( epochManager )
614
626
await staking . connect ( assetHolder . signer ) . collect ( tokensToCollect , allocationID )
615
627
await advanceToNextEpoch ( epochManager )
616
628
await staking . connect ( indexer . signer ) . closeAllocation ( allocationID , poi )
629
+ // We've callected 5e18 GRT (a ridiculous amount),
630
+ // which means the price of a share is now 5 GRT
617
631
618
- // Delegate with such small amount of tokens (1 wei ) that we do not have enough precision
619
- // to even assign 1 wei of shares
620
- const tx = staking . connect ( delegator . signer ) . delegate ( indexer . address , toBN ( 1 ) )
632
+ // Delegate with such small amount of tokens (1 GRT ) that we do not have enough precision
633
+ // to even assign 1 share
634
+ const tx = staking . connect ( delegator . signer ) . delegate ( indexer . address , toGRT ( '1' ) )
621
635
await expect ( tx ) . revertedWith ( '!shares' )
622
636
} )
623
637
} )
0 commit comments