Skip to content

Commit 8054fe7

Browse files
committed
Move utils from disputes.ts into network.ts
1 parent df0b34f commit 8054fe7

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

cli/commands/contracts/disputeManager.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import consola from 'consola'
22
import yargs, { Argv } from 'yargs'
3-
import { constants, utils, Wallet, providers, BigNumber } from 'ethers'
3+
import { constants, utils, Wallet } from 'ethers'
44
import { createAttestation, Attestation, Receipt } from '@graphprotocol/common-ts'
55

6-
import { sendTransaction } from '../../network'
6+
import { sendTransaction, getChainID, getProvider, toGRT, randomHexBytes } from '../../network'
77
import { loadEnv, CLIArgs, CLIEnvironment } from '../../env'
88

99
const { HashZero } = constants
10-
const { defaultAbiCoder: abi, arrayify, concat, hexlify, randomBytes, parseUnits } = utils
10+
const { defaultAbiCoder: abi, arrayify, concat, hexlify } = utils
1111

1212
interface ChannelKey {
1313
privKey: string
@@ -16,16 +16,6 @@ interface ChannelKey {
1616
}
1717

1818
const logger = consola.create({})
19-
export const randomHexBytes = (n = 32): string => hexlify(randomBytes(n))
20-
export const toGRT = (value: string | number): BigNumber => {
21-
return parseUnits(typeof value === 'number' ? value.toString() : value, '18')
22-
}
23-
export const getProvider = (providerUrl: string, network?: number): providers.JsonRpcProvider =>
24-
new providers.JsonRpcProvider(providerUrl, network)
25-
26-
export const getChainID = (): number => {
27-
return 4 // Only works for rinkeby right now
28-
}
2919

3020
async function buildAttestation(receipt: Receipt, signer: string, disputeManagerAddress: string) {
3121
const attestation = await createAttestation(signer, getChainID(), disputeManagerAddress, receipt)
@@ -77,12 +67,12 @@ async function setupIndexer(
7767
logger.log('Staking...')
7868
await sendTransaction(cli.wallet, staking, 'stake', [indexerTokens])
7969
logger.log('Allocating...')
80-
await sendTransaction(
81-
cli.wallet,
82-
staking,
83-
'allocate',
84-
[receipt.subgraphDeploymentID, indexerAllocatedTokens, indexerChannelKey.address, metadata],
85-
)
70+
await sendTransaction(cli.wallet, staking, 'allocate', [
71+
receipt.subgraphDeploymentID,
72+
indexerAllocatedTokens,
73+
indexerChannelKey.address,
74+
metadata,
75+
])
8676
}
8777

8878
// This just creates any query dispute conflict to test the subgraph, no real data is sent
@@ -122,12 +112,10 @@ export const createTestQueryDisputeConflict = async (
122112
)
123113

124114
logger.log(`Creating conflicting attestations...`)
125-
await sendTransaction(
126-
cli.wallet,
127-
disputeManager,
128-
'createQueryDisputeConflict',
129-
[encodeAttestation(attestation1), encodeAttestation(attestation2)],
130-
)
115+
await sendTransaction(cli.wallet, disputeManager, 'createQueryDisputeConflict', [
116+
encodeAttestation(attestation1),
117+
encodeAttestation(attestation2),
118+
])
131119
}
132120

133121
// This just creates any indexing dispute to test the subgraph, no real data is sent
@@ -156,12 +144,10 @@ export const createTestIndexingDispute = async (
156144
await sendTransaction(cli.wallet, grt, 'approve', [disputeManager.address, deposit])
157145

158146
logger.log(`Creating indexing dispute...`)
159-
await sendTransaction(
160-
cli.wallet,
161-
disputeManager,
162-
'createIndexingDispute',
163-
[indexerChannelKey.address, deposit],
164-
)
147+
await sendTransaction(cli.wallet, disputeManager, 'createIndexingDispute', [
148+
indexerChannelKey.address,
149+
deposit,
150+
])
165151
}
166152

167153
export const accept = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {

cli/network.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,29 @@ import {
88
ContractTransaction,
99
Signer,
1010
Overrides,
11+
BigNumber,
1112
} from 'ethers'
1213
import consola from 'consola'
1314

1415
import { AddressBook } from './address-book'
1516
import { loadArtifact } from './artifacts'
1617
import { defaultOverrides } from './defaults'
1718

18-
const { keccak256 } = utils
19+
const { keccak256, randomBytes, parseUnits, hexlify } = utils
1920

2021
export const logger = consola.create({})
2122

23+
export const randomHexBytes = (n = 32): string => hexlify(randomBytes(n))
24+
export const toGRT = (value: string | number): BigNumber => {
25+
return parseUnits(typeof value === 'number' ? value.toString() : value, '18')
26+
}
27+
export const getProvider = (providerUrl: string, network?: number): providers.JsonRpcProvider =>
28+
new providers.JsonRpcProvider(providerUrl, network)
29+
30+
export const getChainID = (): number => {
31+
return 4 // Only works for rinkeby right now
32+
}
33+
2234
const hash = (input: string): string => keccak256(`0x${input.replace(/^0x/, '')}`)
2335

2436
type DeployResult = {

0 commit comments

Comments
 (0)