Skip to content

Commit 37a59dd

Browse files
authored
test: use separate address book for unit tests (#899)
* 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]>
1 parent d9aafd1 commit 37a59dd

File tree

9 files changed

+29
-339
lines changed

9 files changed

+29
-339
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ bin/
3131
.vscode
3232

3333
# Coverage and other reports
34-
/reports
34+
reports/
3535
coverage.json
3636

3737
# Local test files

packages/contracts/addresses.json

Lines changed: 0 additions & 319 deletions
Large diffs are not rendered by default.

packages/contracts/cli/defaults.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { Overrides } from 'ethers'
44
export const local = {
55
mnemonic: 'myth like bonus scare over problem client lizard pioneer submit female collect',
66
providerUrl: 'http://localhost:8545',
7-
addressBookPath: './addresses.json',
7+
addressBookPath: './addresses-local.json',
88
graphConfigPath: './config/graph.mainnet.yml',
99
accountNumber: '0',
1010
arbitrumAddressBookPath: './arbitrum-addresses.json',

packages/contracts/scripts/coverage

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ set -eo pipefail
44

55
yarn build
66

7+
echo {} > addresses-local.json
8+
79
DISABLE_SECURE_ACCOUNTS=true \
810
L1_GRAPH_CONFIG=config/graph.hardhat.yml \
911
L2_GRAPH_CONFIG=config/graph.arbitrum-hardhat.yml \
12+
ADDRESS_BOOK=addresses-local.json \
1013
npx hardhat coverage $@

packages/contracts/scripts/test

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ fi
2626

2727
### Main
2828

29+
# Init address book
30+
echo {} > addresses-local.json
31+
2932
mkdir -p reports
3033

3134
# Run using the standalone evm instance

packages/contracts/test/gns.test.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737
loadContractAt,
3838
} from '@graphprotocol/sdk'
3939
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
40+
import { SubgraphNFT } from '../build/types'
4041

4142
const { AddressZero, HashZero } = ethers.constants
4243

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

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

5051
let me: SignerWithAddress
5152
let other: SignerWithAddress
@@ -65,6 +66,7 @@ describe('L1GNS', () => {
6566
let curation: Curation
6667
let controller: Controller
6768
let proxyAdmin: GraphProxyAdmin
69+
let subgraphNFT: SubgraphNFT
6870
let l1GraphTokenGateway: L1GraphTokenGateway
6971
let arbitrumMocks: ArbitrumL1Mocks
7072

@@ -244,6 +246,7 @@ describe('L1GNS', () => {
244246
controller = fixtureContracts.Controller as Controller
245247
proxyAdmin = fixtureContracts.GraphProxyAdmin as GraphProxyAdmin
246248
l1GraphTokenGateway = fixtureContracts.L1GraphTokenGateway as L1GraphTokenGateway
249+
subgraphNFT = fixtureContracts.SubgraphNFT as SubgraphNFT
247250

248251
newSubgraph0 = buildSubgraph()
249252
newSubgraph1 = buildSubgraph()
@@ -888,17 +891,17 @@ describe('L1GNS', () => {
888891

889892
describe('NFT descriptor', function () {
890893
it('cannot be minted by an account that is not the minter (i.e. GNS)', async function () {
891-
const tx = graph.contracts.SubgraphNFT.connect(me).mint(me.address, 1)
894+
const tx = subgraphNFT.connect(me).mint(me.address, 1)
892895
await expect(tx).revertedWith('Must be a minter')
893896
})
894897
it('cannot be burned by an account that is not the minter (i.e. GNS)', async function () {
895-
const tx = graph.contracts.SubgraphNFT.connect(me).burn(1)
898+
const tx = subgraphNFT.connect(me).burn(1)
896899
await expect(tx).revertedWith('Must be a minter')
897900
})
898901
it('with token descriptor', async function () {
899902
const subgraph0 = await publishNewSubgraph(me, newSubgraph0, gns, graph.chainId)
900903

901-
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
904+
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
902905

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

910-
await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
911-
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
913+
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
914+
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
912915

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

920-
await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
921-
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
923+
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
924+
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
922925

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

930-
await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
931-
await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
932-
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
933+
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
934+
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
935+
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
933936

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

943-
await graph.contracts.SubgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
944-
await graph.contracts.SubgraphNFT.connect(governor).setBaseURI('ipfs://')
945-
const tokenURI = await graph.contracts.SubgraphNFT.connect(me).tokenURI(subgraph0.id)
946+
await subgraphNFT.connect(governor).setTokenDescriptor(AddressZero)
947+
await subgraphNFT.connect(governor).setBaseURI('ipfs://')
948+
const tokenURI = await subgraphNFT.connect(me).tokenURI(subgraph0.id)
946949
expect('ipfs://' + subgraph0.id).eq(tokenURI)
947950
})
948951
})

packages/contracts/test/lib/fixtures.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class NetworkFixture {
8080

8181
// Deploy contracts
8282
await deployGraphNetwork(
83-
'./addresses.json',
83+
'./addresses-local.json',
8484
l2Deploy ? './config/graph.arbitrum-hardhat.yml' : './config/graph.hardhat.yml',
8585
1337,
8686
deployer,
@@ -93,7 +93,7 @@ export class NetworkFixture {
9393
)
9494

9595
const contracts = loadGraphNetworkContracts(
96-
'./addresses.json',
96+
'./addresses-local.json',
9797
1337,
9898
this.provider,
9999
undefined,

packages/contracts/test/staking/allocation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const ABI_LIB_EXPONENTIAL = [
7979
]
8080

8181
describe('Staking:Allocation', () => {
82-
const graph = hre.graph()
82+
const graph = hre.graph({ addressBook: 'addresses-local.json' })
8383
let me: SignerWithAddress
8484
let governor: SignerWithAddress
8585
let indexer: SignerWithAddress

packages/contracts/test/staking/rebate.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export function exponentialRebates(
103103
}
104104

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

108108
let libExponential: LibExponential
109109
let fixture: NetworkFixture

0 commit comments

Comments
 (0)