Skip to content

Commit 0e8c64f

Browse files
committed
feat: support for running e2e on nitro testnodes
Signed-off-by: Tomás Migone <[email protected]>
1 parent 3f6c55e commit 0e8c64f

File tree

6 files changed

+185
-50
lines changed

6 files changed

+185
-50
lines changed

cli/commands/protocol/configure-bridge.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,16 @@ export const configureL1Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
3232

3333
const l1Inbox = arbAddressBook.getEntry('IInbox')
3434
const l1Router = arbAddressBook.getEntry('L1GatewayRouter')
35-
logger.info(
36-
'L1 Inbox address: ' + l1Inbox.address + ' and L1 Router address: ' + l1Router.address,
37-
)
35+
36+
// There is no L1GatewayRouter on L1, use random address instead as setArbitrumAddresses will reject 0x0
37+
const l1RouterAddress =
38+
cli.chainId.toString() === '1337'
39+
? '0x000000000000000000000000000000000000dead'
40+
: l1Router.address
41+
logger.info('L1 Inbox address: ' + l1Inbox.address + ' and L1 Router address: ' + l1RouterAddress)
3842
await sendTransaction(cli.wallet, gateway, 'setArbitrumAddresses', [
3943
l1Inbox.address,
40-
l1Router.address,
44+
l1RouterAddress,
4145
])
4246
}
4347

@@ -64,9 +68,12 @@ export const configureL2Bridge = async (cli: CLIEnvironment, cliArgs: CLIArgs):
6468
logger.info('L1 Gateway address: ' + l1Counterpart.address)
6569
await sendTransaction(cli.wallet, gateway, 'setL1CounterpartAddress', [l1Counterpart.address])
6670

67-
const l2Router = arbAddressBook.getEntry('L2GatewayRouter')
68-
logger.info('L2 Router address: ' + l2Router.address)
69-
await sendTransaction(cli.wallet, gateway, 'setL2Router', [l2Router.address])
71+
// There is no L2GatewayRouter in localhost
72+
if (cli.chainId.toString() !== '412346') {
73+
const l2Router = arbAddressBook.getEntry('L2GatewayRouter')
74+
logger.info('L2 Router address: ' + l2Router.address)
75+
await sendTransaction(cli.wallet, gateway, 'setL2Router', [l2Router.address])
76+
}
7077

7178
logger.info('L2 Gateway address: ' + gateway.address)
7279
await sendTransaction(cli.wallet, token, 'setGateway', [gateway.address])

config/graph.arbitrum-localhost.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
general:
2-
arbitrator: &arbitrator "0xFFcf8FDEE72ac11b5c542428B35EEF5769C409f0" # Arbitration Council
3-
governor: &governor "0x22d491Bde2303f2f43325b2108D26f1eAbA1e32b" # Graph Council
4-
authority: &authority "0xE11BA2b4D45Eaed5996Cd0823791E0C93114882d" # Authority that signs payment vouchers
5-
availabilityOracle: &availabilityOracle "0xd03ea8624C8C5987235048901fB614fDcA89b117" # Subgraph Availability Oracle
6-
pauseGuardian: &pauseGuardian "0x95cED938F7991cd0dFcb48F0a06a40FA1aF46EBC" # Protocol pause guardian
7-
allocationExchangeOwner: &allocationExchangeOwner "0x3E5e9111Ae8eB78Fe1CC3bb8915d5D461F3Ef9A9" # Allocation Exchange owner
2+
arbitrator: &arbitrator "0x4237154FE0510FdE3575656B60c68a01B9dCDdF8" # Arbitration Council
3+
governor: &governor "0x1257227a2ECA34834940110f7B5e341A5143A2c4" # Graph Council
4+
authority: &authority "0x12B8D08b116E1E3cc29eE9Cf42bB0AA8129C3215" # Authority that signs payment vouchers
5+
availabilityOracle: &availabilityOracle "0x7694a48065f063a767a962610C6717c59F36b445" # Subgraph Availability Oracle
6+
pauseGuardian: &pauseGuardian "0x601060e0DC5349AA55EC73df5A58cB0FC1cD2e3C" # Protocol pause guardian
7+
allocationExchangeOwner: &allocationExchangeOwner "0xbD38F7b67a591A5cc7D642e1026E5095B819d952" # Allocation Exchange owner
88

99
contracts:
1010
Controller:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('[L1] L1GraphTokenGateway configuration', function () {
7777
'0x00',
7878
)
7979

80-
await expect(tx).revertedWith('INBOX_NOT_SET')
80+
await expect(tx).revertedWith('NOT_FROM_BRIDGE')
8181
})
8282
})
8383
})

hardhat.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ function setupNetworkProviders(hardhatConfig) {
101101
const DEFAULT_TEST_MNEMONIC =
102102
'myth like bonus scare over problem client lizard pioneer submit female collect'
103103

104+
const DEFAULT_L2_TEST_MNEMONIC =
105+
'urge never interest human any economy gentle canvas anxiety pave unlock find'
106+
104107
const config: HardhatUserConfig = {
105108
paths: {
106109
sources: './contracts',
@@ -160,7 +163,7 @@ const config: HardhatUserConfig = {
160163
localnitrol2: {
161164
chainId: 412346,
162165
url: 'http://localhost:8547',
163-
accounts: { mnemonic: DEFAULT_TEST_MNEMONIC },
166+
accounts: { mnemonic: DEFAULT_L2_TEST_MNEMONIC },
164167
},
165168
},
166169
graph: {

scripts/e2e

Lines changed: 145 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,134 @@
33
set -eo pipefail
44
source $(pwd)/scripts/evm
55

6+
function pre_deploy() {
7+
local NETWORK=$1
8+
local GRAPH_CONFIG=$2
9+
10+
# Create named accounts
11+
npx hardhat migrate:accounts --network "$NETWORK" --graph-config "$GRAPH_CONFIG"
12+
13+
# Fund accounts if using nitro test nodes
14+
if [[ "$NETWORK" == *"localnitro"* ]]; then
15+
npx hardhat migrate:accounts:nitro --network "$NETWORK" --graph-config "$GRAPH_CONFIG"
16+
fi
17+
}
18+
19+
function deploy() {
20+
local NETWORK=$1
21+
local GRAPH_CONFIG=$2
22+
local ADDRESS_BOOK=$3
23+
24+
# Deploy protocol
25+
npx hardhat migrate \
26+
--network "$NETWORK" \
27+
--skip-confirmation \
28+
--auto-mine \
29+
--force \
30+
--graph-config "$GRAPH_CONFIG" \
31+
--address-book "$ADDRESS_BOOK"
32+
}
33+
34+
function post_deploy () {
35+
local NETWORK=$1
36+
local GRAPH_CONFIG=$2
37+
local ADDRESS_BOOK=$3
38+
39+
# Governor to accept contracts ownership
40+
npx hardhat migrate:ownership --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
41+
42+
# Unpause the protocol
43+
npx hardhat migrate:unpause:protocol --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
44+
}
45+
46+
function configure_bridge () {
47+
local L1_NETWORK=$1
48+
local L1_GRAPH_CONFIG=$2
49+
local L2_NETWORK=$3
50+
local L2_GRAPH_CONFIG=$4
51+
local ADDRESS_BOOK=$5
52+
53+
# These settings are only used for CLI bridge commands
54+
# so we keep them here to avoid confusion with hardhat based tasks
55+
local L1_CHAIN_ID=${L1_CHAIN_ID:-"1337"}
56+
local L2_CHAIN_ID=${L2_CHAIN_ID:-"412346"}
57+
58+
local L1_RPC=${L1_RPC:-"http://localhost:8545"}
59+
local L2_RPC=${L2_RPC:-"http://localhost:8547"}
60+
61+
local L1_MNEMONIC=${L1_MNEMONIC:-"myth like bonus scare over problem client lizard pioneer submit female collect"}
62+
local L2_MNEMONIC=${L2_MNEMONIC:-"urge never interest human any economy gentle canvas anxiety pave unlock find"}
63+
64+
# Set L1Inbox address in arbitrum address book
65+
local L1_INBOX=$(docker exec $(docker ps -qf "name=nitro_geth") cat /config/deployment.json | jq -r '.inbox')
66+
jq -r '."1337" += { "IInbox" : { "address": "'"$L1_INBOX"'" } }' arbitrum-addresses.json > updated.json
67+
mv updated.json arbitrum-addresses.json
68+
69+
# Configure the bridge
70+
./cli/cli.ts -a "$ADDRESS_BOOK" -p "$L2_RPC" -m "$L2_MNEMONIC" -n 2 protocol configure-l2-bridge "$L1_CHAIN_ID"
71+
./cli/cli.ts -a "$ADDRESS_BOOK" -p "$L1_RPC" -m "$L1_MNEMONIC" -n 2 protocol configure-l1-bridge "$L2_CHAIN_ID"
72+
73+
# Unpause the bridge
74+
npx hardhat migrate:unpause:bridge --network "$L2_NETWORK" --graph-config "$L2_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
75+
npx hardhat migrate:unpause:bridge --network "$L1_NETWORK" --graph-config "$L1_GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
76+
}
77+
78+
function test_e2e () {
79+
local NETWORK=$1
80+
local GRAPH_CONFIG=$2
81+
local ADDRESS_BOOK=$3
82+
83+
npx hardhat e2e --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
84+
}
85+
86+
function test_e2e_scenarios () {
87+
local NETWORK=$1
88+
local GRAPH_CONFIG=$2
89+
local ADDRESS_BOOK=$3
90+
91+
# Skip GRT based scenarios as L2 doesnt have tokens yet...
92+
if [[ "$NETWORK" != "localnitrol2" ]]; then
93+
npx hardhat e2e:scenario create-subgraphs --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
94+
npx hardhat e2e:scenario open-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
95+
fi
96+
97+
# skip close-allocations for arbitrum testnodes as we can't advance epoch
98+
if [[ "$NETWORK" != *"localnitro"* ]]; then
99+
npx hardhat e2e:scenario close-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
100+
fi
101+
}
102+
6103
# Allow overriding config
7-
GRAPH_CONFIG=${GRAPH_CONFIG:-"config/graph.localhost.yml"}
104+
# By default run only L1 tests on localhost network
8105
ADDRESS_BOOK=${ADDRESS_BOOK:-"addresses.json"}
9-
NETWORK=${NETWORK:-"localhost"}
106+
L1_NETWORK=${L1_NETWORK:-"localhost"}
107+
L2_NETWORK=${L2_NETWORK}
108+
L1_GRAPH_CONFIG=${L1_GRAPH_CONFIG:-"config/graph.localhost.yml"}
109+
L2_GRAPH_CONFIG=${L2_GRAPH_CONFIG:-"config/graph.arbitrum-localhost.yml"}
10110

11111
echo "Running e2e tests"
12-
echo "- Using config: $GRAPH_CONFIG"
13112
echo "- Using address book: $ADDRESS_BOOK"
14-
echo "- Using network: $NETWORK"
113+
echo "- Using L1 network: $L1_NETWORK"
114+
echo "- Using L1 config: $L1_GRAPH_CONFIG"
115+
116+
if [[ -n "$L2_NETWORK" ]]; then
117+
echo "- Using L2 network: $L2_NETWORK"
118+
echo "- Using L2 config: $L2_GRAPH_CONFIG"
119+
else
120+
echo "- Skipping L2 tests"
121+
fi
122+
123+
### SETUP
124+
# Check binary dependencies before starting
125+
dependencies=( jq docker )
126+
for i in "${dependencies[@]}"
127+
do
128+
if ! command -v "$i" &> /dev/null; then
129+
echo "$i not found, please install and re run"
130+
exit
131+
fi
132+
done
15133

16-
### Setup
17134
# Compile contracts
18135
yarn build
19136

@@ -29,38 +146,35 @@ if [[ ! -f "$ADDRESS_BOOK" ]]; then
29146
echo '{}' > "$ADDRESS_BOOK"
30147
fi
31148

32-
# Pre-deploy actions
33-
npx hardhat migrate:accounts --network "$NETWORK" --graph-config "$GRAPH_CONFIG"
34-
if [[ "$NETWORK" == *"localnitro"* ]]; then
35-
npx hardhat migrate:accounts:nitro --network "$NETWORK" --graph-config "$GRAPH_CONFIG"
149+
### DEPLOY
150+
# Deploy L1
151+
echo "Deploying L1 protocol"
152+
pre_deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG"
153+
deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
154+
post_deploy "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
155+
156+
# Deploy L2
157+
if [[ -n "$L2_NETWORK" ]]; then
158+
echo "Deploying L2 protocol"
159+
pre_deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG"
160+
deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
161+
post_deploy "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
36162
fi
37163

38-
# Deploy protocol
39-
npx hardhat migrate \
40-
--network "$NETWORK" \
41-
--skip-confirmation \
42-
--auto-mine \
43-
--graph-config "$GRAPH_CONFIG" \
44-
--address-book "$ADDRESS_BOOK"
164+
# Configure bridge
165+
if [[ -n "$L2_NETWORK" ]]; then
166+
configure_bridge "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
167+
fi
45168

46-
# Post deploy actions
47-
npx hardhat migrate:ownership --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
48-
npx hardhat migrate:unpause --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
49169

50-
### Test
51-
# Run tests
52-
npx hardhat e2e --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
170+
### TEST
171+
# Run e2e tests
172+
test_e2e "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
173+
test_e2e "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
53174

54175
# Skip GRT scenarios in L2 as we don't have bridged GRT yet
55-
if [[ "$NETWORK" != "localnitrol2" ]]; then
56-
npx hardhat e2e:scenario create-subgraphs --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
57-
npx hardhat e2e:scenario open-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
58-
fi
59-
60-
# skip close-allocations for arbitrum testnodes as we can't advance epoch
61-
if [[ "$NETWORK" != *"localnitro"* ]]; then
62-
npx hardhat e2e:scenario close-allocations --network "$NETWORK" --graph-config "$GRAPH_CONFIG" --address-book "$ADDRESS_BOOK"
63-
fi
176+
test_e2e_scenarios "$L1_NETWORK" "$L1_GRAPH_CONFIG" "$ADDRESS_BOOK"
177+
test_e2e_scenarios "$L2_NETWORK" "$L2_GRAPH_CONFIG" "$ADDRESS_BOOK"
64178

65179
### Cleanup
66180
# Exit error mode so the evm instance always gets killed

tasks/deployment/unpause.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,35 @@ import { task } from 'hardhat/config'
22
import { cliOpts } from '../../cli/defaults'
33
import GraphChain from '../../gre/helpers/network'
44

5-
task('migrate:unpause', 'Unpause protocol and bridge')
5+
task('migrate:unpause:protocol', 'Unpause protocol')
66
.addOptionalParam('addressBook', cliOpts.addressBook.description)
77
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
88
.setAction(async (taskArgs, hre) => {
99
const graph = hre.graph(taskArgs)
1010
const { governor } = await graph.getNamedAccounts()
11-
const { Controller, L1GraphTokenGateway, L2GraphTokenGateway } = graph.contracts
11+
const { Controller } = graph.contracts
1212

1313
console.log('> Unpausing protocol')
1414
const tx = await Controller.connect(governor).setPaused(false)
1515
await tx.wait()
1616

17+
console.log('Done!')
18+
})
19+
20+
task('migrate:unpause:bridge', 'Unpause bridge')
21+
.addOptionalParam('addressBook', cliOpts.addressBook.description)
22+
.addOptionalParam('graphConfig', cliOpts.graphConfig.description)
23+
.setAction(async (taskArgs, hre) => {
24+
const graph = hre.graph(taskArgs)
25+
const { governor } = await graph.getNamedAccounts()
26+
const { L1GraphTokenGateway, L2GraphTokenGateway } = graph.contracts
27+
1728
console.log('> Unpausing bridge')
1829
const GraphTokenGateway = GraphChain.isL2(graph.chainId)
1930
? L2GraphTokenGateway
2031
: L1GraphTokenGateway
21-
const tx2 = await GraphTokenGateway.connect(governor).setPaused(false)
22-
await tx2.wait()
32+
const tx = await GraphTokenGateway.connect(governor).setPaused(false)
33+
await tx.wait()
2334

2435
console.log('Done!')
2536
})

0 commit comments

Comments
 (0)