Skip to content

Commit 8c97d85

Browse files
committed
explicitly select address book
1 parent 711b1ba commit 8c97d85

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Signer } from 'ethers'
22
import { connectContracts } from '.'
3+
import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json'
34

45
jest.mock('ethers')
56

@@ -8,7 +9,7 @@ const mockSigner = jest.fn() as unknown as Signer
89
describe('Contracts', () => {
910
// Test for each supported protocol network
1011
test.each([1, 5, 42161, 421613])('Connect contracts [chainId: %p]', chainId => {
11-
const contracts = connectContracts(mockSigner, chainId)
12+
const contracts = connectContracts(mockSigner, chainId, DEPLOYED_CONTRACTS)
1213
expect(contracts).toBeDefined()
1314
})
1415
})

packages/common-ts/src/contracts/index.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import { providers, Signer } from 'ethers'
22
import graphChain from './chain'
33

4-
// Contract addresses
5-
import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json'
6-
74
// Contract ABIs
85
import { Curation } from '@graphprotocol/contracts/dist/types/Curation'
96
import { DisputeManager } from '@graphprotocol/contracts/dist/types/DisputeManager'
@@ -45,7 +42,6 @@ import { L1GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/type
4542
import { BridgeEscrow__factory } from '@graphprotocol/contracts/dist/types/factories/BridgeEscrow__factory'
4643
import { L2GraphToken__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphToken__factory'
4744
import { L2GraphTokenGateway__factory } from '@graphprotocol/contracts/dist/types/factories/L2GraphTokenGateway__factory'
48-
import { readFileSync } from 'fs'
4945

5046
export const GraphChain = graphChain
5147

@@ -72,16 +68,14 @@ export interface NetworkContracts {
7268
l2GraphTokenGateway?: L2GraphTokenGateway
7369
}
7470

71+
export type AddressBook = { [key: string]: { [key: string]: { address: string } } }
72+
7573
export const connectContracts = async (
7674
providerOrSigner: providers.Provider | Signer,
7775
chainId: number,
78-
addressBook?: string,
76+
addressBook: AddressBook,
7977
): Promise<NetworkContracts> => {
80-
const deployedContracts = addressBook
81-
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
82-
JSON.parse(readFileSync(addressBook).toString())[`${chainId}`]
83-
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
84-
(DEPLOYED_CONTRACTS as any)[`${chainId}`]
78+
const deployedContracts = addressBook[`${chainId}`]
8579
if (!deployedContracts) {
8680
throw new Error(`chainId: '${chainId}' has no deployed contracts`)
8781
}

0 commit comments

Comments
 (0)