@@ -537,6 +537,29 @@ describe('Rewards', () => {
537
537
)
538
538
}
539
539
540
+ async function setupIndexerAllocationSignalingAfter ( ) {
541
+ // Setup
542
+ await epochManager . setEpochLength ( 10 )
543
+
544
+ // Allocate
545
+ const tokensToAllocate = toGRT ( '12500' )
546
+ await staking . connect ( indexer1 . signer ) . stake ( tokensToAllocate )
547
+ await staking
548
+ . connect ( indexer1 . signer )
549
+ . allocateFrom (
550
+ indexer1 . address ,
551
+ subgraphDeploymentID1 ,
552
+ tokensToAllocate ,
553
+ allocationID1 ,
554
+ metadata ,
555
+ await channelKey1 . generateProof ( indexer1 . address ) ,
556
+ )
557
+
558
+ // Update total signalled
559
+ const signalled1 = toGRT ( '1500' )
560
+ await curation . connect ( curator1 . signer ) . mint ( subgraphDeploymentID1 , signalled1 , 0 )
561
+ }
562
+
540
563
async function setupIndexerAllocationWithDelegation (
541
564
tokensToDelegate : BigNumber ,
542
565
delegationParams : DelegationParameters ,
@@ -636,6 +659,59 @@ describe('Rewards', () => {
636
659
expect ( toRound ( afterTokenSupply ) ) . eq ( toRound ( expectedTokenSupply ) )
637
660
} )
638
661
662
+ it ( 'does not revert with an underflow if the minimum signal changes' , async function ( ) {
663
+ // Align with the epoch boundary
664
+ await advanceToNextEpoch ( epochManager )
665
+ // Setup
666
+ await setupIndexerAllocation ( )
667
+
668
+ await rewardsManager . connect ( governor . signer ) . setMinimumSubgraphSignal ( toGRT ( 14000 ) )
669
+
670
+ // Jump
671
+ await advanceToNextEpoch ( epochManager )
672
+
673
+ // Close allocation. At this point rewards should be collected for that indexer
674
+ const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
675
+ await expect ( tx )
676
+ . emit ( rewardsManager , 'RewardsAssigned' )
677
+ . withArgs ( indexer1 . address , allocationID1 , await epochManager . currentEpoch ( ) , toBN ( 0 ) )
678
+ } )
679
+
680
+ it ( 'does not revert with an underflow if the minimum signal changes, and signal came after allocation' , async function ( ) {
681
+ // Align with the epoch boundary
682
+ await advanceToNextEpoch ( epochManager )
683
+ // Setup
684
+ await setupIndexerAllocationSignalingAfter ( )
685
+
686
+ await rewardsManager . connect ( governor . signer ) . setMinimumSubgraphSignal ( toGRT ( 14000 ) )
687
+
688
+ // Jump
689
+ await advanceToNextEpoch ( epochManager )
690
+
691
+ // Close allocation. At this point rewards should be collected for that indexer
692
+ const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
693
+ await expect ( tx )
694
+ . emit ( rewardsManager , 'RewardsAssigned' )
695
+ . withArgs ( indexer1 . address , allocationID1 , await epochManager . currentEpoch ( ) , toBN ( 0 ) )
696
+ } )
697
+
698
+ it ( 'does not revert if signal was already under minimum' , async function ( ) {
699
+ await rewardsManager . connect ( governor . signer ) . setMinimumSubgraphSignal ( toGRT ( 2000 ) )
700
+ // Align with the epoch boundary
701
+ await advanceToNextEpoch ( epochManager )
702
+ // Setup
703
+ await setupIndexerAllocation ( )
704
+
705
+ // Jump
706
+ await advanceToNextEpoch ( epochManager )
707
+ // Close allocation. At this point rewards should be collected for that indexer
708
+ const tx = staking . connect ( indexer1 . signer ) . closeAllocation ( allocationID1 , randomHexBytes ( ) )
709
+
710
+ await expect ( tx )
711
+ . emit ( rewardsManager , 'RewardsAssigned' )
712
+ . withArgs ( indexer1 . address , allocationID1 , await epochManager . currentEpoch ( ) , toBN ( 0 ) )
713
+ } )
714
+
639
715
it ( 'should distribute rewards on closed allocation and send to destination' , async function ( ) {
640
716
const destinationAddress = randomHexBytes ( 20 )
641
717
await staking . connect ( indexer1 . signer ) . setRewardsDestination ( destinationAddress )
0 commit comments