Skip to content

Commit ad96844

Browse files
committed
feat: add L2 bridge (unconfigured) e2e deployment tests
Signed-off-by: Tomás Migone <[email protected]>
1 parent a0cba8d commit ad96844

File tree

3 files changed

+106
-1
lines changed

3 files changed

+106
-1
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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] L2 bridge auth protection', () => {
7+
const {
8+
contracts: { L2GraphToken, L2GraphTokenGateway },
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('L2GraphToken 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+
44+
describe('L2GraphTokenGateway calls with unauthorized user', () => {
45+
it('initialize should revert', async function () {
46+
const tx = L2GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
47+
await expect(tx).revertedWith('Caller must be the implementation')
48+
})
49+
50+
it('setL2Router should revert', async function () {
51+
const tx = L2GraphTokenGateway.connect(unauthorized).setL2Router(unauthorized.address)
52+
await expect(tx).revertedWith('Caller must be Controller governor')
53+
})
54+
55+
it('setL1TokenAddress should revert', async function () {
56+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1TokenAddress(unauthorized.address)
57+
await expect(tx).revertedWith('Caller must be Controller governor')
58+
})
59+
60+
it('setL1CounterpartAddress should revert', async function () {
61+
const tx = L2GraphTokenGateway.connect(unauthorized).setL1CounterpartAddress(
62+
unauthorized.address,
63+
)
64+
await expect(tx).revertedWith('Caller must be Controller governor')
65+
})
66+
67+
it('outboundTransfer should revert', async function () {
68+
const tx = L2GraphTokenGateway.connect(unauthorized)[
69+
'outboundTransfer(address,address,uint256,uint256,uint256,bytes)'
70+
](L2GraphToken.address, unauthorized.address, '1000000000000', 0, 0, '0x00')
71+
72+
await expect(tx).revertedWith('TOKEN_NOT_GRT')
73+
})
74+
75+
it('finalizeInboundTransfer should revert', async function () {
76+
const tx = L2GraphTokenGateway.connect(unauthorized).finalizeInboundTransfer(
77+
unauthorized.address,
78+
unauthorized.address,
79+
unauthorized.address,
80+
'1000000000000',
81+
'0x00',
82+
)
83+
84+
await expect(tx).revertedWith('ONLY_COUNTERPART_GATEWAY')
85+
})
86+
})
87+
})
Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { expect } from 'chai'
22
import hre from 'hardhat'
3+
import { chainIdIsL2 } from '../../../cli/utils'
34

45
describe('Protocol configuration', () => {
56
const { contracts } = hre.graph()
67

7-
it('should be unpaused', async function () {
8+
it('protocol should be unpaused', async function () {
89
const paused = await contracts.Controller.paused()
910
expect(paused).eq(false)
1011
})
12+
13+
it('bridge should be unpaused', async function () {
14+
const chainId = (await hre.ethers.provider.getNetwork()).chainId
15+
const isL2 = chainIdIsL2(chainId)
16+
const GraphTokenGateway = isL2 ? contracts.L2GraphTokenGateway : contracts.L1GraphTokenGateway
17+
const paused = await GraphTokenGateway.paused()
18+
expect(paused).eq(false)
19+
})
1120
})

tasks/deployment/unpause.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { task } from 'hardhat/config'
22
import { cliOpts } from '../../cli/defaults'
3+
import { chainIdIsL2 } from '../../cli/utils'
34

45
task('migrate:unpause', 'Unpause protocol')
56
.addParam('addressBook', cliOpts.addressBook.description, cliOpts.addressBook.default)
@@ -14,5 +15,13 @@ task('migrate:unpause', 'Unpause protocol')
1415
console.log('> Unpausing protocol')
1516
const tx = await contracts.Controller.connect(governor).setPaused(false)
1617
await tx.wait()
18+
19+
console.log('> Unpausing bridge')
20+
const chainId = (await hre.ethers.provider.getNetwork()).chainId
21+
const isL2 = chainIdIsL2(chainId)
22+
const GraphTokenGateway = isL2 ? contracts.L2GraphTokenGateway : contracts.L1GraphTokenGateway
23+
const tx2 = await GraphTokenGateway.connect(governor).setPaused(false)
24+
await tx2.wait()
25+
1726
console.log('Done!')
1827
})

0 commit comments

Comments
 (0)