Skip to content

Commit 842a8da

Browse files
authored
feat: add account management methods to GRE (#645)
* feat: add account management methods to GRE Signed-off-by: Tomás Migone <[email protected]>
1 parent 7c6e27d commit 842a8da

32 files changed

+388
-152
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

config/graph.goerli.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ contracts:
3030
- fn: "setContractProxy"
3131
id: "0x45fc200c7e4544e457d3c5709bfe0d520442c30bbcbdaede89e8d4a4bbc19247" # keccak256('GraphToken')
3232
contractAddress: "${{GraphToken.address}}"
33+
- fn: "setPauseGuardian"
34+
pauseGuardian: *pauseGuardian
35+
- fn: "transferOwnership"
36+
owner: *governor
37+
GraphProxyAdmin:
38+
calls:
39+
- fn: "transferOwnership"
40+
owner: *governor
3341
ServiceRegistry:
3442
proxy: true
3543
init:
@@ -45,6 +53,9 @@ contracts:
4553
calls:
4654
- fn: "addMinter"
4755
minter: "${{RewardsManager.address}}"
56+
- fn: "renounceMinter"
57+
- fn: "transferOwnership"
58+
owner: *governor
4859
Curation:
4960
proxy: true
5061
init:
@@ -79,6 +90,8 @@ contracts:
7990
tokenDescriptor: "${{SubgraphNFTDescriptor.address}}"
8091
- fn: "setMinter"
8192
minter: "${{GNS.address}}"
93+
- fn: "transferOwnership"
94+
owner: *governor
8295
Staking:
8396
proxy: true
8497
init:
@@ -107,6 +120,9 @@ contracts:
107120
init:
108121
controller: "${{Controller.address}}"
109122
issuanceRate: "1000000012184945188" # per block increase of total supply, blocks in a year = 365*60*60*24/13
123+
calls:
124+
- fn: "setSubgraphAvailabilityOracle"
125+
subgraphAvailabilityOracle: *availabilityOracle
110126
AllocationExchange:
111127
init:
112128
graphToken: "${{GraphToken.address}}"

e2e/deployment/allocationExchange.test.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { expect } from 'chai'
2+
import hre from 'hardhat'
3+
import { NamedAccounts } from '../../../tasks/type-extensions'
4+
5+
describe('AllocationExchange configuration', () => {
6+
const {
7+
contracts: { AllocationExchange },
8+
getNamedAccounts,
9+
} = hre.graph()
10+
11+
let namedAccounts: NamedAccounts
12+
13+
before(async () => {
14+
namedAccounts = await getNamedAccounts()
15+
})
16+
17+
it('should be owned by allocationExchangeOwner', async function () {
18+
const owner = await AllocationExchange.governor()
19+
expect(owner).eq(namedAccounts.allocationExchangeOwner.address)
20+
})
21+
22+
it('should accept vouchers from authority', async function () {
23+
const allowed = await AllocationExchange.authority(namedAccounts.authority.address)
24+
expect(allowed).eq(true)
25+
})
26+
27+
// graphToken and staking are private variables so we can't verify
28+
it.skip('graphToken should match the GraphToken deployment address')
29+
it.skip('staking should match the Staking deployment address')
30+
})

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

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

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

99
const proxyContracts = [
@@ -16,6 +16,12 @@ describe('Controller deployment', () => {
1616
'GraphToken',
1717
]
1818

19+
let namedAccounts: NamedAccounts
20+
21+
before(async () => {
22+
namedAccounts = await getNamedAccounts()
23+
})
24+
1925
const proxyShouldMatchDeployed = async (contractName: string) => {
2026
const curationAddress = await Controller.getContractProxy(
2127
ethers.utils.solidityKeccak256(['string'], [contractName]),
@@ -25,14 +31,12 @@ describe('Controller deployment', () => {
2531

2632
it('should be owned by governor', async function () {
2733
const owner = await Controller.governor()
28-
const governorAddress = getItemValue(graphConfig, 'general/governor')
29-
expect(owner).eq(governorAddress)
34+
expect(owner).eq(namedAccounts.governor.address)
3035
})
3136

3237
it('pause guardian should be able to pause protocol', async function () {
33-
const pauseGuardianAddress = getItemValue(graphConfig, 'general/pauseGuardian')
3438
const pauseGuardian = await Controller.pauseGuardian()
35-
expect(pauseGuardian).eq(pauseGuardianAddress)
39+
expect(pauseGuardian).eq(namedAccounts.pauseGuardian.address)
3640
})
3741

3842
describe('proxy contract', async function () {

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
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { expect } from 'chai'
2+
import hre from 'hardhat'
3+
import { NamedAccounts } from '../../../tasks/type-extensions'
4+
5+
describe('GraphProxyAdmin configuration', () => {
6+
const {
7+
contracts: { GraphProxyAdmin },
8+
getNamedAccounts,
9+
} = hre.graph()
10+
11+
let namedAccounts: NamedAccounts
12+
13+
before(async () => {
14+
namedAccounts = await getNamedAccounts()
15+
})
16+
17+
it('should be owned by governor', async function () {
18+
const owner = await GraphProxyAdmin.governor()
19+
expect(owner).eq(namedAccounts.governor.address)
20+
})
21+
})

0 commit comments

Comments
 (0)