Skip to content

Commit 5883005

Browse files
committed
feat: split e2e tests into config and init
Signed-off-by: Tomás Migone <[email protected]>
1 parent d5709f8 commit 5883005

22 files changed

+162
-51
lines changed

README.md

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,34 +90,58 @@ To test a single file run: `npx hardhat test test/<FILE_NAME>.ts`
9090

9191
## E2E Testing
9292

93-
End to end tests are also available and can be run against a local network or a live network. These can be useful to validate a protocol deployment is configured and working as expected.
93+
End to end tests are also available and can be run against a local network or a live network. These can be useful to validate a protocol deployment is configured and working as expected.
94+
95+
There are several types of e2e tests which can be run separately:
96+
- **deployment/config**
97+
- Test the configuration of deployed contracts (parameters that don't change over time).
98+
- Can be run against any network at any time and the tests should pass.
99+
- Only read only interactions with the blockchain.
100+
- Example: a test validating the curation default reserve ratio matches the value in the graph config file.
101+
- **deployment/init**
102+
- Test the initialization of deployed contracts (parameters that change with protocol usage).
103+
- Can be run against a "fresh" protocol deployment. Running these tests against a protocol with pre-existing state will probably fail.
104+
- Only read only interactions with the blockchain.
105+
- Example: a test validating that the GRT total supply equals 10B, this is only true on a freshly deployed protocol until the first allocation is closed and protocol issuance kicks in.
106+
- **scenarios**
107+
- Test the execution of common protocol actions.
108+
- Can be run against any network at any time and the tests should pass.
109+
- Read and write interactions with the blockchain. _Requires an account with sufficient balance!_
110+
- Example: a test validating that a user can add signal to a subgraph.
94111

95112
### Hardhat local node
96113

97-
To run e2e tests against a hardhat local node run:
114+
To run all e2e tests against a hardhat local node run:
98115

99116
```bash
100117
yarn test:e2e
101118
```
102119

103-
The command will invoke several hardhat tasks, including:
120+
The command will perform the following actions:
104121

105122
- Start a hardhat node (localhost)
106123
- Run `migrate:accounts` hardhat task to create keys for all protocol roles (deployer, governor, arbiter, etc). This currently doesn't support multisig accounts.
107124
- Run `migrate` hardhat task to deploy the protocol
108125
- Run `migrate:ownership` hardhat task to transfer ownership of governed contracts to the governor
109126
- Run `migrate:unpause` to unpause the protocol
110-
- Run e2e tests
127+
- Run `e2e` hardhat task to run all e2e tests
111128

112129
### Other networks
113130

114131
To run tests against a live testnet or even mainnet run:
115132

116133
```bash
117-
GRAPH_CONFIG=config/graph.<network>.yml ADDRESS_BOOK=addresses.json npx hardhat test e2e/**/*.ts --network <network>
134+
# All e2e tests
135+
npx hardhat e2e --network <network> --graph-config config/graph.<network>.yml
136+
137+
# Only deployment config tests
138+
npx hardhat e2e:config --network <network> --graph-config config/graph.<network>.yml
139+
140+
# Only deployment init tests
141+
npx hardhat e2e:init --network <network> --graph-config config/graph.<network>.yml
118142
```
119143

120-
This command will only run the tests so you need to be sure the protocol is already deployed and the graph config file and address book files are up to date.
144+
Note that this command will only run the tests so you need to be sure the protocol is already deployed and the graph config file and address book files are up to date.
121145

122146
# Interacting with the contracts
123147

e2e/deployment/allocationExchange.test.ts renamed to e2e/deployment/config/allocationExchange.test.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('AllocationExchange deployment', () => {
5+
describe('AllocationExchange configuration', () => {
66
const {
77
graphConfig,
8-
contracts: { AllocationExchange, GraphToken, Staking },
8+
contracts: { AllocationExchange },
99
} = hre.graph()
1010

1111
it('should be owned by allocationExchangeOwner', async function () {
@@ -23,9 +23,4 @@ describe('AllocationExchange deployment', () => {
2323
// graphToken and staking are private variables so we can't verify
2424
it.skip('graphToken should match the GraphToken deployment address')
2525
it.skip('staking should match the Staking deployment address')
26-
27-
it('should allow Staking contract to spend MAX_UINT256 tokens on AllocationExchange behalf', async function () {
28-
const allowance = await GraphToken.allowance(AllocationExchange.address, Staking.address)
29-
expect(allowance).eq(hre.ethers.constants.MaxUint256)
30-
})
3126
})

e2e/deployment/controller.test.ts renamed to e2e/deployment/config/controller.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre, { ethers } from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('Controller deployment', () => {
5+
describe('Controller configuration', () => {
66
const { contracts, graphConfig } = hre.graph()
77
const { Controller } = contracts
88

e2e/deployment/curation.test.ts renamed to e2e/deployment/config/curation.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('Curation deployment', () => {
5+
describe('Curation configuration', () => {
66
const {
77
graphConfig,
88
contracts: { Controller, Curation, BancorFormula, GraphCurationToken },

e2e/deployment/disputeManager.test.ts renamed to e2e/deployment/config/disputeManager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('DisputeManager deployment', () => {
5+
describe('DisputeManager configuration', () => {
66
const {
77
graphConfig,
88
contracts: { Controller, DisputeManager },

e2e/deployment/epochManager.test.ts renamed to e2e/deployment/config/epochManager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('EpochManager deployment', () => {
5+
describe('EpochManager configuration', () => {
66
const {
77
graphConfig,
88
contracts: { EpochManager, Controller },

e2e/deployment/gns.test.ts renamed to e2e/deployment/config/gns.test.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
33

4-
describe('GNS deployment', () => {
4+
describe('GNS configuration', () => {
55
const {
6-
contracts: { Controller, GNS, BancorFormula, SubgraphNFT, GraphToken, Curation },
6+
contracts: { Controller, GNS, BancorFormula, SubgraphNFT },
77
} = hre.graph()
88

99
it('should be controlled by Controller', async function () {
@@ -20,9 +20,4 @@ describe('GNS deployment', () => {
2020
const subgraphNFT = await GNS.subgraphNFT()
2121
expect(subgraphNFT).eq(SubgraphNFT.address)
2222
})
23-
24-
it('should allow Curation contract to spend MAX_UINT256 tokens on GNS behalf', async function () {
25-
const allowance = await GraphToken.allowance(GNS.address, Curation.address)
26-
expect(allowance).eq(hre.ethers.constants.MaxUint256)
27-
})
2823
})

e2e/deployment/graphProxyAdmin.test.ts renamed to e2e/deployment/config/graphProxyAdmin.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('GraphProxyAdmin deployment', () => {
5+
describe('GraphProxyAdmin configuration', () => {
66
const {
77
contracts: { GraphProxyAdmin },
88
graphConfig,

e2e/deployment/graphToken.test.ts renamed to e2e/deployment/config/graphToken.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3-
import { getItemValue } from '../../cli/config'
3+
import { getItemValue } from '../../../cli/config'
44

5-
describe('GraphToken deployment', () => {
5+
describe('GraphToken configuration', () => {
66
const {
77
graphConfig,
88
contracts: { GraphToken, RewardsManager },
@@ -25,10 +25,4 @@ describe('GraphToken deployment', () => {
2525
const deployerIsMinter = await GraphToken.isMinter(RewardsManager.address)
2626
expect(deployerIsMinter).eq(true)
2727
})
28-
29-
it('total supply should match "initialSupply" on the config file', async function () {
30-
const value = await GraphToken.totalSupply()
31-
const expected = getItemValue(graphConfig, 'contracts/GraphToken/init/initialSupply')
32-
hre.network.config.chainId === 1337 ? expect(value).eq(expected) : expect(value).gte(expected)
33-
})
3428
})

e2e/deployment/protocol.ts renamed to e2e/deployment/config/protocol.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
33

4-
describe('Protocol', () => {
4+
describe('Protocol configuration', () => {
55
const { contracts } = hre.graph()
66

77
it('should be unpaused', async function () {

0 commit comments

Comments
 (0)