Skip to content

Commit 4a99df6

Browse files
tmigonepcarranzav
authored andcommitted
e2e: add bridge e2e tests (#720)
* feat(e2e): run L1 and L2 together in e2e tests Signed-off-by: Tomás Migone <[email protected]>
1 parent 449e12e commit 4a99df6

File tree

7 files changed

+119
-33
lines changed

7 files changed

+119
-33
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ coverage.json
2222

2323
# Local test files
2424
addresses-local.json
25+
localNetwork.json
2526
arbitrum-addresses-local.json
26-
localNetwork.json

e2e/deployment/config/l1/l1GraphTokenGateway.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { expect } from 'chai'
22
import hre from 'hardhat'
33
import GraphChain from '../../../../gre/helpers/network'
44
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
5+
import { getAddressBook } from '../../../../cli/address-book'
56

67
describe('[L1] L1GraphTokenGateway configuration', function () {
78
const graph = hre.graph()
@@ -23,6 +24,43 @@ describe('[L1] L1GraphTokenGateway configuration', function () {
2324
expect(controller).eq(Controller.address)
2425
})
2526

27+
it('l2GRT should match the L2 GraphToken deployed address', async function () {
28+
const l2GRT = await L1GraphTokenGateway.l2GRT()
29+
expect(l2GRT).eq(graph.l2.contracts.GraphToken.address)
30+
})
31+
32+
it('l2Counterpart should match the deployed L2 GraphTokenGateway address', async function () {
33+
const l2Counterpart = await L1GraphTokenGateway.l2Counterpart()
34+
expect(l2Counterpart).eq(graph.l2.contracts.L2GraphTokenGateway.address)
35+
})
36+
37+
it('escrow should match the deployed L1 BridgeEscrow address', async function () {
38+
const escrow = await L1GraphTokenGateway.escrow()
39+
expect(escrow).eq(graph.l1.contracts.BridgeEscrow.address)
40+
})
41+
42+
it("inbox should match Arbitrum's Inbox address", async function () {
43+
const inbox = await L1GraphTokenGateway.inbox()
44+
45+
// TODO: is there a cleaner way to get the router address?
46+
const arbitrumAddressBook = process.env.ARBITRUM_ADDRESS_BOOK ?? 'arbitrum-addresses-local.json'
47+
const arbAddressBook = getAddressBook(arbitrumAddressBook, graph.l1.chainId.toString())
48+
const arbIInbox = arbAddressBook.getEntry('IInbox')
49+
50+
expect(inbox.toLowerCase()).eq(arbIInbox.address.toLowerCase())
51+
})
52+
53+
it("l1Router should match Arbitrum's router address", async function () {
54+
const l1Router = await L1GraphTokenGateway.l1Router()
55+
56+
// TODO: is there a cleaner way to get the router address?
57+
const arbitrumAddressBook = process.env.ARBITRUM_ADDRESS_BOOK ?? 'arbitrum-addresses-local.json'
58+
const arbAddressBook = getAddressBook(arbitrumAddressBook, graph.l1.chainId.toString())
59+
const arbL2Router = arbAddressBook.getEntry('L1GatewayRouter')
60+
61+
expect(l1Router).eq(arbL2Router.address)
62+
})
63+
2664
describe('calls with unauthorized user', () => {
2765
it('initialize should revert', async function () {
2866
const tx = L1GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ describe('[L2] L2GraphToken', () => {
1414
unauthorized = (await graph.getTestAccounts())[0]
1515
})
1616

17+
it('l1Address should match the L1 GraphToken deployed address', async function () {
18+
const l1Address = await L2GraphToken.l1Address()
19+
expect(l1Address).eq(graph.l1.contracts.GraphToken.address)
20+
})
21+
22+
it('gateway should match the L2 GraphTokenGateway deployed address', async function () {
23+
const gateway = await L2GraphToken.gateway()
24+
expect(gateway).eq(graph.l2.contracts.L2GraphTokenGateway.address)
25+
})
26+
1727
describe('calls with unauthorized user', () => {
1828
it('mint should revert', async function () {
1929
const tx = L2GraphToken.connect(unauthorized).mint(

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers'
22
import { expect } from 'chai'
33
import hre from 'hardhat'
4+
import { getAddressBook } from '../../../../cli/address-book'
45
import GraphChain from '../../../../gre/helpers/network'
56

67
describe('[L2] L2GraphTokenGateway configuration', function () {
@@ -23,6 +24,27 @@ describe('[L2] L2GraphTokenGateway configuration', function () {
2324
expect(controller).eq(Controller.address)
2425
})
2526

27+
it('l1GRT should match the L1 GraphToken deployed address', async function () {
28+
const l1GRT = await L2GraphTokenGateway.l1GRT()
29+
expect(l1GRT).eq(graph.l1.contracts.GraphToken.address)
30+
})
31+
32+
it('l1Counterpart should match the deployed L1 GraphTokenGateway address', async function () {
33+
const l1Counterpart = await L2GraphTokenGateway.l1Counterpart()
34+
expect(l1Counterpart).eq(graph.l1.contracts.L1GraphTokenGateway.address)
35+
})
36+
37+
it("l2Router should match Arbitrum's router address", async function () {
38+
const l2Router = await L2GraphTokenGateway.l2Router()
39+
40+
// TODO: is there a cleaner way to get the router address?
41+
const arbitrumAddressBook = process.env.ARBITRUM_ADDRESS_BOOK ?? 'arbitrum-addresses-local.json'
42+
const arbAddressBook = getAddressBook(arbitrumAddressBook, graph.l2.chainId.toString())
43+
const arbL2Router = arbAddressBook.getEntry('L2GatewayRouter')
44+
45+
expect(l2Router).eq(arbL2Router.address)
46+
})
47+
2648
describe('calls with unauthorized user', () => {
2749
it('initialize should revert', async function () {
2850
const tx = L2GraphTokenGateway.connect(unauthorized).initialize(unauthorized.address)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { expect } from 'chai'
2+
import hre from 'hardhat'
3+
import GraphChain from '../../../../gre/helpers/network'
4+
5+
describe('BridgeEscrow initialization', () => {
6+
const graph = hre.graph()
7+
const { BridgeEscrow, GraphToken, L1GraphTokenGateway } = graph.contracts
8+
9+
before(async function () {
10+
if (GraphChain.isL2(graph.chainId)) this.skip()
11+
})
12+
13+
it("should allow L1GraphTokenGateway contract to spend MAX_UINT256 tokens on BridgeEscrow's behalf", async function () {
14+
const allowance = await GraphToken.allowance(BridgeEscrow.address, L1GraphTokenGateway.address)
15+
expect(allowance).eq(hre.ethers.constants.MaxUint256)
16+
})
17+
})

scripts/e2e

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -121,39 +121,40 @@ function configure_bridge () {
121121

122122
function test_e2e () {
123123
local NETWORK=$1
124-
local GRAPH_CONFIG=$2
125-
local ADDRESS_BOOK=$3
126-
local COUNTERPART_NETWORK=$4
124+
local L1_GRAPH_CONFIG=$2
125+
local L2_GRAPH_CONFIG=$3
126+
local ADDRESS_BOOK=$4
127+
local SKIP_BRIDGE_TESTS=$5
127128

128-
if [[ -n "$COUNTERPART_NETWORK" ]]; then
129-
npx hardhat e2e --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
129+
if [[ -z "$SKIP_BRIDGE_TESTS" ]]; then
130+
npx hardhat e2e --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
130131
else
131-
npx hardhat e2e --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --skip-bridge
132+
npx hardhat e2e --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK" --skip-bridge
132133
fi
133134
}
134135

135136
function test_e2e_scenarios () {
136137
local NETWORK=$1
137-
local GRAPH_CONFIG=$2
138-
local ADDRESS_BOOK=$3
138+
local L1_GRAPH_CONFIG=$2
139+
local L2_GRAPH_CONFIG=$3
140+
local ADDRESS_BOOK=$4
139141

140-
npx hardhat e2e:scenario create-subgraphs --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
141-
npx hardhat e2e:scenario open-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
142+
npx hardhat e2e:scenario create-subgraphs --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
143+
npx hardhat e2e:scenario open-allocations --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
142144

143145
# skip close-allocations for arbitrum testnodes as we can't advance epoch
144146
if [[ "$NETWORK" != *"localnitro"* ]]; then
145-
npx hardhat e2e:scenario close-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
147+
npx hardhat e2e:scenario close-allocations --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
146148
fi
147149
}
148150

149151
function test_e2e_scenarios_bridge () {
150-
local L1_NETWORK=$1
152+
local NETWORK=$1
151153
local L1_GRAPH_CONFIG=$2
152-
local L2_NETWORK=$3
153-
local L2_GRAPH_CONFIG=$4
154-
local ADDRESS_BOOK=$5
154+
local L2_GRAPH_CONFIG=$3
155+
local ADDRESS_BOOK=$4
155156

156-
npx hardhat e2e:scenario send-grt-to-l2 --network "$L1_NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
157+
npx hardhat e2e:scenario send-grt-to-l2 --network "$NETWORK" --l1-graph-config "$L1_GRAPH_CONFIG" --l2-graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
157158
}
158159

159160

@@ -200,28 +201,20 @@ if [[ -n "$L1_NETWORK" ]] && [[ -n "$L2_NETWORK" ]]; then
200201
configure_bridge "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK" "$ARBITRUM_ADDRESS_BOOK" "$ARBITRUM_DEPLOYMENT_FILE"
201202
fi
202203

203-
204204
## TEST
205205
# Run e2e tests
206-
if [[ -n "$L1_NETWORK" ]]; then
207-
test_e2e "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK" "$L2_NETWORK"
208-
fi
209-
210-
if [[ -n "$L2_NETWORK" ]]; then
211-
test_e2e "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK" "$L1_NETWORK"
206+
if [[ -z "$L2_NETWORK" ]]; then
207+
test_e2e "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK" true
208+
else
209+
test_e2e "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
210+
test_e2e "$L2_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
212211
fi
213212

214213
# Run scenario tests
215-
if [[ -n "$L1_NETWORK" ]]; then
216-
test_e2e_scenarios "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
217-
fi
218-
219-
if [[ -n "$L1_NETWORK" ]] && [[ -n "$L2_NETWORK" ]]; then
220-
test_e2e_scenarios_bridge "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
221-
fi
222-
214+
test_e2e_scenarios "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
223215
if [[ -n "$L2_NETWORK" ]]; then
224-
test_e2e_scenarios "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
216+
test_e2e_scenarios_bridge "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
217+
test_e2e_scenarios "$L2_NETWORK" "$L1_GRAPH_CONFIG" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
225218
fi
226219

227220
## Cleanup

tasks/e2e/e2e.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ const setGraphConfig = async (args: TaskArguments, hre: HardhatRuntimeEnvironmen
2929

3030
task('e2e', 'Run all e2e tests')
3131
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
32+
.addOptionalParam('l1GraphConfig', cliOpts.graphConfig.description)
33+
.addOptionalParam('l2GraphConfig', cliOpts.graphConfig.description)
3234
.addOptionalParam('addressBook', cliOpts.addressBook.description)
3335
.addFlag('skipBridge', 'Skip bridge tests')
3436
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
@@ -49,6 +51,8 @@ task('e2e', 'Run all e2e tests')
4951

5052
task('e2e:config', 'Run deployment configuration e2e tests')
5153
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
54+
.addOptionalParam('l1GraphConfig', cliOpts.graphConfig.description)
55+
.addOptionalParam('l2GraphConfig', cliOpts.graphConfig.description)
5256
.addOptionalParam('addressBook', cliOpts.addressBook.description)
5357
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
5458
const files = new glob.GlobSync(CONFIG_TESTS).found
@@ -60,6 +64,8 @@ task('e2e:config', 'Run deployment configuration e2e tests')
6064

6165
task('e2e:init', 'Run deployment initialization e2e tests')
6266
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
67+
.addOptionalParam('l1GraphConfig', cliOpts.graphConfig.description)
68+
.addOptionalParam('l2GraphConfig', cliOpts.graphConfig.description)
6369
.addOptionalParam('addressBook', cliOpts.addressBook.description)
6470
.setAction(async (args, hre: HardhatRuntimeEnvironment) => {
6571
const files = new glob.GlobSync(INIT_TESTS).found

0 commit comments

Comments
 (0)