Skip to content

Commit ac35887

Browse files
committed
test: Add a test for two simultaneous allocations with a GRT burn in the middle
1 parent ee73107 commit ac35887

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

test/lib/fixtures.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export class NetworkFixture {
9696

9797
async setUp(): Promise<void> {
9898
this.lastSnapshotId = await evmSnapshot()
99+
provider().send('evm_setAutomine', [true])
99100
}
100101

101102
async tearDown(): Promise<void> {

test/rewards/rewards.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
formatGRT,
2424
Account,
2525
advanceToNextEpoch,
26+
provider,
2627
} from '../lib/testHelpers'
2728

2829
const MAX_PPM = 1000000
@@ -816,6 +817,55 @@ describe('Rewards', () => {
816817
})
817818

818819
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+
})
819869
it('two simultanous-similar allocations should get same amount of rewards', async function () {
820870
await advanceToNextEpoch(epochManager)
821871

0 commit comments

Comments
 (0)