Skip to content

Commit a2abc90

Browse files
committed
test(contract): hack outdated test suite to pass
Signed-off-by: Tomás Migone <tomas@edgeandnode.com>
1 parent eb59951 commit a2abc90

File tree

7 files changed

+39
-11
lines changed

7 files changed

+39
-11
lines changed

packages/contracts/contracts/rewards/RewardsManager.sol

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,9 @@ contract RewardsManager is RewardsManagerV5Storage, GraphUpgradeable, IRewardsMa
249249
);
250250

251251
uint256 subgraphAllocatedTokens = 0;
252-
address[1] memory rewardsIssuers = [address(subgraphService)];
253-
for (uint256 i = 0; i < rewardsIssuers.length; i++) {
254-
if (rewardsIssuers[i] != address(0)) {
255-
subgraphAllocatedTokens += IRewardsIssuer(rewardsIssuers[i]).getSubgraphAllocatedTokens(
256-
_subgraphDeploymentID
257-
);
258-
}
252+
address rewardsIssuer = address(subgraphService);
253+
if (rewardsIssuer != address(0)) {
254+
subgraphAllocatedTokens += IRewardsIssuer(rewardsIssuer).getSubgraphAllocatedTokens(_subgraphDeploymentID);
259255
}
260256

261257
if (subgraphAllocatedTokens == 0) {

packages/contracts/test/tests/unit/disputes/poi.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DisputeManager } from '@graphprotocol/contracts'
1+
import { DisputeManager, IRewardsManager } from '@graphprotocol/contracts'
22
import { EpochManager } from '@graphprotocol/contracts'
33
import { GraphToken } from '@graphprotocol/contracts'
44
import { IStaking } from '@graphprotocol/contracts'
@@ -30,6 +30,7 @@ describe('DisputeManager:POI', () => {
3030
let epochManager: EpochManager
3131
let grt: GraphToken
3232
let staking: IStaking
33+
let rewardsManager: IRewardsManager
3334

3435
// Derive some channel keys for each indexer used to sign attestations
3536
const indexerChannelKey = deriveChannelKey()
@@ -92,10 +93,15 @@ describe('DisputeManager:POI', () => {
9293
epochManager = contracts.EpochManager as EpochManager
9394
grt = contracts.GraphToken as GraphToken
9495
staking = contracts.Staking as IStaking
96+
rewardsManager = contracts.RewardsManager as IRewardsManager
9597

9698
// Give some funds to the fisherman
9799
await grt.connect(governor).mint(fisherman.address, fishermanTokens)
98100
await grt.connect(fisherman).approve(disputeManager.address, fishermanTokens)
101+
102+
// HACK: we set the staking contract as the subgraph service to make tests pass.
103+
// This is due to the test suite being outdated.
104+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
99105
})
100106

101107
beforeEach(async function () {

packages/contracts/test/tests/unit/disputes/query.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAttestation, Receipt } from '@graphprotocol/common-ts'
2-
import { DisputeManager } from '@graphprotocol/contracts'
2+
import { DisputeManager, IRewardsManager } from '@graphprotocol/contracts'
33
import { EpochManager } from '@graphprotocol/contracts'
44
import { GraphToken } from '@graphprotocol/contracts'
55
import { IStaking } from '@graphprotocol/contracts'
@@ -35,6 +35,7 @@ describe('DisputeManager:Query', () => {
3535
let epochManager: EpochManager
3636
let grt: GraphToken
3737
let staking: IStaking
38+
let rewardsManager: IRewardsManager
3839

3940
// Derive some channel keys for each indexer used to sign attestations
4041
const indexer1ChannelKey = deriveChannelKey()
@@ -121,6 +122,7 @@ describe('DisputeManager:Query', () => {
121122
epochManager = contracts.EpochManager as EpochManager
122123
grt = contracts.GraphToken as GraphToken
123124
staking = contracts.Staking as IStaking
125+
rewardsManager = contracts.RewardsManager as IRewardsManager
124126

125127
// Give some funds to the fisherman
126128
for (const dst of [fisherman, fisherman2]) {
@@ -139,6 +141,10 @@ describe('DisputeManager:Query', () => {
139141
indexerAddress: indexer.address,
140142
receipt,
141143
}
144+
145+
// HACK: we set the staking contract as the subgraph service to make tests pass.
146+
// This is due to the test suite being outdated.
147+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
142148
})
143149

144150
beforeEach(async function () {

packages/contracts/test/tests/unit/l2/l2Staking.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IL2Staking } from '@graphprotocol/contracts'
1+
import { IL2Staking, IRewardsManager } from '@graphprotocol/contracts'
22
import { L2GraphTokenGateway } from '@graphprotocol/contracts'
33
import { GraphToken } from '@graphprotocol/contracts'
44
import { EpochManager, L1GNS, L1GraphTokenGateway, L1Staking } from '@graphprotocol/contracts'
@@ -35,6 +35,7 @@ describe('L2Staking', () => {
3535
let l2GraphTokenGateway: L2GraphTokenGateway
3636
let staking: IL2Staking
3737
let grt: GraphToken
38+
let rewardsManager: IRewardsManager
3839

3940
const tokens10k = toGRT('10000')
4041
const tokens100k = toGRT('100000')
@@ -88,6 +89,7 @@ describe('L2Staking', () => {
8889
l1StakingMock = l1MockContracts.L1Staking as L1Staking
8990
l1GNSMock = l1MockContracts.L1GNS as L1GNS
9091
l1GRTGatewayMock = l1MockContracts.L1GraphTokenGateway as L1GraphTokenGateway
92+
rewardsManager = fixtureContracts.RewardsManager as IRewardsManager
9193

9294
// Deploy L2 arbitrum bridge
9395
await fixture.loadL2ArbitrumBridge(governor)
@@ -99,6 +101,10 @@ describe('L2Staking', () => {
99101
await grt.connect(me).approve(staking.address, tokens1m)
100102
await grt.connect(governor).mint(other.address, tokens1m)
101103
await grt.connect(other).approve(staking.address, tokens1m)
104+
105+
// HACK: we set the staking contract as the subgraph service to make tests pass.
106+
// This is due to the test suite being outdated.
107+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
102108
})
103109

104110
beforeEach(async function () {

packages/contracts/test/tests/unit/rewards/rewards.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ describe('Rewards', () => {
151151
await grt.connect(wallet).approve(staking.address, toGRT('1000000'))
152152
await grt.connect(wallet).approve(curation.address, toGRT('1000000'))
153153
}
154+
155+
// HACK: we set the staking contract as the subgraph service to make tests pass.
156+
// This is due to the test suite being outdated.
157+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
154158
})
155159

156160
beforeEach(async function () {

packages/contracts/test/tests/unit/staking/allocation.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,10 @@ describe('Staking:Allocation', () => {
379379
// Give some funds to the delegator and approve staking contract to use funds on delegator behalf
380380
await grt.connect(governor).mint(delegator.address, tokensToDelegate)
381381
await grt.connect(delegator).approve(staking.address, tokensToDelegate)
382+
383+
// HACK: we set the staking contract as the subgraph service to make tests pass.
384+
// This is due to the test suite being outdated.
385+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
382386
})
383387

384388
beforeEach(async function () {

packages/contracts/test/tests/unit/staking/delegation.test.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EpochManager } from '@graphprotocol/contracts'
1+
import { EpochManager, IRewardsManager } from '@graphprotocol/contracts'
22
import { GraphToken } from '@graphprotocol/contracts'
33
import { IStaking } from '@graphprotocol/contracts'
44
import { deriveChannelKey, GraphNetworkContracts, helpers, randomHexBytes, toBN, toGRT } from '@graphprotocol/sdk'
@@ -29,6 +29,7 @@ describe('Staking::Delegation', () => {
2929
let epochManager: EpochManager
3030
let grt: GraphToken
3131
let staking: IStaking
32+
let rewardsManager: IRewardsManager
3233

3334
// Test values
3435
const poi = randomHexBytes()
@@ -159,6 +160,7 @@ describe('Staking::Delegation', () => {
159160
epochManager = contracts.EpochManager as EpochManager
160161
grt = contracts.GraphToken as GraphToken
161162
staking = contracts.Staking as IStaking
163+
rewardsManager = contracts.RewardsManager as IRewardsManager
162164

163165
// Distribute test funds
164166
for (const wallet of [delegator, delegator2]) {
@@ -173,6 +175,10 @@ describe('Staking::Delegation', () => {
173175
}
174176
await grt.connect(governor).mint(assetHolder.address, tokensToCollect)
175177
await grt.connect(assetHolder).approve(staking.address, tokensToCollect)
178+
179+
// HACK: we set the staking contract as the subgraph service to make tests pass.
180+
// This is due to the test suite being outdated.
181+
await rewardsManager.connect(governor).setSubgraphService(staking.address)
176182
})
177183

178184
beforeEach(async function () {

0 commit comments

Comments
 (0)