3
3
set -eo pipefail
4
4
source $( pwd) /scripts/evm
5
5
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
+
6
103
# Allow overriding config
7
- GRAPH_CONFIG= ${GRAPH_CONFIG :- " config/graph. localhost.yml " }
104
+ # By default run only L1 tests on localhost network
8
105
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" }
10
110
11
111
echo " Running e2e tests"
12
- echo " - Using config: $GRAPH_CONFIG "
13
112
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
15
133
16
- # ## Setup
17
134
# Compile contracts
18
135
yarn build
19
136
@@ -29,38 +146,35 @@ if [[ ! -f "$ADDRESS_BOOK" ]]; then
29
146
echo ' {}' > " $ADDRESS_BOOK "
30
147
fi
31
148
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 "
36
162
fi
37
163
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
45
168
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 "
49
169
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 "
53
174
54
175
# 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 "
64
178
65
179
# ## Cleanup
66
180
# Exit error mode so the evm instance always gets killed
0 commit comments