Skip to content

Commit

Permalink
test: use separate address book for unit tests (#899)
Browse files Browse the repository at this point in the history
* test: do not commit local addressbook

Signed-off-by: Tomás Migone <[email protected]>

* fix: tests assuming address.json

Signed-off-by: Tomás Migone <[email protected]>

* chore: clean up address book

Signed-off-by: Tomás Migone <[email protected]>

* test: fix coverage command

Signed-off-by: Tomás Migone <[email protected]>

* test: fix coverage ci

Signed-off-by: Tomás Migone <[email protected]>

---------

Signed-off-by: Tomás Migone <[email protected]>
  • Loading branch information
tmigone authored Dec 26, 2023
1 parent d9aafd1 commit 37a59dd
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ bin/
.vscode

# Coverage and other reports
/reports
reports/
coverage.json

# Local test files
Expand Down
319 changes: 0 additions & 319 deletions packages/contracts/addresses.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/contracts/cli/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Overrides } from 'ethers'
export const local = {
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
providerUrl: 'http://localhost:8545',
addressBookPath: './addresses.json',
addressBookPath: './addresses-local.json',
graphConfigPath: './config/graph.mainnet.yml',
accountNumber: '0',
arbitrumAddressBookPath: './arbitrum-addresses.json',
Expand Down
3 changes: 3 additions & 0 deletions packages/contracts/scripts/coverage
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ set -eo pipefail

yarn build

echo {} > addresses-local.json

DISABLE_SECURE_ACCOUNTS=true \
L1_GRAPH_CONFIG=config/graph.hardhat.yml \
L2_GRAPH_CONFIG=config/graph.arbitrum-hardhat.yml \
ADDRESS_BOOK=addresses-local.json \
npx hardhat coverage $@
3 changes: 3 additions & 0 deletions packages/contracts/scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ fi

### Main

# Init address book
echo {} > addresses-local.json

mkdir -p reports

# Run using the standalone evm instance
Expand Down
31 changes: 17 additions & 14 deletions packages/contracts/test/gns.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
loadContractAt,
} from '@graphprotocol/sdk'
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
import { SubgraphNFT } from '../build/types'

const { AddressZero, HashZero } = ethers.constants

Expand All @@ -45,7 +46,7 @@ const toFloat = (n: BigNumber) => parseFloat(formatGRT(n))
const toRound = (n: number) => n.toFixed(12)

describe('L1GNS', () => {
const graph = hre.graph()
const graph = hre.graph({ addressBook: 'addresses-local.json' })

let me: SignerWithAddress
let other: SignerWithAddress
Expand All @@ -65,6 +66,7 @@ describe('L1GNS', () => {
let curation: Curation
let controller: Controller
let proxyAdmin: GraphProxyAdmin
let subgraphNFT: SubgraphNFT
let l1GraphTokenGateway: L1GraphTokenGateway
let arbitrumMocks: ArbitrumL1Mocks

Expand Down Expand Up @@ -244,6 +246,7 @@ describe('L1GNS', () => {
controller = fixtureContracts.Controller as Controller
proxyAdmin = fixtureContracts.GraphProxyAdmin as GraphProxyAdmin
l1GraphTokenGateway = fixtureContracts.L1GraphTokenGateway as L1GraphTokenGateway
subgraphNFT = fixtureContracts.SubgraphNFT as SubgraphNFT

newSubgraph0 = buildSubgraph()
newSubgraph1 = buildSubgraph()
Expand Down Expand Up @@ -888,17 +891,17 @@ describe('L1GNS', () => {

describe('NFT descriptor', function () {
it('cannot be minted by an account that is not the minter (i.e. GNS)', async function () {
const tx = graph.contracts.SubgraphNFT.connect(me).mint(me.address, 1)
const tx = subgraphNFT.connect(me).mint(me.address, 1)
await expect(tx).revertedWith('Must be a minter')
})
it('cannot be burned by an account that is not the minter (i.e. GNS)', async function () {
const tx = graph.contracts.SubgraphNFT.connect(me).burn(1)
const tx = subgraphNFT.connect(me).burn(1)
await expect(tx).revertedWith('Must be a minter')
})
it('with token descriptor', async function () {
const subgraph0 = await publishNewSubgraph(me, newSubgraph0, gns, graph.chainId)

const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph0.subgraphMetadata)
expect(sub.ipfsHash).eq(tokenURI)
Expand All @@ -907,8 +910,8 @@ describe('L1GNS', () => {
it('with token descriptor and baseURI', async function () {
const subgraph0 = await publishNewSubgraph(me, newSubgraph0, gns, graph.chainId)

await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph0.subgraphMetadata)
expect('ipfs://' + sub.ipfsHash).eq(tokenURI)
Expand All @@ -917,8 +920,8 @@ describe('L1GNS', () => {
it('without token descriptor', async function () {
const subgraph0 = await publishNewSubgraph(me, newSubgraph0, gns, graph.chainId)

await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph0.subgraphMetadata)
expect(sub.bytes32).eq(tokenURI)
Expand All @@ -927,9 +930,9 @@ describe('L1GNS', () => {
it('without token descriptor and baseURI', async function () {
const subgraph0 = await publishNewSubgraph(me, newSubgraph0, gns, graph.chainId)

await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)

const sub = new SubgraphDeploymentID(newSubgraph0.subgraphMetadata)
expect('ipfs://' + sub.bytes32).eq(tokenURI)
Expand All @@ -940,9 +943,9 @@ describe('L1GNS', () => {
newSubgraphNoMetadata.subgraphMetadata = HashZero
const subgraph0 = await publishNewSubgraph(me, newSubgraphNoMetadata, gns, graph.chainId)

await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
expect('ipfs://' + subgraph0.id).eq(tokenURI)
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/contracts/test/lib/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export class NetworkFixture {

// Deploy contracts
await deployGraphNetwork(
'./addresses.json',
'./addresses-local.json',
l2Deploy ? './config/graph.arbitrum-hardhat.yml' : './config/graph.hardhat.yml',
1337,
deployer,
Expand All @@ -93,7 +93,7 @@ export class NetworkFixture {
)

const contracts = loadGraphNetworkContracts(
'./addresses.json',
'./addresses-local.json',
1337,
this.provider,
undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/staking/allocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const ABI_LIB_EXPONENTIAL = [
]

describe('Staking:Allocation', () => {
const graph = hre.graph()
const graph = hre.graph({ addressBook: 'addresses-local.json' })
let me: SignerWithAddress
let governor: SignerWithAddress
let indexer: SignerWithAddress
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/staking/rebate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function exponentialRebates(
}

describe('Staking:rebates', () => {
const graph = hre.graph()
const graph = hre.graph({ addressBook: 'addresses-local.json' })

let libExponential: LibExponential
let fixture: NetworkFixture
Expand Down

0 comments on commit 37a59dd

Please sign in to comment.