Skip to content

Commit e322e6a

Browse files
authored
tests: much faster tests (#242)
* tests: much faster tests 🚀 * build: skip flatten when running tests
1 parent a84e854 commit e322e6a

16 files changed

+411
-311
lines changed

buidler.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const config: BuidlerConfig = {
6262
version: '0.6.4',
6363
optimizer: {
6464
enabled: true,
65-
runs: 500,
65+
runs: 200,
6666
},
6767
},
6868
defaultNetwork: 'buidlerevm',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
"deploy": "npm run migrate",
6969
"deploy-kovan": "npm run migrate -- --force --network kovan",
7070
"migrate": "buidler migrate",
71-
"test": "npm run build && buidler test",
71+
"test": "scripts/test",
7272
"coverage": "SOLIDITY_COVERAGE=true npm run evm:test",
7373
"evm:test": "scripts/evm",
7474
"lint": "npm run lint:ts && npm run lint:sol",

scripts/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -eo pipefail
4+
5+
npm run compile
6+
npm run typechain
7+
buidler test

test/curation/configuration.test.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,37 @@
1-
import { expect } from 'chai'
1+
import { expect, use } from 'chai'
2+
import { solidity } from 'ethereum-waffle'
23

34
import { Curation } from '../../build/typechain/contracts/Curation'
45
import { GraphToken } from '../../build/typechain/contracts/GraphToken'
6+
import { Staking } from '../../build/typechain/contracts/Staking'
57

8+
import { NetworkFixture } from '../lib/fixtures'
69
import { defaults, provider, toBN } from '../lib/testHelpers'
7-
import { loadFixture } from './fixture.test'
10+
11+
use(solidity)
812

913
const MAX_PPM = 1000000
1014

1115
describe('Curation:Config', () => {
12-
const [me, governor, staking] = provider().getWallets()
16+
const [me, governor] = provider().getWallets()
17+
18+
let fixture: NetworkFixture
1319

1420
let curation: Curation
1521
let grt: GraphToken
22+
let staking: Staking
23+
24+
before(async function () {
25+
fixture = new NetworkFixture()
26+
;({ curation, grt, staking } = await fixture.load(governor))
27+
})
1628

1729
beforeEach(async function () {
18-
;({ curation, grt } = await loadFixture(governor, staking))
30+
await fixture.setUp()
31+
})
32+
33+
afterEach(async function () {
34+
await fixture.tearDown()
1935
})
2036

2137
it('should set `governor`', async function () {

test/curation/curation.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ import { solidity } from 'ethereum-waffle'
55
import { Curation } from '../../build/typechain/contracts/Curation'
66
import { GraphToken } from '../../build/typechain/contracts/GraphToken'
77

8+
import { NetworkFixture } from '../lib/fixtures'
89
import { defaults, provider, randomHexBytes, toBN, toGRT } from '../lib/testHelpers'
9-
import { loadFixture } from './fixture.test'
10-
11-
// const { formatEther } = utils
1210

1311
use(solidity)
1412

@@ -31,7 +29,9 @@ const chunkify = (total: BigNumber, maxChunks = 10): Array<BigNumber> => {
3129
}
3230

3331
describe('Curation', () => {
34-
const [me, governor, curator, staking] = provider().getWallets()
32+
const [me, governor, curator, stakingMock] = provider().getWallets()
33+
34+
let fixture: NetworkFixture
3535

3636
let curation: Curation
3737
let grt: GraphToken
@@ -136,7 +136,7 @@ describe('Curation', () => {
136136
const beforeTotalBalance = await grt.balanceOf(curation.address)
137137

138138
// Source of tokens must be the staking for this to work
139-
const tx = curation.connect(staking).collect(subgraphDeploymentID, tokensToCollect)
139+
const tx = curation.connect(stakingMock).collect(subgraphDeploymentID, tokensToCollect)
140140
await expect(tx).emit(curation, 'Collected').withArgs(subgraphDeploymentID, tokensToCollect)
141141

142142
// After state
@@ -148,16 +148,28 @@ describe('Curation', () => {
148148
expect(afterTotalBalance).eq(beforeTotalBalance.add(tokensToCollect))
149149
}
150150

151-
beforeEach(async function () {
152-
;({ curation, grt } = await loadFixture(governor, staking))
151+
before(async function () {
152+
fixture = new NetworkFixture()
153+
;({ curation, grt } = await fixture.load(governor))
154+
155+
// Replace the staking contract with a mock so we can call collect
156+
await curation.connect(governor).setStaking(stakingMock.address)
153157

154158
// Give some funds to the curator and approve the curation contract
155159
await grt.connect(governor).mint(curator.address, curatorTokens)
156160
await grt.connect(curator).approve(curation.address, curatorTokens)
157161

158162
// Give some funds to the staking contract and approve the curation contract
159-
await grt.connect(governor).mint(staking.address, tokensToCollect)
160-
await grt.connect(staking).approve(curation.address, tokensToCollect)
163+
await grt.connect(governor).mint(stakingMock.address, tokensToCollect)
164+
await grt.connect(stakingMock).approve(curation.address, tokensToCollect)
165+
})
166+
167+
beforeEach(async function () {
168+
await fixture.setUp()
169+
})
170+
171+
afterEach(async function () {
172+
await fixture.tearDown()
161173
})
162174

163175
describe('bonding curve', function () {
@@ -210,7 +222,7 @@ describe('Curation', () => {
210222
context('> not curated', async function () {
211223
it('reject collect tokens distributed to the curation pool', async function () {
212224
// Source of tokens must be the staking for this to work
213-
const tx = curation.connect(staking).collect(subgraphDeploymentID, tokensToCollect)
225+
const tx = curation.connect(stakingMock).collect(subgraphDeploymentID, tokensToCollect)
214226
await expect(tx).revertedWith('SubgraphDeployment must be curated to collect fees')
215227
})
216228
})

test/curation/fixture.test.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

test/disputes/configuration.test.ts

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
import { expect, use } from 'chai'
2+
import { solidity } from 'ethereum-waffle'
3+
4+
import { DisputeManager } from '../../build/typechain/contracts/DisputeManager'
5+
import { GraphToken } from '../../build/typechain/contracts/GraphToken'
6+
import { Staking } from '../../build/typechain/contracts/Staking'
7+
8+
import { NetworkFixture } from '../lib/fixtures'
9+
import { defaults, provider, toBN } from '../lib/testHelpers'
10+
11+
use(solidity)
12+
13+
const MAX_PPM = 1000000
14+
15+
describe('DisputeManager:Config', () => {
16+
const [me, governor, slasher, arbitrator] = provider().getWallets()
17+
18+
let fixture: NetworkFixture
19+
20+
let disputeManager: DisputeManager
21+
let grt: GraphToken
22+
let staking: Staking
23+
24+
before(async function () {
25+
fixture = new NetworkFixture()
26+
;({ disputeManager, grt, staking } = await fixture.load(governor, slasher, arbitrator))
27+
})
28+
29+
beforeEach(async function () {
30+
await fixture.setUp()
31+
})
32+
33+
afterEach(async function () {
34+
await fixture.tearDown()
35+
})
36+
37+
describe('configuration', () => {
38+
it('should set `governor`', async function () {
39+
// Set right in the constructor
40+
expect(await disputeManager.governor()).eq(governor.address)
41+
})
42+
43+
it('should set `graphToken`', async function () {
44+
// Set right in the constructor
45+
expect(await disputeManager.token()).eq(grt.address)
46+
})
47+
48+
describe('arbitrator', function () {
49+
it('should set `arbitrator`', async function () {
50+
// Set right in the constructor
51+
expect(await disputeManager.arbitrator()).eq(arbitrator.address)
52+
53+
// Can set if allowed
54+
await disputeManager.connect(governor).setArbitrator(me.address)
55+
expect(await disputeManager.arbitrator()).eq(me.address)
56+
})
57+
58+
it('reject set `arbitrator` if not allowed', async function () {
59+
const tx = disputeManager.connect(me).setArbitrator(arbitrator.address)
60+
await expect(tx).revertedWith('Only Governor can call')
61+
})
62+
})
63+
64+
describe('minimumDeposit', function () {
65+
it('should set `minimumDeposit`', async function () {
66+
const oldValue = defaults.dispute.minimumDeposit
67+
const newValue = toBN('1')
68+
69+
// Set right in the constructor
70+
expect(await disputeManager.minimumDeposit()).eq(oldValue)
71+
72+
// Set new value
73+
await disputeManager.connect(governor).setMinimumDeposit(newValue)
74+
expect(await disputeManager.minimumDeposit()).eq(newValue)
75+
})
76+
77+
it('reject set `minimumDeposit` if not allowed', async function () {
78+
const newValue = toBN('1')
79+
const tx = disputeManager.connect(me).setMinimumDeposit(newValue)
80+
await expect(tx).revertedWith('Only Governor can call')
81+
})
82+
})
83+
84+
describe('fishermanRewardPercentage', function () {
85+
it('should set `fishermanRewardPercentage`', async function () {
86+
const newValue = defaults.dispute.fishermanRewardPercentage
87+
88+
// Set right in the constructor
89+
expect(await disputeManager.fishermanRewardPercentage()).eq(newValue)
90+
91+
// Set new value
92+
await disputeManager.connect(governor).setFishermanRewardPercentage(0)
93+
await disputeManager.connect(governor).setFishermanRewardPercentage(newValue)
94+
})
95+
96+
it('reject set `fishermanRewardPercentage` if out of bounds', async function () {
97+
const tx = disputeManager.connect(governor).setFishermanRewardPercentage(MAX_PPM + 1)
98+
await expect(tx).revertedWith('Reward percentage must be below or equal to MAX_PPM')
99+
})
100+
101+
it('reject set `fishermanRewardPercentage` if not allowed', async function () {
102+
const tx = disputeManager.connect(me).setFishermanRewardPercentage(50)
103+
await expect(tx).revertedWith('Only Governor can call')
104+
})
105+
})
106+
107+
describe('slashingPercentage', function () {
108+
it('should set `slashingPercentage`', async function () {
109+
const newValue = defaults.dispute.slashingPercentage
110+
111+
// Set right in the constructor
112+
expect(await disputeManager.slashingPercentage()).eq(newValue.toString())
113+
114+
// Set new value
115+
await disputeManager.connect(governor).setSlashingPercentage(0)
116+
await disputeManager.connect(governor).setSlashingPercentage(newValue)
117+
})
118+
119+
it('reject set `slashingPercentage` if out of bounds', async function () {
120+
const tx = disputeManager.connect(governor).setSlashingPercentage(MAX_PPM + 1)
121+
await expect(tx).revertedWith('Slashing percentage must be below or equal to MAX_PPM')
122+
})
123+
124+
it('reject set `slashingPercentage` if not allowed', async function () {
125+
const tx = disputeManager.connect(me).setSlashingPercentage(50)
126+
await expect(tx).revertedWith('Only Governor can call')
127+
})
128+
})
129+
130+
describe('staking', function () {
131+
it('should set `staking`', async function () {
132+
// Set right in the constructor
133+
expect(await disputeManager.staking()).eq(staking.address)
134+
135+
// Can set if allowed
136+
await disputeManager.connect(governor).setStaking(grt.address)
137+
expect(await disputeManager.staking()).eq(grt.address)
138+
})
139+
140+
it('reject set `staking` if not allowed', async function () {
141+
const tx = disputeManager.connect(me).setStaking(grt.address)
142+
await expect(tx).revertedWith('Only Governor can call')
143+
})
144+
})
145+
})
146+
})

0 commit comments

Comments
 (0)