Skip to content

Commit 2dc2a5a

Browse files
committed
feat: add bridge tests
Signed-off-by: Tomás Migone <[email protected]>
1 parent 88758f9 commit 2dc2a5a

File tree

7 files changed

+168
-16
lines changed

7 files changed

+168
-16
lines changed

e2e/deployment/config/controller.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ describe('Controller configuration', () => {
4545
expect(address).eq(graph.contracts[contractName].address)
4646
}
4747

48+
it('protocol should be unpaused', async function () {
49+
const paused = await Controller.paused()
50+
expect(paused).eq(false)
51+
})
52+
4853
it('should be owned by governor', async function () {
4954
const owner = await Controller.governor()
5055
expect(owner).eq(namedAccounts.governor.address)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,83 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
33
import GraphChain from '../../../../gre/helpers/network'
4+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
45

56
describe('[L1] L1GraphTokenGateway configuration', function () {
67
const graph = hre.graph()
78
const { Controller, L1GraphTokenGateway } = graph.contracts
89

10+
let unauthorized: SignerWithAddress
911
before(async function () {
1012
if (GraphChain.isL2(graph.chainId)) this.skip()
13+
unauthorized = (await graph.getTestAccounts())[0]
14+
})
15+
16+
it('bridge should be unpaused', async function () {
17+
const paused = await L1GraphTokenGateway.paused()
18+
expect(paused).eq(false)
1119
})
1220

1321
it('should be controlled by Controller', async function () {
1422
const controller = await L1GraphTokenGateway.controller()
1523
expect(controller).eq(Controller.address)
1624
})
25+
26+
describe('calls with unauthorized user', () => {
27+
it('initialize should revert', async function () {
28+
const tx = L1GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
29+
await expect(tx).revertedWith('Caller must be the implementation')
30+
})
31+
32+
it('setArbitrumAddresses should revert', async function () {
33+
const tx = L1GraphTokenGateway.connect(unauthorized).setArbitrumAddresses(
34+
unauthorized.address,
35+
unauthorized.address,
36+
)
37+
await expect(tx).revertedWith('Caller must be Controller governor')
38+
})
39+
40+
it('setL2TokenAddress should revert', async function () {
41+
const tx = L1GraphTokenGateway.connect(unauthorized).setL2TokenAddress(unauthorized.address)
42+
await expect(tx).revertedWith('Caller must be Controller governor')
43+
})
44+
45+
it('setL2CounterpartAddress should revert', async function () {
46+
const tx = L1GraphTokenGateway.connect(unauthorized).setL2CounterpartAddress(
47+
unauthorized.address,
48+
)
49+
await expect(tx).revertedWith('Caller must be Controller governor')
50+
})
51+
52+
it('setEscrowAddress should revert', async function () {
53+
const tx = L1GraphTokenGateway.connect(unauthorized).setEscrowAddress(unauthorized.address)
54+
await expect(tx).revertedWith('Caller must be Controller governor')
55+
})
56+
57+
it('addToCallhookWhitelist should revert', async function () {
58+
const tx = L1GraphTokenGateway.connect(unauthorized).addToCallhookWhitelist(
59+
unauthorized.address,
60+
)
61+
await expect(tx).revertedWith('Caller must be Controller governor')
62+
})
63+
64+
it('removeFromCallhookWhitelist should revert', async function () {
65+
const tx = L1GraphTokenGateway.connect(unauthorized).removeFromCallhookWhitelist(
66+
unauthorized.address,
67+
)
68+
await expect(tx).revertedWith('Caller must be Controller governor')
69+
})
70+
71+
it('finalizeInboundTransfer should revert', async function () {
72+
const tx = L1GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer(
73+
unauthorized.address,
74+
unauthorized.address,
75+
unauthorized.address,
76+
'100',
77+
'0x00',
78+
)
79+
80+
await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY')
81+
})
82+
})
1783
})
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import GraphChain from '../../../../gre/helpers/network'
5+
6+
describe('[L2] L2GraphToken', () => {
7+
const graph = hre.graph()
8+
const { L2GraphToken } = graph.contracts
9+
10+
let unauthorized: SignerWithAddress
11+
12+
before(async function () {
13+
if (GraphChain.isL1(graph.chainId)) this.skip()
14+
unauthorized = (await graph.getTestAccounts())[0]
15+
})
16+
17+
describe('calls with unauthorized user', () => {
18+
it('mint should revert', async function () {
19+
const tx = L2GraphToken.connect(unauthorized).mint(
20+
unauthorized.address,
21+
'1000000000000000000000',
22+
)
23+
await expect(tx).revertedWith('Only minter can call')
24+
})
25+
26+
it('bridgeMint should revert', async function () {
27+
const tx = L2GraphToken.connect(unauthorized).bridgeMint(
28+
unauthorized.address,
29+
'1000000000000000000000',
30+
)
31+
await expect(tx).revertedWith('NOT_GATEWAY')
32+
})
33+
34+
it('setGateway should revert', async function () {
35+
const tx = L2GraphToken.connect(unauthorized).setGateway(unauthorized.address)
36+
await expect(tx).revertedWith('Only Governor can call')
37+
})
38+
})
39+
})

e2e/deployment/config/l2/l2GraphTokenGateway.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
12
import { expect } from 'chai'
23
import hre from 'hardhat'
34
import GraphChain from '../../../../gre/helpers/network'
@@ -6,12 +7,55 @@ describe('[L2] L2GraphTokenGateway configuration', function () {
67
const graph = hre.graph()
78
const { Controller, L2GraphTokenGateway } = graph.contracts
89

10+
let unauthorized: SignerWithAddress
911
before(async function () {
1012
if (GraphChain.isL1(graph.chainId)) this.skip()
13+
unauthorized = (await graph.getTestAccounts())[0]
14+
})
15+
16+
it('bridge should be unpaused', async function () {
17+
const paused = await L2GraphTokenGateway.paused()
18+
expect(paused).eq(false)
1119
})
1220

1321
it('should be controlled by Controller', async function () {
1422
const controller = await L2GraphTokenGateway.controller()
1523
expect(controller).eq(Controller.address)
1624
})
25+
26+
describe('calls with unauthorized user', () => {
27+
it('initialize should revert', async function () {
28+
const tx = L2GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
29+
await expect(tx).revertedWith('Caller must be the implementation')
30+
})
31+
32+
it('setL2Router should revert', async function () {
33+
const tx = L2GraphTokenGateway.connect(unauthorized).setL2Router(unauthorized.address)
34+
await expect(tx).revertedWith('Caller must be Controller governor')
35+
})
36+
37+
it('setL1TokenAddress should revert', async function () {
38+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1TokenAddress(unauthorized.address)
39+
await expect(tx).revertedWith('Caller must be Controller governor')
40+
})
41+
42+
it('setL1CounterpartAddress should revert', async function () {
43+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1CounterpartAddress(
44+
unauthorized.address,
45+
)
46+
await expect(tx).revertedWith('Caller must be Controller governor')
47+
})
48+
49+
it('finalizeInboundTransfer should revert', async function () {
50+
const tx = L2GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer(
51+
unauthorized.address,
52+
unauthorized.address,
53+
unauthorized.address,
54+
'1000000000000',
55+
'0x00',
56+
)
57+
58+
await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY')
59+
})
60+
})
1761
})

e2e/deployment/config/protocol.test.ts

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

tasks/deployment/ownership.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ task('migrate:ownership', 'Accepts ownership of protocol contracts on behalf of
1515
console.log(`- Governor: ${governor.address}`)
1616

1717
const txs: ContractTransaction[] = []
18-
txs.push(await GraphToken.connect(governor).acceptOwnership())
1918
txs.push(await Controller.connect(governor).acceptOwnership())
2019
txs.push(await GraphProxyAdmin.connect(governor).acceptOwnership())
2120
txs.push(await SubgraphNFT.connect(governor).acceptOwnership())

tasks/deployment/unpause.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,25 @@
11
import { task } from 'hardhat/config'
22
import { cliOpts } from '../../cli/defaults'
3+
import GraphChain from '../../gre/helpers/network'
34

4-
task('migrate:unpause', 'Unpause protocol')
5+
task('migrate:unpause', 'Unpause protocol and bridge')
56
.addOptionalParam('addressBook', cliOpts.addressBook.description)
67
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
78
.setAction(async (taskArgs, hre) => {
8-
const { contracts, getNamedAccounts } = hre.graph(taskArgs)
9-
const { governor } = await getNamedAccounts()
9+
const graph = hre.graph(taskArgs)
10+
const { governor } = await graph.getNamedAccounts()
11+
const { Controller, L1GraphTokenGateway, L2GraphTokenGateway } = graph.contracts
1012

1113
console.log('> Unpausing protocol')
12-
const tx = await contracts.Controller.connect(governor).setPaused(false)
14+
const tx = await Controller.connect(governor).setPaused(false)
1315
await tx.wait()
16+
17+
console.log('> Unpausing bridge')
18+
const GraphTokenGateway = GraphChain.isL2(graph.chainId)
19+
? L2GraphTokenGateway
20+
: L1GraphTokenGateway
21+
const tx2 = await GraphTokenGateway.connect(governor).setPaused(false)
22+
await tx2.wait()
23+
1424
console.log('Done!')
1525
})

0 commit comments

Comments
 (0)