Skip to content

Commit d3bdf31

Browse files
authored
feat: add ops script for query dispute testing and sdk modifications to support it (#934)
Signed-off-by: Tomás Migone <[email protected]>
1 parent a93ec65 commit d3bdf31

File tree

6 files changed

+138
-10
lines changed

6 files changed

+138
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Wallet } from 'ethers'
2+
import hre from 'hardhat'
3+
4+
async function main() {
5+
const graph = hre.graph()
6+
const arbitratorPrivateKey = process.env.ARBITRATOR_PRIVATE_KEY
7+
const arbitrator = new Wallet(arbitratorPrivateKey, graph.provider)
8+
console.log('Arbitrator:', arbitrator.address)
9+
10+
const disputeId = '0x35e6e68aa71ee59cb710d8005563d63d644f11f2eee879eca9bc22f523c9fade'
11+
console.log('Dispute ID:', disputeId)
12+
13+
// Accept dispute
14+
await graph.contracts.DisputeManager.connect(arbitrator).acceptDispute(disputeId)
15+
}
16+
17+
main().catch((error) => {
18+
console.error(error)
19+
process.exitCode = 1
20+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {
2+
GraphChainId,
3+
buildAttestation,
4+
encodeAttestation,
5+
randomHexBytes,
6+
} from '@graphprotocol/sdk'
7+
import hre from 'hardhat'
8+
9+
async function main() {
10+
const graph = hre.graph()
11+
const deployer = await graph.getDeployer()
12+
const [indexer] = await graph.getTestAccounts()
13+
const indexerChannelPrivKey = '0x82226c70efbe0d9525a5f9dc85c29b11fed1f46798a416b7626e21fdd6518d08'
14+
15+
console.log('Deployer:', deployer.address)
16+
console.log('Indexer:', indexer.address)
17+
18+
const receipt = {
19+
requestCID: '0x8bec406793c8e1c5d4bd4e059833e95b7a9aeed6a118cbe335a79735836f9ff7',
20+
responseCID: '0xbdfc41643b5ff8d55f6cdb50f05575e1fdf177fa54d98cae1b9c76d8b360ff57',
21+
subgraphDeploymentID: '0xa3bfbfc6f53fd8a61b78e0b9a90c7fbe9ff290cba87b045bc476137fb2963cf9',
22+
}
23+
const receipt2 = { ...receipt, responseCID: randomHexBytes() }
24+
25+
const attestation1 = await buildAttestation(
26+
receipt,
27+
indexerChannelPrivKey,
28+
graph.contracts.DisputeManager.address,
29+
graph.chainId as GraphChainId,
30+
)
31+
const attestation2 = await buildAttestation(
32+
receipt2,
33+
indexerChannelPrivKey,
34+
graph.contracts.DisputeManager.address,
35+
graph.chainId as GraphChainId,
36+
)
37+
38+
console.log('Attestation 1:', attestation1)
39+
console.log('Attestation 2:', attestation2)
40+
41+
// Create dispute
42+
await graph.contracts.DisputeManager.connect(deployer).createQueryDisputeConflict(
43+
encodeAttestation(attestation1),
44+
encodeAttestation(attestation2),
45+
)
46+
}
47+
48+
main().catch((error) => {
49+
console.error(error)
50+
process.exitCode = 1
51+
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { allocateFrom, deriveChannelKey, randomHexBytes, stake, toGRT } from '@graphprotocol/sdk'
2+
import hre, { ethers } from 'hardhat'
3+
4+
async function main() {
5+
const graph = hre.graph()
6+
const deployer = await graph.getDeployer()
7+
const [indexer] = await graph.getTestAccounts()
8+
9+
console.log('Deployer:', deployer.address)
10+
console.log('Indexer:', indexer.address)
11+
12+
const receipt = {
13+
requestCID: '0x8bec406793c8e1c5d4bd4e059833e95b7a9aeed6a118cbe335a79735836f9ff7',
14+
responseCID: '0xbdfc41643b5ff8d55f6cdb50f05575e1fdf177fa54d98cae1b9c76d8b360ff57',
15+
subgraphDeploymentID: '0xa3bfbfc6f53fd8a61b78e0b9a90c7fbe9ff290cba87b045bc476137fb2963cf9',
16+
}
17+
18+
console.log('Receipt requestCID:', receipt.requestCID)
19+
console.log('Receipt response CID:', receipt.responseCID)
20+
console.log('Receipt subgraphDeploymentID:', receipt.subgraphDeploymentID)
21+
22+
const indexerChannelKey = deriveChannelKey()
23+
console.log('Indexer channel key:', indexerChannelKey.address)
24+
console.log('Indexer channel key privKey:', indexerChannelKey.privKey)
25+
26+
// Set up indexer
27+
await deployer.sendTransaction({ value: toGRT('0.05'), to: indexer.address })
28+
await graph.contracts.GraphToken.connect(deployer).transfer(indexer.address, toGRT('100000'))
29+
await stake(graph.contracts, indexer, { amount: toGRT('100000') })
30+
await allocateFrom(graph.contracts, indexer, {
31+
channelKey: indexerChannelKey,
32+
amount: toGRT('100000'),
33+
subgraphDeploymentID: receipt.subgraphDeploymentID,
34+
})
35+
}
36+
37+
main().catch((error) => {
38+
console.error(error)
39+
process.exitCode = 1
40+
})

packages/sdk/src/deployments/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export {
3333
getDefaults,
3434
} from './network/deployment/config'
3535

36+
export * from './network/actions/disputes'
3637
export * from './network/actions/gns'
3738
export * from './network/actions/staking'
3839
export * from './network/actions/graph-token'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {
2+
createAttestation,
3+
encodeAttestation as encodeAttestationLib,
4+
Attestation,
5+
Receipt,
6+
} from '@graphprotocol/common-ts'
7+
import { GraphChainId } from '../../../chain'
8+
9+
export async function buildAttestation(
10+
receipt: Receipt,
11+
signer: string,
12+
disputeManagerAddress: string,
13+
chainId: GraphChainId,
14+
) {
15+
return await createAttestation(signer, chainId, disputeManagerAddress, receipt, '0')
16+
}
17+
18+
export function encodeAttestation(attestation: Attestation): string {
19+
return encodeAttestationLib(attestation)
20+
}

packages/sdk/src/deployments/network/actions/staking.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { randomHexBytes } from '../../../utils/bytes'
66

77
import type { GraphNetworkAction } from './types'
88
import type { GraphNetworkContracts } from '../deployment/contracts/load'
9+
import { ChannelKey } from '../../../utils'
910

1011
export const stake: GraphNetworkAction<{ amount: BigNumber }> = async (
1112
contracts: GraphNetworkContracts,
@@ -28,23 +29,18 @@ export const stake: GraphNetworkAction<{ amount: BigNumber }> = async (
2829
}
2930

3031
export const allocateFrom: GraphNetworkAction<{
31-
allocationSigner: SignerWithAddress
32+
channelKey: ChannelKey
3233
subgraphDeploymentID: string
3334
amount: BigNumber
3435
}> = async (
3536
contracts: GraphNetworkContracts,
3637
indexer: SignerWithAddress,
37-
args: { allocationSigner: SignerWithAddress; subgraphDeploymentID: string; amount: BigNumber },
38+
args: { channelKey: ChannelKey; subgraphDeploymentID: string; amount: BigNumber },
3839
): Promise<void> => {
39-
const { allocationSigner, subgraphDeploymentID, amount } = args
40+
const { channelKey, subgraphDeploymentID, amount } = args
4041

41-
const allocationId = allocationSigner.address
42-
const messageHash = ethers.utils.solidityKeccak256(
43-
['address', 'address'],
44-
[indexer.address, allocationId],
45-
)
46-
const messageHashBytes = ethers.utils.arrayify(messageHash)
47-
const proof = await allocationSigner.signMessage(messageHashBytes)
42+
const allocationId = channelKey.address
43+
const proof = await channelKey.generateProof(indexer.address)
4844
const metadata = ethers.constants.HashZero
4945

5046
console.log(`\nAllocating ${amount} tokens on ${allocationId}...`)

0 commit comments

Comments
 (0)