Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(contracts): optionally override address book #114

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/common-ts/src/contracts/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Signer } from 'ethers'
import { connectContracts } from '.'
import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json'

jest.mock('ethers')

Expand All @@ -8,7 +9,7 @@ const mockSigner = jest.fn() as unknown as Signer
describe('Contracts', () => {
// Test for each supported protocol network
test.each([1, 5, 42161, 421613])('Connect contracts [chainId: %p]', chainId => {
const contracts = connectContracts(mockSigner, chainId)
const contracts = connectContracts(mockSigner, chainId, DEPLOYED_CONTRACTS)
expect(contracts).toBeDefined()
})
})
9 changes: 4 additions & 5 deletions packages/common-ts/src/contracts/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { providers, Signer } from 'ethers'
import graphChain from './chain'

// Contract addresses
import * as DEPLOYED_CONTRACTS from '@graphprotocol/contracts/addresses.json'

// Contract ABIs
import { Curation } from '@graphprotocol/contracts/dist/types/Curation'
import { DisputeManager } from '@graphprotocol/contracts/dist/types/DisputeManager'
Expand Down Expand Up @@ -71,12 +68,14 @@ export interface NetworkContracts {
l2GraphTokenGateway?: L2GraphTokenGateway
}

export type AddressBook = { [key: string]: { [key: string]: { address: string } } }

export const connectContracts = async (
providerOrSigner: providers.Provider | Signer,
chainId: number,
addressBook: AddressBook,
): Promise<NetworkContracts> => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const deployedContracts = (DEPLOYED_CONTRACTS as any)[`${chainId}`]
const deployedContracts = addressBook[`${chainId}`]
if (!deployedContracts) {
throw new Error(`chainId: '${chainId}' has no deployed contracts`)
}
Expand Down
Loading