-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ops script for query dispute testing and sdk modifications …
…to support it (#934) Signed-off-by: Tomás Migone <[email protected]>
- Loading branch information
Showing
6 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
packages/contracts/scripts/ops/testDisputeConflict/acceptDispute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Wallet } from 'ethers' | ||
import hre from 'hardhat' | ||
|
||
async function main() { | ||
const graph = hre.graph() | ||
const arbitratorPrivateKey = process.env.ARBITRATOR_PRIVATE_KEY | ||
const arbitrator = new Wallet(arbitratorPrivateKey, graph.provider) | ||
console.log('Arbitrator:', arbitrator.address) | ||
|
||
const disputeId = '0x35e6e68aa71ee59cb710d8005563d63d644f11f2eee879eca9bc22f523c9fade' | ||
console.log('Dispute ID:', disputeId) | ||
|
||
// Accept dispute | ||
await graph.contracts.DisputeManager.connect(arbitrator).acceptDispute(disputeId) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
51 changes: 51 additions & 0 deletions
51
packages/contracts/scripts/ops/testDisputeConflict/createDispute.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { | ||
GraphChainId, | ||
buildAttestation, | ||
encodeAttestation, | ||
randomHexBytes, | ||
} from '@graphprotocol/sdk' | ||
import hre from 'hardhat' | ||
|
||
async function main() { | ||
const graph = hre.graph() | ||
const deployer = await graph.getDeployer() | ||
const [indexer] = await graph.getTestAccounts() | ||
const indexerChannelPrivKey = '0x82226c70efbe0d9525a5f9dc85c29b11fed1f46798a416b7626e21fdd6518d08' | ||
|
||
console.log('Deployer:', deployer.address) | ||
console.log('Indexer:', indexer.address) | ||
|
||
const receipt = { | ||
requestCID: '0x8bec406793c8e1c5d4bd4e059833e95b7a9aeed6a118cbe335a79735836f9ff7', | ||
responseCID: '0xbdfc41643b5ff8d55f6cdb50f05575e1fdf177fa54d98cae1b9c76d8b360ff57', | ||
subgraphDeploymentID: '0xa3bfbfc6f53fd8a61b78e0b9a90c7fbe9ff290cba87b045bc476137fb2963cf9', | ||
} | ||
const receipt2 = { ...receipt, responseCID: randomHexBytes() } | ||
|
||
const attestation1 = await buildAttestation( | ||
receipt, | ||
indexerChannelPrivKey, | ||
graph.contracts.DisputeManager.address, | ||
graph.chainId as GraphChainId, | ||
) | ||
const attestation2 = await buildAttestation( | ||
receipt2, | ||
indexerChannelPrivKey, | ||
graph.contracts.DisputeManager.address, | ||
graph.chainId as GraphChainId, | ||
) | ||
|
||
console.log('Attestation 1:', attestation1) | ||
console.log('Attestation 2:', attestation2) | ||
|
||
// Create dispute | ||
await graph.contracts.DisputeManager.connect(deployer).createQueryDisputeConflict( | ||
encodeAttestation(attestation1), | ||
encodeAttestation(attestation2), | ||
) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
40 changes: 40 additions & 0 deletions
40
packages/contracts/scripts/ops/testDisputeConflict/setupIndexer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { allocateFrom, deriveChannelKey, randomHexBytes, stake, toGRT } from '@graphprotocol/sdk' | ||
import hre, { ethers } from 'hardhat' | ||
|
||
async function main() { | ||
const graph = hre.graph() | ||
const deployer = await graph.getDeployer() | ||
const [indexer] = await graph.getTestAccounts() | ||
|
||
console.log('Deployer:', deployer.address) | ||
console.log('Indexer:', indexer.address) | ||
|
||
const receipt = { | ||
requestCID: '0x8bec406793c8e1c5d4bd4e059833e95b7a9aeed6a118cbe335a79735836f9ff7', | ||
responseCID: '0xbdfc41643b5ff8d55f6cdb50f05575e1fdf177fa54d98cae1b9c76d8b360ff57', | ||
subgraphDeploymentID: '0xa3bfbfc6f53fd8a61b78e0b9a90c7fbe9ff290cba87b045bc476137fb2963cf9', | ||
} | ||
|
||
console.log('Receipt requestCID:', receipt.requestCID) | ||
console.log('Receipt response CID:', receipt.responseCID) | ||
console.log('Receipt subgraphDeploymentID:', receipt.subgraphDeploymentID) | ||
|
||
const indexerChannelKey = deriveChannelKey() | ||
console.log('Indexer channel key:', indexerChannelKey.address) | ||
console.log('Indexer channel key privKey:', indexerChannelKey.privKey) | ||
|
||
// Set up indexer | ||
await deployer.sendTransaction({ value: toGRT('0.05'), to: indexer.address }) | ||
await graph.contracts.GraphToken.connect(deployer).transfer(indexer.address, toGRT('100000')) | ||
await stake(graph.contracts, indexer, { amount: toGRT('100000') }) | ||
await allocateFrom(graph.contracts, indexer, { | ||
channelKey: indexerChannelKey, | ||
amount: toGRT('100000'), | ||
subgraphDeploymentID: receipt.subgraphDeploymentID, | ||
}) | ||
} | ||
|
||
main().catch((error) => { | ||
console.error(error) | ||
process.exitCode = 1 | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
createAttestation, | ||
encodeAttestation as encodeAttestationLib, | ||
Attestation, | ||
Receipt, | ||
} from '@graphprotocol/common-ts' | ||
import { GraphChainId } from '../../../chain' | ||
|
||
export async function buildAttestation( | ||
receipt: Receipt, | ||
signer: string, | ||
disputeManagerAddress: string, | ||
chainId: GraphChainId, | ||
) { | ||
return await createAttestation(signer, chainId, disputeManagerAddress, receipt, '0') | ||
} | ||
|
||
export function encodeAttestation(attestation: Attestation): string { | ||
return encodeAttestationLib(attestation) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters