Skip to content

Commit 3e8c024

Browse files
committed
fix: use new generate allocation helper
1 parent 0b6509a commit 3e8c024

File tree

6 files changed

+33
-43
lines changed

6 files changed

+33
-43
lines changed

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@ import { task } from 'hardhat/config'
33
import { HorizonStakingExtension } from '@graphprotocol/horizon'
44

55
import { indexers } from './fixtures/indexers'
6-
import { encodeRegistrationData, encodeStartServiceData, generatePOI } from '@graphprotocol/toolshed'
6+
import { encodeRegistrationData, encodeStartServiceData, generateAllocationProof, generatePOI } from '@graphprotocol/toolshed'
77

88
task('test:seed', 'Seed the test environment, must be run after deployment')
99
.setAction(async (_, hre) => {
1010
// Get contracts
1111
const graph = hre.graph()
12-
const { generateAllocationProof } = graph.subgraphService.actions
1312
const horizonStaking = graph.horizon.contracts.HorizonStaking
1413
const horizonStakingExtension = graph.horizon.contracts.HorizonStaking as HorizonStakingExtension
1514
const subgraphService = graph.subgraphService.contracts.SubgraphService
1615
const disputeManager = graph.subgraphService.contracts.DisputeManager
1716

17+
// Get contract addresses
18+
const subgraphServiceAddress = await subgraphService.getAddress()
19+
20+
// Get chain id
21+
const chainId = (await hre.ethers.provider.getNetwork()).chainId
22+
1823
// Get configs
1924
const disputePeriod = await disputeManager.getDisputePeriod()
2025
const maxSlashingCut = await disputeManager.maxSlashingCut()
@@ -83,7 +88,7 @@ task('test:seed', 'Seed the test environment, must be run after deployment')
8388
console.log(`Starting allocation: ${allocation.allocationID}`)
8489

8590
// Build allocation proof
86-
const signature = await generateAllocationProof(allocation.allocationPrivateKey, [indexer.address, allocation.allocationID])
91+
const signature = await generateAllocationProof(indexer.address, allocation.allocationPrivateKey, subgraphServiceAddress, Number(chainId))
8792
const subgraphDeploymentId = allocation.subgraphDeploymentID
8893
const allocationTokens = allocation.tokens
8994
const allocationId = allocation.allocationID

packages/subgraph-service/test/integration/after-transition-period/subgraph-service/indexer.test.ts

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

6-
import { encodeCollectData, encodeStartServiceData, generatePOI, getSignedRAVCalldata, getSignerProof, PaymentTypes } from '@graphprotocol/toolshed'
6+
import { encodeCollectData, encodeStartServiceData, generateAllocationProof, generatePOI, getSignedRAVCalldata, getSignerProof, PaymentTypes } from '@graphprotocol/toolshed'
77
import { GraphPayments, GraphTallyCollector, HorizonStaking } from '@graphprotocol/horizon'
88
import { IGraphToken, IPaymentsEscrow, SubgraphService } from '../../../../typechain-types'
99
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
@@ -29,7 +29,7 @@ describe('Indexer', () => {
2929
let subgraphServiceAddress: string
3030

3131
const graph = hre.graph()
32-
const { collect, generateAllocationProof } = graph.subgraphService.actions
32+
const { collect } = graph.subgraphService.actions
3333

3434
before(async () => {
3535
// Get contracts
@@ -110,7 +110,7 @@ describe('Indexer', () => {
110110
const beforeLockedTokens = await subgraphService.allocationProvisionTracker(indexer.address)
111111

112112
// Build allocation proof
113-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
113+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
114114

115115
// Attempt to create an allocation with the same ID
116116
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)
@@ -134,7 +134,7 @@ describe('Indexer', () => {
134134

135135
it('should be able to start an allocation with zero tokens', async () => {
136136
// Build allocation proof
137-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
137+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
138138

139139
// Attempt to create an allocation with the same ID
140140
const data = encodeStartServiceData(subgraphDeploymentId, 0n, allocationId, signature)
@@ -154,7 +154,7 @@ describe('Indexer', () => {
154154

155155
it('should not start an allocation without enough tokens', async () => {
156156
// Build allocation proof
157-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
157+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
158158

159159
// Build allocation data
160160
const allocationTokens = provisionTokens + ethers.parseEther('10000000')
@@ -384,7 +384,7 @@ describe('Indexer', () => {
384384
allocationPrivateKey = wallet.privateKey
385385
subgraphDeploymentId = indexers[0].allocations[0].subgraphDeploymentID
386386
const allocationTokens = availableTokens - lockedTokens
387-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
387+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
388388
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)
389389
await subgraphService.connect(indexer).startService(
390390
indexer.address,

packages/subgraph-service/test/integration/after-transition-period/subgraph-service/operator.test.ts

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

55
import { DisputeManager, IGraphToken, IPaymentsEscrow, SubgraphService } from '../../../../typechain-types'
6-
import { encodeCollectData, encodeRegistrationData, encodeStartServiceData, generatePOI, getSignedRAVCalldata, getSignerProof } from '@graphprotocol/toolshed'
6+
import { encodeCollectData, encodeRegistrationData, encodeStartServiceData, generateAllocationProof, generatePOI, getSignedRAVCalldata, getSignerProof } from '@graphprotocol/toolshed'
77
import { GraphTallyCollector, HorizonStaking } from '@graphprotocol/horizon'
88
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
99

@@ -33,7 +33,7 @@ describe('Operator', () => {
3333
let subgraphServiceAddress: string
3434
const graph = hre.graph()
3535
const { provision } = graph.horizon.actions
36-
const { collect, generateAllocationProof } = graph.subgraphService.actions
36+
const { collect } = graph.subgraphService.actions
3737

3838
before(async () => {
3939
// Get contracts
@@ -143,7 +143,7 @@ describe('Operator', () => {
143143

144144
it('should be able to create an allocation', async () => {
145145
// Build allocation proof
146-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
146+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
147147

148148
// Build allocation data
149149
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)
@@ -164,7 +164,7 @@ describe('Operator', () => {
164164
describe('Unauthorized Operator', () => {
165165
it('should not be able to create an allocation', async () => {
166166
// Build allocation proof
167-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
167+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
168168

169169
// Build allocation data
170170
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)

packages/subgraph-service/test/integration/after-transition-period/subgraph-service/paused.test.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { DisputeManager, IGraphToken, SubgraphService } from '../../../../typech
66
import { setGRTBalance } from '@graphprotocol/toolshed/hardhat'
77
import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
88

9-
import { encodeCollectData, encodeRegistrationData, encodeStartServiceData, generatePOI, PaymentTypes } from '@graphprotocol/toolshed'
9+
import { encodeCollectData, encodeRegistrationData, encodeStartServiceData, generateAllocationProof, generatePOI, PaymentTypes } from '@graphprotocol/toolshed'
1010
import { indexers } from '../../../../tasks/test/fixtures/indexers'
1111

1212
describe('Paused Protocol', () => {
@@ -15,17 +15,19 @@ describe('Paused Protocol', () => {
1515
let subgraphService: SubgraphService
1616

1717
let snapshotId: string
18+
let chainId: number
1819

1920
// Test addresses
2021
let pauseGuardian: HardhatEthersSigner
2122
let indexer: HardhatEthersSigner
2223
let allocationId: string
2324
let subgraphDeploymentId: string
2425
let allocationTokens: bigint
26+
let subgraphServiceAddress: string
2527

2628
const graph = hre.graph()
2729
const { provision } = graph.horizon.actions
28-
const { collect, generateAllocationProof } = graph.subgraphService.actions
30+
const { collect } = graph.subgraphService.actions
2931

3032
before(async () => {
3133
// Get contracts
@@ -35,6 +37,12 @@ describe('Paused Protocol', () => {
3537

3638
// Get signers
3739
pauseGuardian = await graph.accounts.getPauseGuardian()
40+
41+
// Get chain id
42+
chainId = Number((await hre.ethers.provider.getNetwork()).chainId)
43+
44+
// Get subgraph service address
45+
subgraphServiceAddress = await subgraphService.getAddress()
3846
})
3947

4048
beforeEach(async () => {
@@ -155,7 +163,7 @@ describe('Paused Protocol', () => {
155163

156164
it('should not allow indexer to start an allocation while paused', async () => {
157165
// Build allocation proof
158-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
166+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
159167

160168
// Build allocation data
161169
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)

packages/subgraph-service/test/integration/after-transition-period/subgraph-service/permisionless.test.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { HardhatEthersSigner } from '@nomicfoundation/hardhat-ethers/signers'
66
import { SubgraphService } from '../../../../typechain-types'
77

88
import { indexers } from '../../../../tasks/test/fixtures/indexers'
9-
import { encodeStartServiceData } from '@graphprotocol/toolshed'
9+
import { encodeStartServiceData, generateAllocationProof } from '@graphprotocol/toolshed'
1010

1111
describe('Permissionless', () => {
1212
let subgraphService: SubgraphService
@@ -20,7 +20,6 @@ describe('Permissionless', () => {
2020
let allocationTokens: bigint
2121

2222
const graph = hre.graph()
23-
const { generateAllocationProof } = graph.subgraphService.actions
2423

2524
before(async () => {
2625
// Get contracts
@@ -91,7 +90,9 @@ describe('Permissionless', () => {
9190
allocationTokens = 0n
9291

9392
// Start allocation
94-
const signature = await generateAllocationProof(allocationPrivateKey, [indexer.address, allocationId])
93+
const subgraphServiceAddress = await subgraphService.getAddress()
94+
const chainId = Number((await hre.ethers.provider.getNetwork()).chainId)
95+
const signature = await generateAllocationProof(indexer.address, allocationPrivateKey, subgraphServiceAddress, chainId)
9596
const data = encodeStartServiceData(subgraphDeploymentId, allocationTokens, allocationId, signature)
9697
await subgraphService.connect(indexer).startService(indexer.address, data)
9798
})

packages/toolshed/src/deployments/subgraph-service/actions.ts

-24
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,6 @@ export function loadActions(contracts: { SubgraphService: ISubgraphService }) {
1414
* @returns The payment collected
1515
*/
1616
collect: (signer: HardhatEthersSigner, args: Parameters<ISubgraphService['collect']>): Promise<bigint> => collect(contracts, signer, args),
17-
18-
/**
19-
* Generates an allocation proof for the subgraph services
20-
* @param signer - The signer that will sign the allocation proof
21-
* @param args Parameters:
22-
* - `[indexer, allocationId]` - The encodeAllocationProof parameters
23-
* @returns The allocation proof
24-
*/
25-
generateAllocationProof: (allocationPrivateKey: string, args: Parameters<ISubgraphService['encodeAllocationProof']>): Promise<string> => generateAllocationProof(contracts, allocationPrivateKey, args),
2617
}
2718
}
2819

@@ -45,18 +36,3 @@ async function collect(
4536

4637
return BigInt(event.data)
4738
}
48-
49-
// Generate allocation proof for the subgraph services
50-
async function generateAllocationProof(
51-
contracts: { SubgraphService: ISubgraphService },
52-
allocationPrivateKey: string,
53-
args: Parameters<ISubgraphService['encodeAllocationProof']>,
54-
): Promise<string> {
55-
const { SubgraphService } = contracts
56-
const [indexer, allocationId] = args
57-
58-
const wallet = new ethers.Wallet(allocationPrivateKey)
59-
const messageHash = await SubgraphService.encodeAllocationProof(indexer, allocationId)
60-
const signature = wallet.signingKey.sign(messageHash)
61-
return ethers.Signature.from(signature).serialized
62-
}

0 commit comments

Comments
 (0)