Skip to content

Commit e6111eb

Browse files
authored
Merge branch 'develop' into refactor-integrate-base-observer
2 parents 0ee1e60 + 72dc5f0 commit e6111eb

File tree

80 files changed

+1831
-2980
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+1831
-2980
lines changed

changelog.md

+2
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,10 @@
6767
* [2299](https://github.com/zeta-chain/node/pull/2299) - add `zetae2e` command to deploy test contracts
6868
* [2360](https://github.com/zeta-chain/node/pull/2360) - add stateful e2e tests.
6969
* [2349](https://github.com/zeta-chain/node/pull/2349) - add TestBitcoinDepositRefund and WithdrawBitcoinMultipleTimes E2E tests
70+
* [2368](https://github.com/zeta-chain/node/pull/2368) - eliminate panic usage across testing suite
7071
* [2369](https://github.com/zeta-chain/node/pull/2369) - fix random cross-chain swap failure caused by using tiny UTXO
7172

73+
7274
### Fixes
7375

7476
* [1484](https://github.com/zeta-chain/node/issues/1484) - replaced hard-coded `MaxLookaheadNonce` with a default lookback factor

cmd/zetaclientd/gen_pre_params.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var GenPrePramsCmd = &cobra.Command{
1818
Use: "gen-pre-params <path>",
1919
Short: "Generate pre parameters for TSS",
2020
Args: cobra.ExactArgs(1),
21-
RunE: func(cmd *cobra.Command, args []string) error {
21+
RunE: func(_ *cobra.Command, args []string) error {
2222
startTime := time.Now()
2323
preParams, err := keygen.GeneratePreParams(time.Second * 300)
2424
if err != nil {

cmd/zetae2e/local/admin.go

-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"fmt"
5-
"runtime"
65
"time"
76

87
"github.com/fatih/color"
@@ -20,17 +19,6 @@ func adminTestRoutine(
2019
testNames ...string,
2120
) func() error {
2221
return func() (err error) {
23-
// return an error on panic
24-
// https://github.com/zeta-chain/node/issues/1500
25-
defer func() {
26-
if r := recover(); r != nil {
27-
// print stack trace
28-
stack := make([]byte, 4096)
29-
n := runtime.Stack(stack, false)
30-
err = fmt.Errorf("admin panic: %v, stack trace %s", r, stack[:n])
31-
}
32-
}()
33-
3422
// initialize runner for erc20 advanced test
3523
adminRunner, err := initTestRunner(
3624
"admin",

cmd/zetae2e/local/bitcoin.go

-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"fmt"
5-
"runtime"
65
"time"
76

87
"github.com/fatih/color"
@@ -22,18 +21,6 @@ func bitcoinTestRoutine(
2221
testNames ...string,
2322
) func() error {
2423
return func() (err error) {
25-
// return an error on panic
26-
// TODO: remove and instead return errors in the tests
27-
// https://github.com/zeta-chain/node/issues/1500
28-
defer func() {
29-
if r := recover(); r != nil {
30-
// print stack trace
31-
stack := make([]byte, 4096)
32-
n := runtime.Stack(stack, false)
33-
err = fmt.Errorf("bitcoin panic: %v, stack trace %s", r, stack[:n])
34-
}
35-
}()
36-
3724
// initialize runner for bitcoin test
3825
bitcoinRunner, err := initTestRunner(
3926
"bitcoin",

cmd/zetae2e/local/erc20.go

-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"fmt"
5-
"runtime"
65
"time"
76

87
"github.com/fatih/color"
@@ -20,18 +19,6 @@ func erc20TestRoutine(
2019
testNames ...string,
2120
) func() error {
2221
return func() (err error) {
23-
// return an error on panic
24-
// TODO: remove and instead return errors in the tests
25-
// https://github.com/zeta-chain/node/issues/1500
26-
defer func() {
27-
if r := recover(); r != nil {
28-
// print stack trace
29-
stack := make([]byte, 4096)
30-
n := runtime.Stack(stack, false)
31-
err = fmt.Errorf("erc20 panic: %v, stack trace %s", r, stack[:n])
32-
}
33-
}()
34-
3522
// initialize runner for erc20 test
3623
erc20Runner, err := initTestRunner(
3724
"erc20",

cmd/zetae2e/local/ethereum.go

-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"fmt"
5-
"runtime"
65
"time"
76

87
"github.com/fatih/color"
@@ -21,18 +20,6 @@ func ethereumTestRoutine(
2120
testNames ...string,
2221
) func() error {
2322
return func() (err error) {
24-
// return an error on panic
25-
// TODO: remove and instead return errors in the tests
26-
// https://github.com/zeta-chain/node/issues/1500
27-
defer func() {
28-
if r := recover(); r != nil {
29-
// print stack trace
30-
stack := make([]byte, 4096)
31-
n := runtime.Stack(stack, false)
32-
err = fmt.Errorf("ethereum panic: %v, stack trace %s", r, stack[:n])
33-
}
34-
}()
35-
3623
// initialize runner for ether test
3724
ethereumRunner, err := initTestRunner(
3825
"ether",

cmd/zetae2e/local/local.go

+36-84
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"context"
5-
"fmt"
65
"os"
76
"path/filepath"
87
"time"
@@ -18,6 +17,7 @@ import (
1817
"github.com/zeta-chain/zetacore/e2e/txserver"
1918
"github.com/zeta-chain/zetacore/e2e/utils"
2019
"github.com/zeta-chain/zetacore/pkg/chains"
20+
"github.com/zeta-chain/zetacore/testutil"
2121
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
2222
)
2323

@@ -42,6 +42,8 @@ var (
4242
TestTimeout = 15 * time.Minute
4343
)
4444

45+
var noError = testutil.NoError
46+
4547
// NewLocalCmd returns the local command
4648
// which runs the E2E tests locally on the machine with localnet for each blockchain
4749
func NewLocalCmd() *cobra.Command {
@@ -70,58 +72,21 @@ func NewLocalCmd() *cobra.Command {
7072

7173
func localE2ETest(cmd *cobra.Command, _ []string) {
7274
// 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+
)
12590

12691
logger := runner.NewLogger(verbose, color.FgWhite, "setup")
12792

@@ -146,16 +111,14 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
146111

147112
// initialize tests config
148113
conf, err := GetConfig(cmd)
149-
if err != nil {
150-
panic(err)
151-
}
114+
noError(err)
152115

153116
// initialize context
154117
ctx, cancel := context.WithCancel(context.Background())
155118

156119
// wait for a specific height on ZetaChain
157120
if waitForHeight != 0 {
158-
utils.WaitForBlockHeight(ctx, waitForHeight, conf.RPCs.ZetaCoreRPC, logger)
121+
noError(utils.WaitForBlockHeight(ctx, waitForHeight, conf.RPCs.ZetaCoreRPC, logger))
159122
}
160123

161124
// set account prefix to zeta
@@ -167,9 +130,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
167130
[]string{UserFungibleAdminPrivateKey},
168131
conf.ZetaChainID,
169132
)
170-
if err != nil {
171-
panic(fmt.Errorf("failed to initialize ZetaChain tx server: %w", err))
172-
}
133+
noError(err)
173134

174135
// initialize deployer runner with config
175136
deployerRunner, err := zetae2econfig.RunnerFromConfig(
@@ -182,9 +143,7 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
182143
logger,
183144
runner.WithZetaTxServer(zetaTxServer),
184145
)
185-
if err != nil {
186-
panic(err)
187-
}
146+
noError(err)
188147

189148
// wait for keygen to be completed
190149
// if setup is skipped, we assume that the keygen is already completed
@@ -193,16 +152,13 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
193152
}
194153

195154
// query and set the TSS
196-
if err := deployerRunner.SetTSSAddresses(); err != nil {
197-
panic(err)
198-
}
155+
noError(deployerRunner.SetTSSAddresses())
199156

200157
if !skipHeaderProof {
201-
if err := deployerRunner.EnableHeaderVerification([]int64{
158+
noError(deployerRunner.EnableHeaderVerification([]int64{
202159
chains.GoerliLocalnet.ChainId,
203-
chains.BitcoinRegtest.ChainId}); err != nil {
204-
panic(err)
205-
}
160+
chains.BitcoinRegtest.ChainId,
161+
}))
206162
}
207163

208164
// setting up the networks
@@ -212,30 +168,22 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
212168

213169
deployerRunner.SetupEVM(contractsDeployed, true)
214170
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())
222172

223173
deployerRunner.MintERC20OnEvm(10000)
224174

225175
logger.Print("✅ setup completed in %s", time.Since(startTime))
226176
}
177+
227178
// if a config output is specified, write the config
228179
if configOut != "" {
229180
newConfig := zetae2econfig.ExportContractsFromRunner(deployerRunner, conf)
230-
configOut, err := filepath.Abs(configOut)
231-
if err != nil {
232-
panic(err)
233-
}
234181

235182
// 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))
239187

240188
logger.Print("✅ config file written in %s", configOut)
241189
}
@@ -407,3 +355,7 @@ func waitKeygenHeight(
407355
logger.Info("Last ZetaHeight: %d", response.Height)
408356
}
409357
}
358+
359+
func must[T any](v T, err error) T {
360+
return testutil.Must(v, err)
361+
}

cmd/zetae2e/local/misc.go

-13
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package local
22

33
import (
44
"fmt"
5-
"runtime"
65
"time"
76

87
"github.com/fatih/color"
@@ -20,18 +19,6 @@ func miscTestRoutine(
2019
testNames ...string,
2120
) func() error {
2221
return func() (err error) {
23-
// return an error on panic
24-
// TODO: remove and instead return errors in the tests
25-
// https://github.com/zeta-chain/node/issues/1500
26-
defer func() {
27-
if r := recover(); r != nil {
28-
// print stack trace
29-
stack := make([]byte, 4096)
30-
n := runtime.Stack(stack, false)
31-
err = fmt.Errorf("misc panic: %v, stack trace %s", r, stack[:n])
32-
}
33-
}()
34-
3522
// initialize runner for misc test
3623
miscRunner, err := initTestRunner(
3724
"misc",

0 commit comments

Comments
 (0)