@@ -2,7 +2,6 @@ package local
2
2
3
3
import (
4
4
"context"
5
- "fmt"
6
5
"os"
7
6
"path/filepath"
8
7
"time"
@@ -18,6 +17,7 @@ import (
18
17
"github.com/zeta-chain/zetacore/e2e/txserver"
19
18
"github.com/zeta-chain/zetacore/e2e/utils"
20
19
"github.com/zeta-chain/zetacore/pkg/chains"
20
+ "github.com/zeta-chain/zetacore/testutil"
21
21
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
22
22
)
23
23
42
42
TestTimeout = 15 * time .Minute
43
43
)
44
44
45
+ var noError = testutil .NoError
46
+
45
47
// NewLocalCmd returns the local command
46
48
// which runs the E2E tests locally on the machine with localnet for each blockchain
47
49
func NewLocalCmd () * cobra.Command {
@@ -70,58 +72,21 @@ func NewLocalCmd() *cobra.Command {
70
72
71
73
func localE2ETest (cmd * cobra.Command , _ []string ) {
72
74
// fetch flags
73
- waitForHeight , err := cmd .Flags ().GetInt64 (flagWaitForHeight )
74
- if err != nil {
75
- panic (err )
76
- }
77
- contractsDeployed , err := cmd .Flags ().GetBool (flagContractsDeployed )
78
- if err != nil {
79
- panic (err )
80
- }
81
- verbose , err := cmd .Flags ().GetBool (flagVerbose )
82
- if err != nil {
83
- panic (err )
84
- }
85
- configOut , err := cmd .Flags ().GetString (flagConfigOut )
86
- if err != nil {
87
- panic (err )
88
- }
89
- testAdmin , err := cmd .Flags ().GetBool (flagTestAdmin )
90
- if err != nil {
91
- panic (err )
92
- }
93
- testPerformance , err := cmd .Flags ().GetBool (flagTestPerformance )
94
- if err != nil {
95
- panic (err )
96
- }
97
- testCustom , err := cmd .Flags ().GetBool (flagTestCustom )
98
- if err != nil {
99
- panic (err )
100
- }
101
- skipRegular , err := cmd .Flags ().GetBool (flagSkipRegular )
102
- if err != nil {
103
- panic (err )
104
- }
105
- light , err := cmd .Flags ().GetBool (flagLight )
106
- if err != nil {
107
- panic (err )
108
- }
109
- setupOnly , err := cmd .Flags ().GetBool (flagSetupOnly )
110
- if err != nil {
111
- panic (err )
112
- }
113
- skipSetup , err := cmd .Flags ().GetBool (flagSkipSetup )
114
- if err != nil {
115
- panic (err )
116
- }
117
- skipBitcoinSetup , err := cmd .Flags ().GetBool (flagSkipBitcoinSetup )
118
- if err != nil {
119
- panic (err )
120
- }
121
- skipHeaderProof , err := cmd .Flags ().GetBool (flagSkipHeaderProof )
122
- if err != nil {
123
- panic (err )
124
- }
75
+ var (
76
+ waitForHeight = must (cmd .Flags ().GetInt64 (flagWaitForHeight ))
77
+ contractsDeployed = must (cmd .Flags ().GetBool (flagContractsDeployed ))
78
+ verbose = must (cmd .Flags ().GetBool (flagVerbose ))
79
+ configOut = must (cmd .Flags ().GetString (flagConfigOut ))
80
+ testAdmin = must (cmd .Flags ().GetBool (flagTestAdmin ))
81
+ testPerformance = must (cmd .Flags ().GetBool (flagTestPerformance ))
82
+ testCustom = must (cmd .Flags ().GetBool (flagTestCustom ))
83
+ skipRegular = must (cmd .Flags ().GetBool (flagSkipRegular ))
84
+ light = must (cmd .Flags ().GetBool (flagLight ))
85
+ setupOnly = must (cmd .Flags ().GetBool (flagSetupOnly ))
86
+ skipSetup = must (cmd .Flags ().GetBool (flagSkipSetup ))
87
+ skipBitcoinSetup = must (cmd .Flags ().GetBool (flagSkipBitcoinSetup ))
88
+ skipHeaderProof = must (cmd .Flags ().GetBool (flagSkipHeaderProof ))
89
+ )
125
90
126
91
logger := runner .NewLogger (verbose , color .FgWhite , "setup" )
127
92
@@ -146,16 +111,14 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
146
111
147
112
// initialize tests config
148
113
conf , err := GetConfig (cmd )
149
- if err != nil {
150
- panic (err )
151
- }
114
+ noError (err )
152
115
153
116
// initialize context
154
117
ctx , cancel := context .WithCancel (context .Background ())
155
118
156
119
// wait for a specific height on ZetaChain
157
120
if waitForHeight != 0 {
158
- utils .WaitForBlockHeight (ctx , waitForHeight , conf .RPCs .ZetaCoreRPC , logger )
121
+ noError ( utils .WaitForBlockHeight (ctx , waitForHeight , conf .RPCs .ZetaCoreRPC , logger ) )
159
122
}
160
123
161
124
// set account prefix to zeta
@@ -167,9 +130,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
167
130
[]string {UserFungibleAdminPrivateKey },
168
131
conf .ZetaChainID ,
169
132
)
170
- if err != nil {
171
- panic (fmt .Errorf ("failed to initialize ZetaChain tx server: %w" , err ))
172
- }
133
+ noError (err )
173
134
174
135
// initialize deployer runner with config
175
136
deployerRunner , err := zetae2econfig .RunnerFromConfig (
@@ -182,9 +143,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
182
143
logger ,
183
144
runner .WithZetaTxServer (zetaTxServer ),
184
145
)
185
- if err != nil {
186
- panic (err )
187
- }
146
+ noError (err )
188
147
189
148
// wait for keygen to be completed
190
149
// if setup is skipped, we assume that the keygen is already completed
@@ -193,16 +152,13 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
193
152
}
194
153
195
154
// query and set the TSS
196
- if err := deployerRunner .SetTSSAddresses (); err != nil {
197
- panic (err )
198
- }
155
+ noError (deployerRunner .SetTSSAddresses ())
199
156
200
157
if ! skipHeaderProof {
201
- if err := deployerRunner .EnableHeaderVerification ([]int64 {
158
+ noError ( deployerRunner .EnableHeaderVerification ([]int64 {
202
159
chains .GoerliLocalnet .ChainId ,
203
- chains .BitcoinRegtest .ChainId }); err != nil {
204
- panic (err )
205
- }
160
+ chains .BitcoinRegtest .ChainId ,
161
+ }))
206
162
}
207
163
208
164
// setting up the networks
@@ -212,30 +168,22 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
212
168
213
169
deployerRunner .SetupEVM (contractsDeployed , true )
214
170
deployerRunner .SetZEVMContracts ()
215
-
216
- // NOTE: this method return an error so we handle it and panic if it occurs unlike other method that panics directly
217
- // TODO: all methods should return errors instead of panicking and this current function should also return an error
218
- // https://github.com/zeta-chain/node/issues/1500
219
- if err := deployerRunner .FundEmissionsPool (); err != nil {
220
- panic (err )
221
- }
171
+ noError (deployerRunner .FundEmissionsPool ())
222
172
223
173
deployerRunner .MintERC20OnEvm (10000 )
224
174
225
175
logger .Print ("✅ setup completed in %s" , time .Since (startTime ))
226
176
}
177
+
227
178
// if a config output is specified, write the config
228
179
if configOut != "" {
229
180
newConfig := zetae2econfig .ExportContractsFromRunner (deployerRunner , conf )
230
- configOut , err := filepath .Abs (configOut )
231
- if err != nil {
232
- panic (err )
233
- }
234
181
235
182
// write config into stdout
236
- if err := config .WriteConfig (configOut , newConfig ); err != nil {
237
- panic (err )
238
- }
183
+ configOut , err := filepath .Abs (configOut )
184
+ noError (err )
185
+
186
+ noError (config .WriteConfig (configOut , newConfig ))
239
187
240
188
logger .Print ("✅ config file written in %s" , configOut )
241
189
}
@@ -407,3 +355,7 @@ func waitKeygenHeight(
407
355
logger .Info ("Last ZetaHeight: %d" , response .Height )
408
356
}
409
357
}
358
+
359
+ func must [T any ](v T , err error ) T {
360
+ return testutil .Must (v , err )
361
+ }
0 commit comments