Skip to content

Commit b8ea9e6

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

12 files changed

+169
-125
lines changed

e2e/deployment/config/controller.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ describe('Controller configuration', () => {
3737
namedAccounts = await getNamedAccounts()
3838
})
3939

40+
it('protocol should be unpaused', async function () {
41+
const paused = await contracts.Controller.paused()
42+
expect(paused).eq(false)
43+
})
44+
4045
const proxyShouldMatchDeployed = async (contractName: string) => {
4146
// remove L1/L2 prefix, contracts are not registered as L1/L2 on controller
4247
const name = contractName.replace(/(^L1|L2)/gi, '')
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,88 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
12
import { expect } from 'chai'
23
import hre from 'hardhat'
34
import { chainIdIsL2 } from '../../../../cli/utils'
45

56
describe('[L1] L1GraphTokenGateway configuration', () => {
67
const {
78
contracts: { Controller, L1GraphTokenGateway },
9+
getTestAccounts,
810
} = hre.graph()
911

12+
let unauthorized: SignerWithAddress
13+
1014
before(async function () {
1115
const chainId = (await hre.ethers.provider.getNetwork()).chainId
1216
if (chainIdIsL2(chainId)) this.skip()
17+
18+
unauthorized = (await getTestAccounts())[0]
19+
})
20+
21+
it('bridge should be unpaused', async function () {
22+
const paused = await L1GraphTokenGateway.paused()
23+
expect(paused).eq(false)
1324
})
1425

1526
it('should be controlled by Controller', async function () {
1627
const controller = await L1GraphTokenGateway.controller()
1728
expect(controller).eq(Controller.address)
1829
})
30+
31+
describe('calls with unauthorized user', () => {
32+
it('initialize should revert', async function () {
33+
const tx = L1GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
34+
await expect(tx).revertedWith('Caller must be the implementation')
35+
})
36+
37+
it('setArbitrumAddresses should revert', async function () {
38+
const tx = L1GraphTokenGateway.connect(unauthorized).setArbitrumAddresses(
39+
unauthorized.address,
40+
unauthorized.address,
41+
)
42+
await expect(tx).revertedWith('Caller must be Controller governor')
43+
})
44+
45+
it('setL2TokenAddress should revert', async function () {
46+
const tx = L1GraphTokenGateway.connect(unauthorized).setL2TokenAddress(unauthorized.address)
47+
await expect(tx).revertedWith('Caller must be Controller governor')
48+
})
49+
50+
it('setL2CounterpartAddress should revert', async function () {
51+
const tx = L1GraphTokenGateway.connect(unauthorized).setL2CounterpartAddress(
52+
unauthorized.address,
53+
)
54+
await expect(tx).revertedWith('Caller must be Controller governor')
55+
})
56+
57+
it('setEscrowAddress should revert', async function () {
58+
const tx = L1GraphTokenGateway.connect(unauthorized).setEscrowAddress(unauthorized.address)
59+
await expect(tx).revertedWith('Caller must be Controller governor')
60+
})
61+
62+
it('addToCallhookWhitelist should revert', async function () {
63+
const tx = L1GraphTokenGateway.connect(unauthorized).addToCallhookWhitelist(
64+
unauthorized.address,
65+
)
66+
await expect(tx).revertedWith('Caller must be Controller governor')
67+
})
68+
69+
it('removeFromCallhookWhitelist should revert', async function () {
70+
const tx = L1GraphTokenGateway.connect(unauthorized).removeFromCallhookWhitelist(
71+
unauthorized.address,
72+
)
73+
await expect(tx).revertedWith('Caller must be Controller governor')
74+
})
75+
76+
it('finalizeInboundTransfer should revert', async function () {
77+
const tx = L1GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer(
78+
unauthorized.address,
79+
unauthorized.address,
80+
unauthorized.address,
81+
'100',
82+
'0x00',
83+
)
84+
85+
await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY')
86+
})
87+
})
1988
})

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

Lines changed: 0 additions & 87 deletions
This file was deleted.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
2+
import { expect } from 'chai'
3+
import hre from 'hardhat'
4+
import { chainIdIsL2 } from '../../../../cli/utils'
5+
6+
describe('[L2] L2GraphToken', () => {
7+
const {
8+
contracts: { L2GraphToken },
9+
getTestAccounts,
10+
} = hre.graph()
11+
12+
let unauthorized: SignerWithAddress
13+
14+
before(async function () {
15+
const chainId = (await hre.ethers.provider.getNetwork()).chainId
16+
if (!chainIdIsL2(chainId)) this.skip()
17+
18+
unauthorized = (await getTestAccounts())[0]
19+
})
20+
21+
describe('calls with unauthorized user', () => {
22+
it('mint should revert', async function () {
23+
const tx = L2GraphToken.connect(unauthorized).mint(
24+
unauthorized.address,
25+
'1000000000000000000000',
26+
)
27+
await expect(tx).revertedWith('Only minter can call')
28+
})
29+
30+
it('bridgeMint should revert', async function () {
31+
const tx = L2GraphToken.connect(unauthorized).bridgeMint(
32+
unauthorized.address,
33+
'1000000000000000000000',
34+
)
35+
await expect(tx).revertedWith('NOT_GATEWAY')
36+
})
37+
38+
it('setGateway should revert', async function () {
39+
const tx = L2GraphToken.connect(unauthorized).setGateway(unauthorized.address)
40+
await expect(tx).revertedWith('Only Governor can call')
41+
})
42+
})
43+
})
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,66 @@
1+
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
12
import { expect } from 'chai'
23
import hre from 'hardhat'
34
import { chainIdIsL2 } from '../../../../cli/utils'
45

56
describe('[L2] L2GraphTokenGateway configuration', () => {
67
const {
78
contracts: { Controller, L2GraphTokenGateway },
9+
getTestAccounts,
810
} = hre.graph()
911

12+
let unauthorized: SignerWithAddress
13+
1014
before(async function () {
1115
const chainId = (await hre.ethers.provider.getNetwork()).chainId
1216
if (!chainIdIsL2(chainId)) this.skip()
17+
18+
unauthorized = (await getTestAccounts())[0]
19+
})
20+
21+
it('bridge should be unpaused', async function () {
22+
const paused = await L2GraphTokenGateway.paused()
23+
expect(paused).eq(false)
1324
})
1425

1526
it('should be controlled by Controller', async function () {
1627
const controller = await L2GraphTokenGateway.controller()
1728
expect(controller).eq(Controller.address)
1829
})
30+
31+
describe('calls with unauthorized user', () => {
32+
it('initialize should revert', async function () {
33+
const tx = L2GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
34+
await expect(tx).revertedWith('Caller must be the implementation')
35+
})
36+
37+
it('setL2Router should revert', async function () {
38+
const tx = L2GraphTokenGateway.connect(unauthorized).setL2Router(unauthorized.address)
39+
await expect(tx).revertedWith('Caller must be Controller governor')
40+
})
41+
42+
it('setL1TokenAddress should revert', async function () {
43+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1TokenAddress(unauthorized.address)
44+
await expect(tx).revertedWith('Caller must be Controller governor')
45+
})
46+
47+
it('setL1CounterpartAddress should revert', async function () {
48+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1CounterpartAddress(
49+
unauthorized.address,
50+
)
51+
await expect(tx).revertedWith('Caller must be Controller governor')
52+
})
53+
54+
it('finalizeInboundTransfer should revert', async function () {
55+
const tx = L2GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer(
56+
unauthorized.address,
57+
unauthorized.address,
58+
unauthorized.address,
59+
'1000000000000',
60+
'0x00',
61+
)
62+
63+
await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY')
64+
})
65+
})
1966
})

e2e/deployment/config/protocol.test.ts

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

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ const config: HardhatUserConfig = {
143143
hardfork: 'london',
144144
},
145145
localhost: {
146+
chainId: 1337,
146147
accounts:
147148
process.env.FORK === 'true' ? getAccountsKeys() : { mnemonic: DEFAULT_TEST_MNEMONIC },
148149
},

tasks/deployment/accounts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { task } from 'hardhat/config'
33
import { cliOpts } from '../../cli/defaults'
44
import { updateItemValue, writeConfig } from '../../cli/config'
55

6-
task('migrate:accounts', '[localhost] Creates protocol accounts and saves them in graph config')
6+
task('migrate:accounts', 'Creates protocol accounts and saves them in graph config')
77
.addParam('graphConfig', cliOpts.graphConfig.description, cliOpts.graphConfig.default)
88
.setAction(async (taskArgs, hre) => {
99
const { graphConfig, getDeployer } = hre.graph({

tasks/deployment/unpause.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { task } from 'hardhat/config'
22
import { cliOpts } from '../../cli/defaults'
33
import { chainIdIsL2 } from '../../cli/utils'
44

5-
task('migrate:unpause', 'Unpause protocol')
5+
task('migrate:unpause', 'Unpause protocol and bridge')
66
.addParam('addressBook', cliOpts.addressBook.description, cliOpts.addressBook.default)
77
.addParam('graphConfig', cliOpts.graphConfig.description, cliOpts.graphConfig.default)
88
.setAction(async (taskArgs, hre) => {

tasks/e2e/e2e.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import { TASK_TEST, TASK_RUN } from 'hardhat/builtin-tasks/task-names'
44
import glob from 'glob'
55
import { cliOpts } from '../../cli/defaults'
66
import fs from 'fs'
7-
import path from 'path'
87

98
const CONFIG_TESTS = 'e2e/deployment/config/**/*.test.ts'
109
const INIT_TESTS = 'e2e/deployment/init/**/*.test.ts'
11-
const SCENARIOS = 'e2e/scenarios/*[!.test].ts'
1210

1311
// Built-in test & run tasks don't support our arguments
1412
// we can pass them to GRE via env vars
@@ -29,19 +27,6 @@ task('e2e', 'Run all e2e tests')
2927
await hre.run(TASK_TEST, {
3028
testFiles: testFiles,
3129
})
32-
33-
// Run scenarios one by one
34-
// we don't know how one scenario can affect tests from another one
35-
// const scenarios = new glob.GlobSync(SCENARIOS).found.map((s) =>
36-
// path.basename(s, path.extname(s)),
37-
// )
38-
// for (const scenario of scenarios) {
39-
// await hre.run('e2e:scenario', {
40-
// scenario: scenario,
41-
// graphConfig: args.graphConfig,
42-
// addressBook: args.addressBook,
43-
// })
44-
// }
4530
})
4631

4732
task('e2e:config', 'Run deployment configuration e2e tests')

tasks/gre.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
1212
// Graph Runtime Environment (GRE) extensions for the HRE
1313
extendEnvironment((hre: HardhatRuntimeEnvironment) => {
1414
hre.graph = (opts: GREOptions = {}) => {
15-
const chainId = hre.network.config.chainId?.toString() ?? '1337'
15+
const chainId = opts.chainId ?? hre.network.config.chainId?.toString() ?? '1337'
1616
const addressBookPath = opts.addressBook ?? process.env.ADDRESS_BOOK
1717
const graphConfigPath = opts.graphConfig ?? process.env.GRAPH_CONFIG
1818

tasks/type-extensions.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { NetworkContracts } from '../cli/contracts'
55
export interface GREOptions {
66
addressBook?: string
77
graphConfig?: string
8+
chainId?: string
89
}
910

1011
export interface NamedAccounts {

0 commit comments

Comments
 (0)