Skip to content

Commit 7d72215

Browse files
committed
fix: review comments
1 parent 191f8f3 commit 7d72215

File tree

19 files changed

+370
-324
lines changed

19 files changed

+370
-324
lines changed

packages/subgraph-service/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"build": "hardhat compile",
2222
"test": "forge test",
2323
"test:deployment": "SECURE_ACCOUNTS_DISABLE_PROVIDER=true hardhat test",
24-
"test:integration": "./scripts/test/integration"
24+
"test:integration": "./scripts/integration"
2525
},
2626
"devDependencies": {
2727
"@defi-wonderland/natspec-smells": "^1.1.6",

packages/subgraph-service/scripts/test/integration renamed to packages/subgraph-service/scripts/integration

+4-4
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,20 @@ npx hardhat test:seed --network localhost
9898
npx hardhat test:transfer-ownership --network localhost
9999

100100
# Run Horizon steps 1 deployment
101-
npx hardhat deploy:migrate --network localhost --horizon-config e2e-test --step 1 --account-index 0 --patch-config
101+
npx hardhat deploy:migrate --network localhost --horizon-config e2e-test --step 1 --patch-config
102102

103103
# Run Subgraph Service steps 1 deployment
104104
cd ../subgraph-service
105-
npx hardhat deploy:migrate --network localhost --step 1 --subgraph-service-config integration-test --patch-config --account-index 0 --hide-banner
105+
npx hardhat deploy:migrate --network localhost --step 1 --subgraph-service-config integration-test --patch-config --hide-banner
106106

107107
# Run Horizon deployment steps 2 and 3
108108
cd ../horizon
109109
npx hardhat deploy:migrate --network localhost --horizon-config e2e-test --step 2 --patch-config --account-index 1 --hide-banner
110-
npx hardhat deploy:migrate --network localhost --horizon-config e2e-test --step 3 --patch-config --account-index 0 --hide-banner
110+
npx hardhat deploy:migrate --network localhost --horizon-config e2e-test --step 3 --patch-config --hide-banner
111111

112112
# Run Subgraph Service deployment step 2
113113
cd ../subgraph-service
114-
npx hardhat deploy:migrate --network localhost --step 2 --subgraph-service-config integration-test --patch-config --account-index 0 --hide-banner
114+
npx hardhat deploy:migrate --network localhost --step 2 --subgraph-service-config integration-test --patch-config --hide-banner
115115

116116
# Run Horizon deployment steps 4
117117
cd ../horizon

packages/subgraph-service/tasks/test/seed.ts

+10-17
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
import { keccak256, toUtf8Bytes } from 'ethers'
21
import { task } from 'hardhat/config'
32

4-
import { DisputeManager, SubgraphService } from '../../typechain-types'
5-
import { IHorizonStaking } from '@graphprotocol/horizon'
3+
import { HorizonStakingExtension } from '@graphprotocol/horizon'
64

75
import { indexers } from './fixtures/indexers'
6+
import { encodeRegistrationData, encodeStartServiceData, generatePOI } from '@graphprotocol/toolshed'
87

98
task('test:seed', 'Seed the test environment, must be run after deployment')
109
.setAction(async (_, hre) => {
1110
// Get contracts
1211
const graph = hre.graph()
1312
const { generateAllocationProof } = graph.subgraphService.actions
14-
const horizonStaking = graph.horizon.contracts.HorizonStaking as unknown as IHorizonStaking
15-
const subgraphService = graph.subgraphService.contracts.SubgraphService as unknown as SubgraphService
16-
const disputeManager = graph.subgraphService.contracts.DisputeManager as unknown as DisputeManager
13+
const horizonStaking = graph.horizon.contracts.HorizonStaking
14+
const horizonStakingExtension = graph.horizon.contracts.HorizonStaking as HorizonStakingExtension
15+
const subgraphService = graph.subgraphService.contracts.SubgraphService
16+
const disputeManager = graph.subgraphService.contracts.DisputeManager
1717

1818
// Get configs
1919
const disputePeriod = await disputeManager.getDisputePeriod()
@@ -37,8 +37,8 @@ task('test:seed', 'Seed the test environment, must be run after deployment')
3737
console.log(`Closing allocation: ${allocation.allocationID}`)
3838

3939
// Close allocation
40-
const poi = hre.ethers.getBytes(keccak256(toUtf8Bytes('poi')))
41-
await horizonStaking.connect(indexerSigner).closeAllocation(
40+
const poi = generatePOI()
41+
await horizonStakingExtension.connect(indexerSigner).closeAllocation(
4242
allocation.allocationID,
4343
poi,
4444
)
@@ -58,12 +58,8 @@ task('test:seed', 'Seed the test environment, must be run after deployment')
5858

5959
console.log(`Provision created for indexer with ${indexer.provisionTokens} tokens`)
6060

61-
const indexerRegistrationData = hre.ethers.AbiCoder.defaultAbiCoder().encode(
62-
['string', 'string', 'address'],
63-
[indexer.url, indexer.geoHash, indexer.rewardsDestination || hre.ethers.ZeroAddress],
64-
)
65-
6661
console.log(`Registering indexer: ${indexer.address}`)
62+
const indexerRegistrationData = encodeRegistrationData(indexer.url, indexer.geoHash, indexer.rewardsDestination || hre.ethers.ZeroAddress)
6763
await subgraphService.connect(indexerSigner).register(indexerSigner.address, indexerRegistrationData)
6864

6965
const indexerData = await subgraphService.indexers(indexerSigner.address)
@@ -93,10 +89,7 @@ task('test:seed', 'Seed the test environment, must be run after deployment')
9389
const allocationId = allocation.allocationID
9490

9591
// Attempt to create an allocation with the same ID
96-
const data = hre.ethers.AbiCoder.defaultAbiCoder().encode(
97-
['bytes32', 'uint256', 'address', 'bytes'],
98-
[subgraphDeploymentId, allocationTokens, allocationId, signature],
99-
)
92+
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)
10093

10194
// Start allocation
10295
await subgraphService.connect(indexerSigner).startService(

packages/subgraph-service/test/integration/after-transition-period/dispute-manager/governance.test.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ import { expect } from 'chai'
33
import hre from 'hardhat'
44

55
import { DisputeManager } from '../../../../typechain-types'
6-
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
6+
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
77

88
describe('DisputeManager Governance', () => {
99
let disputeManager: DisputeManager
1010
let snapshotId: string
1111

1212
// Test addresses
13-
let governor: SignerWithAddress
14-
let nonOwner: SignerWithAddress
15-
let newArbitrator: SignerWithAddress
16-
let newSubgraphService: SignerWithAddress
13+
let governor: HardhatEthersSigner
14+
let nonOwner: HardhatEthersSigner
15+
let newArbitrator: HardhatEthersSigner
16+
let newSubgraphService: HardhatEthersSigner
1717

1818
before(async () => {
1919
const graph = hre.graph()
20-
disputeManager = graph.subgraphService.contracts.DisputeManager as unknown as DisputeManager
20+
disputeManager = graph.subgraphService.contracts.DisputeManager
2121

2222
// Get signers
2323
governor = await graph.accounts.getGovernor()

packages/subgraph-service/test/integration/after-transition-period/dispute-manager/indexing-disputes.test.ts

+15-13
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,25 @@ import { EventLog } from 'ethers'
33
import { expect } from 'chai'
44
import hre from 'hardhat'
55

6-
import { DisputeManager, IGraphToken, IHorizonStaking, SubgraphService } from '../../../../typechain-types'
7-
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
6+
import { DisputeManager, IGraphToken, SubgraphService } from '../../../../typechain-types'
7+
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
8+
import { HorizonStaking } from '@graphprotocol/horizon'
89

910
import { indexers } from '../../../../tasks/test/fixtures/indexers'
11+
import { generatePOI } from '@graphprotocol/toolshed'
1012

1113
describe('Indexing Disputes', () => {
1214
let disputeManager: DisputeManager
1315
let graphToken: IGraphToken
14-
let staking: IHorizonStaking
16+
let staking: HorizonStaking
1517
let subgraphService: SubgraphService
1618

1719
let snapshotId: string
1820

1921
// Test addresses
20-
let fisherman: SignerWithAddress
21-
let arbitrator: SignerWithAddress
22-
let indexer: SignerWithAddress
22+
let fisherman: HardhatEthersSigner
23+
let arbitrator: HardhatEthersSigner
24+
let indexer: HardhatEthersSigner
2325

2426
let allocationId: string
2527

@@ -31,10 +33,10 @@ describe('Indexing Disputes', () => {
3133
before(async () => {
3234
// Get contracts
3335
const graph = hre.graph()
34-
disputeManager = graph.subgraphService.contracts.DisputeManager as unknown as DisputeManager
35-
graphToken = graph.horizon.contracts.GraphToken as unknown as IGraphToken
36-
staking = graph.horizon.contracts.HorizonStaking as unknown as IHorizonStaking
37-
subgraphService = graph.subgraphService.contracts.SubgraphService as unknown as SubgraphService
36+
disputeManager = graph.subgraphService.contracts.DisputeManager
37+
graphToken = graph.horizon.contracts.GraphToken
38+
staking = graph.horizon.contracts.HorizonStaking
39+
subgraphService = graph.subgraphService.contracts.SubgraphService
3840

3941
// Get signers
4042
arbitrator = await graph.accounts.getArbitrator()
@@ -67,7 +69,7 @@ describe('Indexing Disputes', () => {
6769
describe('Fisherman', () => {
6870
it('should allow fisherman to create an indexing dispute', async () => {
6971
// Create dispute
70-
const poi = ethers.keccak256(ethers.toUtf8Bytes('test-poi'))
72+
const poi = generatePOI()
7173

7274
// Approve dispute manager for dispute deposit
7375
await graphToken.connect(fisherman).approve(disputeManager.target, disputeDeposit)
@@ -92,7 +94,7 @@ describe('Indexing Disputes', () => {
9294

9395
it('should allow fisherman to cancel an indexing dispute', async () => {
9496
// Create dispute
95-
const poi = ethers.keccak256(ethers.toUtf8Bytes('test-poi'))
97+
const poi = generatePOI()
9698

9799
// Approve dispute manager for dispute deposit
98100
await graphToken.connect(fisherman).approve(disputeManager.target, disputeDeposit)
@@ -135,7 +137,7 @@ describe('Indexing Disputes', () => {
135137
await graphToken.connect(fisherman).approve(disputeManager.target, disputeDeposit)
136138

137139
// Create dispute
138-
const poi = ethers.keccak256(ethers.toUtf8Bytes('test-poi'))
140+
const poi = generatePOI()
139141
const tx = await disputeManager.connect(fisherman).createIndexingDispute(allocationId, poi)
140142
const receipt = await tx.wait()
141143

packages/subgraph-service/test/integration/after-transition-period/dispute-manager/query-conflict-disputes.test.ts

+47-34
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,46 @@ import { ethers } from 'hardhat'
33
import { expect } from 'chai'
44
import hre from 'hardhat'
55

6-
import { DisputeManager, IGraphToken, IHorizonStaking, SubgraphService } from '../../../../typechain-types'
7-
import { createAttestationData } from '@graphprotocol/toolshed'
8-
import { SignerWithAddress } from '@nomicfoundation/hardhat-ethers/signers'
6+
import { DisputeManager, IGraphToken, SubgraphService } from '../../../../typechain-types'
7+
import { generateAttestationData } from '@graphprotocol/toolshed'
8+
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
9+
import { HorizonStaking } from '@graphprotocol/horizon'
910

1011
import { indexers } from '../../../../tasks/test/fixtures/indexers'
1112

1213
describe('Query Conflict Disputes', () => {
1314
let disputeManager: DisputeManager
1415
let graphToken: IGraphToken
15-
let staking: IHorizonStaking
16+
let staking: HorizonStaking
1617
let subgraphService: SubgraphService
1718

1819
let snapshotId: string
20+
let chainId: number
1921

2022
// Test addresses
21-
let fisherman: SignerWithAddress
22-
let arbitrator: SignerWithAddress
23-
let indexer: SignerWithAddress
24-
let relatedIndexer: SignerWithAddress
23+
let fisherman: HardhatEthersSigner
24+
let arbitrator: HardhatEthersSigner
25+
let indexer: HardhatEthersSigner
26+
let relatedIndexer: HardhatEthersSigner
2527

2628
// Allocation variables
27-
let allocationSigner: Wallet
28-
let relatedAllocationSigner: Wallet
29+
let allocationPrivateKey: string
30+
let relatedAllocationPrivateKey: string
2931
let subgraphDeploymentId: string
3032

3133
// Dispute manager variables
3234
let disputeDeposit: bigint
3335
let fishermanRewardCut: bigint
3436
let disputePeriod: bigint
37+
let disputeManagerAddress: string
3538

3639
before(async () => {
3740
// Get contracts
3841
const graph = hre.graph()
39-
disputeManager = graph.subgraphService.contracts.DisputeManager as unknown as DisputeManager
40-
graphToken = graph.horizon.contracts.GraphToken as unknown as IGraphToken
41-
staking = graph.horizon.contracts.HorizonStaking as unknown as IHorizonStaking
42-
subgraphService = graph.subgraphService.contracts.SubgraphService as unknown as SubgraphService
42+
disputeManager = graph.subgraphService.contracts.DisputeManager
43+
graphToken = graph.horizon.contracts.GraphToken
44+
staking = graph.horizon.contracts.HorizonStaking
45+
subgraphService = graph.subgraphService.contracts.SubgraphService
4346

4447
// Get signers
4548
arbitrator = await graph.accounts.getArbitrator()
@@ -53,15 +56,19 @@ describe('Query Conflict Disputes', () => {
5356

5457
// Get allocation
5558
const allocation = indexerFixture.allocations[0]
56-
allocationSigner = new Wallet(allocation.allocationPrivateKey)
59+
allocationPrivateKey = allocation.allocationPrivateKey
5760
const relatedAllocation = relatedIndexerFixture.allocations[0]
58-
relatedAllocationSigner = new Wallet(relatedAllocation.allocationPrivateKey)
61+
relatedAllocationPrivateKey = relatedAllocation.allocationPrivateKey
5962
subgraphDeploymentId = allocation.subgraphDeploymentID
6063

6164
// Dispute manager variables
6265
disputeDeposit = await disputeManager.disputeDeposit()
6366
fishermanRewardCut = await disputeManager.fishermanRewardCut()
6467
disputePeriod = await disputeManager.disputePeriod()
68+
disputeManagerAddress = await disputeManager.getAddress()
69+
70+
// Get chain ID
71+
chainId = Number((await ethers.provider.getNetwork()).chainId)
6572
})
6673

6774
beforeEach(async () => {
@@ -82,19 +89,21 @@ describe('Query Conflict Disputes', () => {
8289
const responseHash2 = ethers.keccak256(ethers.toUtf8Bytes('test-response-2'))
8390

8491
// Create attestation data for both responses
85-
const attestationData1 = await createAttestationData(
86-
disputeManager,
87-
allocationSigner,
92+
const attestationData1 = await generateAttestationData(
8893
queryHash,
8994
responseHash1,
9095
subgraphDeploymentId,
96+
allocationPrivateKey,
97+
disputeManagerAddress,
98+
chainId,
9199
)
92-
const attestationData2 = await createAttestationData(
93-
disputeManager,
94-
relatedAllocationSigner,
100+
const attestationData2 = await generateAttestationData(
95101
queryHash,
96102
responseHash2,
97103
subgraphDeploymentId,
104+
relatedAllocationPrivateKey,
105+
disputeManagerAddress,
106+
chainId,
98107
)
99108

100109
// Approve dispute manager for dispute deposit
@@ -133,19 +142,21 @@ describe('Query Conflict Disputes', () => {
133142
const responseHash2 = ethers.keccak256(ethers.toUtf8Bytes('test-response-2'))
134143

135144
// Create attestation data for both responses
136-
const attestationData1 = await createAttestationData(
137-
disputeManager,
138-
allocationSigner,
145+
const attestationData1 = await generateAttestationData(
139146
queryHash,
140147
responseHash1,
141148
subgraphDeploymentId,
149+
allocationPrivateKey,
150+
disputeManagerAddress,
151+
chainId,
142152
)
143-
const attestationData2 = await createAttestationData(
144-
disputeManager,
145-
relatedAllocationSigner,
153+
const attestationData2 = await generateAttestationData(
146154
queryHash,
147155
responseHash2,
148156
subgraphDeploymentId,
157+
relatedAllocationPrivateKey,
158+
disputeManagerAddress,
159+
chainId,
149160
)
150161

151162
// Approve dispute manager for dispute deposit
@@ -197,19 +208,21 @@ describe('Query Conflict Disputes', () => {
197208
const responseHash2 = ethers.keccak256(ethers.toUtf8Bytes('test-response-2'))
198209

199210
// Create attestation data for both responses
200-
const attestationData1 = await createAttestationData(
201-
disputeManager,
202-
allocationSigner,
211+
const attestationData1 = await generateAttestationData(
203212
queryHash,
204213
responseHash1,
205214
subgraphDeploymentId,
215+
allocationPrivateKey,
216+
disputeManagerAddress,
217+
chainId,
206218
)
207-
const attestationData2 = await createAttestationData(
208-
disputeManager,
209-
relatedAllocationSigner,
219+
const attestationData2 = await generateAttestationData(
210220
queryHash,
211221
responseHash2,
212222
subgraphDeploymentId,
223+
relatedAllocationPrivateKey,
224+
disputeManagerAddress,
225+
chainId,
213226
)
214227

215228
// Approve dispute manager for dispute deposit

0 commit comments

Comments
 (0)