@@ -23,6 +23,7 @@ import {
23
23
formatGRT ,
24
24
Account ,
25
25
advanceToNextEpoch ,
26
+ provider ,
26
27
} from '../lib/testHelpers'
27
28
28
29
const MAX_PPM = 1000000
@@ -816,6 +817,55 @@ describe('Rewards', () => {
816
817
} )
817
818
818
819
describe ( 'multiple allocations' , function ( ) {
820
+ it ( 'two allocations in the same block with a GRT burn in the middle should succeed' , async function ( ) {
821
+ // If rewards are not monotonically increasing, this can trigger
822
+ // a subtraction overflow error as seen in mainnet tx:
823
+ // 0xb6bf7bbc446720a7409c482d714aebac239dd62e671c3c94f7e93dd3a61835ab
824
+ await advanceToNextEpoch ( epochManager )
825
+
826
+ // Setup
827
+ await epochManager . setEpochLength ( 10 )
828
+
829
+ // Update total signalled
830
+ const signalled1 = toGRT ( '1500' )
831
+ await curation . connect ( curator1 . signer ) . mint ( subgraphDeploymentID1 , signalled1 , 0 )
832
+
833
+ // Stake
834
+ const tokensToStake = toGRT ( '12500' )
835
+ await staking . connect ( indexer1 . signer ) . stake ( tokensToStake )
836
+
837
+ // Allocate simultaneously, burning in the middle
838
+ const tokensToAlloc = toGRT ( '5000' )
839
+ await provider ( ) . send ( 'evm_setAutomine' , [ false ] )
840
+ const tx1 = await staking
841
+ . connect ( indexer1 . signer )
842
+ . allocateFrom (
843
+ indexer1 . address ,
844
+ subgraphDeploymentID1 ,
845
+ tokensToAlloc ,
846
+ allocationID1 ,
847
+ metadata ,
848
+ await channelKey1 . generateProof ( indexer1 . address ) ,
849
+ )
850
+ const tx2 = await grt . connect ( indexer1 . signer ) . burn ( toGRT ( 1 ) )
851
+ const tx3 = await staking
852
+ . connect ( indexer1 . signer )
853
+ . allocateFrom (
854
+ indexer1 . address ,
855
+ subgraphDeploymentID1 ,
856
+ tokensToAlloc ,
857
+ allocationID2 ,
858
+ metadata ,
859
+ await channelKey2 . generateProof ( indexer1 . address ) ,
860
+ )
861
+
862
+ await provider ( ) . send ( 'evm_mine' , [ ] )
863
+ await provider ( ) . send ( 'evm_setAutomine' , [ true ] )
864
+
865
+ await expect ( tx1 ) . emit ( staking , 'AllocationCreated' )
866
+ await expect ( tx2 ) . emit ( grt , 'Transfer' )
867
+ await expect ( tx3 ) . emit ( staking , 'AllocationCreated' )
868
+ } )
819
869
it ( 'two simultanous-similar allocations should get same amount of rewards' , async function ( ) {
820
870
await advanceToNextEpoch ( epochManager )
821
871
0 commit comments