Skip to content

Commit

Permalink
test(e2e): allow to run E2E tests on any networks (#1584)
Browse files Browse the repository at this point in the history
* add new logger functionality

* add eth withdraw tests

* logger event parsing

* simplify logs

* add account command

* add example config

* add cctx wait in deposit tests

* bitcoin config

* lint

* push back Ethereum tests

* update config example

* add report rendering

* goimport

* changelog

* fix balance calculation and remove accounting

* initialize bitcoin balance

* remove btc balance

* remove cmd/smoketest

* change deposit value

* some changes for btc

* goimport

* some tests for balances

* fix bitcoin balance code

* initialize bitcoin deposit test

* some fixes for bitcoin setup

* goimports

* some renaming

* start some work to support zeta out test on testnet

* goimports

* disable bitcoin balance

* add donation test

* add readme

* replace hardcoded address for zeta in and out

* fix erc20 deposit

* fix bitcoin deposit for testnet

* some renaming

* implement list tests command

* zeta withdraw

* goimport

* fix zeta withdraw

* fix TestZetaWithdrawBTCRevert

* add zeta deposit test

* reorganize tests

* add some more logs

* improve logger concurrency

* introduce stress tests

* some proposal tests

* add more proposal to test

* add bitcoin stress tests

* deposit stress tests

* btc deposit stress tests

* make generate

* remove legacy get TSS

* fix chain ID

* fix chain ID
  • Loading branch information
lumtis authored Feb 4, 2024
1 parent 7572fad commit 7d86651
Show file tree
Hide file tree
Showing 71 changed files with 2,261 additions and 1,522 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ contrib/meta.pem.pub
dispatch_payload.json
.github/workflows/local-testing.yml


# Hardhat files
cache
localnet/artifacts
Expand Down Expand Up @@ -53,4 +52,7 @@ contrib/localnet/blockscout/services/logs/*
contrib/localnet/blockscout/services/redis-data/*
contrib/localnet/blockscout/services/stats-db-data/*
contrib/localnet/grafana/addresses.txt
contrib/localnet/addresses.txt
contrib/localnet/addresses.txt

# Config for e2e tests
e2e_conf*
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ generate: proto openapi specs typescript docs-zetacored
###############################################################################

install-zetae2e: go.sum
@echo "--> Installing orchestrator"
@echo "--> Installing zetae2e"
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetae2e
.PHONY: install-zetae2e

Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@
* [1667](https://github.com/zeta-chain/node/issues/1667) - estimate SegWit tx size in uinit of vByte
* [1692](https://github.com/zeta-chain/node/pull/1692) - fix get params query for emissions module

### Tests

* [1584](https://github.com/zeta-chain/node/pull/1584) - allow to run E2E tests on any networks

## Version: v12.1.0

### Tests

* [1577](https://github.com/zeta-chain/node/pull/1577) - add chain header tests in E2E tests and fix admin tests

### Features
Expand Down
89 changes: 89 additions & 0 deletions cmd/zetae2e/balances.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package main

import (
"context"
"errors"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/utils"
)

const flagSkipBTC = "skip-btc"

// NewBalancesCmd returns the balances command
// which shows from the key and rpc, the balance of the account on different network
func NewBalancesCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "balances [config-file]",
Short: "Show account balances on networks for E2E tests",
RunE: runBalances,
Args: cobra.ExactArgs(1),
}
cmd.Flags().Bool(
flagSkipBTC,
false,
"skip the BTC network",
)
return cmd
}

func runBalances(cmd *cobra.Command, args []string) error {
// read the config file
conf, err := config.ReadConfig(args[0])
if err != nil {
return err
}

skipBTC, err := cmd.Flags().GetBool(flagSkipBTC)
if err != nil {
return err
}

// initialize logger
logger := runner.NewLogger(false, color.FgHiCyan, "")

// set config
app.SetConfig()

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

// get EVM address from config
evmAddr := conf.Accounts.EVMAddress
if !ethcommon.IsHexAddress(evmAddr) {
cancel()
return errors.New("invalid EVM address")
}

// initialize deployer runner with config
r, err := zetae2econfig.RunnerFromConfig(
ctx,
"e2e",
cancel,
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
cancel()
return err
}

balances, err := r.GetAccountBalances(skipBTC)
if err != nil {
cancel()
return err
}
r.PrintAccountBalances(balances)

return nil
}
92 changes: 92 additions & 0 deletions cmd/zetae2e/bitcoin_address.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package main

import (
"context"
"errors"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/fatih/color"
"github.com/spf13/cobra"
"github.com/zeta-chain/zetacore/app"
zetae2econfig "github.com/zeta-chain/zetacore/cmd/zetae2e/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/utils"
)

const flagPrivKey = "privkey"

// NewBitcoinAddressCmd returns the bitcoin address command
// which shows from the used config file, the bitcoin address that can be used to receive funds for the E2E tests
func NewBitcoinAddressCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bitcoin-address [config-file] ",
Short: "Show Bitcoin address to receive funds for E2E tests",
RunE: runBitcoinAddress,
Args: cobra.ExactArgs(1),
}
cmd.Flags().Bool(
flagPrivKey,
false,
"show the priv key in WIF format",
)
return cmd
}

func runBitcoinAddress(cmd *cobra.Command, args []string) error {
showPrivKey, err := cmd.Flags().GetBool(flagPrivKey)
if err != nil {
return err
}

// read the config file
conf, err := config.ReadConfig(args[0])
if err != nil {
return err
}

// initialize logger
logger := runner.NewLogger(false, color.FgHiYellow, "")

// set config
app.SetConfig()

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

// get EVM address from config
evmAddr := conf.Accounts.EVMAddress
if !ethcommon.IsHexAddress(evmAddr) {
cancel()
return errors.New("invalid EVM address")
}

// initialize deployer runner with config
r, err := zetae2econfig.RunnerFromConfig(
ctx,
"e2e",
cancel,
conf,
ethcommon.HexToAddress(evmAddr),
conf.Accounts.EVMPrivKey,
utils.FungibleAdminName, // placeholder value, not used
FungibleAdminMnemonic, // placeholder value, not used
logger,
)
if err != nil {
cancel()
return err
}

addr, privKey, err := r.GetBtcAddress()
if err != nil {
return err
}

logger.Print("* BTC address: %s", addr)
if showPrivKey {
logger.Print("* BTC privkey: %s", privKey)
}

return nil
}
35 changes: 24 additions & 11 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"fmt"

"google.golang.org/grpc"

Expand Down Expand Up @@ -33,19 +34,19 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st
) {
btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get btc client: %w", err)
}
goerliClient, goerliAuth, err := getEVMClient(ctx, conf.RPCs.EVM, evmPrivKey)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get evm client: %w", err)
}
cctxClient, fungibleClient, authClient, bankClient, observerClient, err := getZetaClients(conf.RPCs.ZetaCoreGRPC)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zeta clients: %w", err)
}
zevmClient, zevmAuth, err := getEVMClient(ctx, conf.RPCs.Zevm, evmPrivKey)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, err
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, fmt.Errorf("failed to get zevm client: %w", err)
}
return btcRPCClient,
goerliClient,
Expand All @@ -61,14 +62,26 @@ func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey st
}

// getBtcClient get btc client
func getBtcClient(rpc string) (*rpcclient.Client, error) {
func getBtcClient(rpcConf config.BitcoinRPC) (*rpcclient.Client, error) {
var param string
switch rpcConf.Params {
case config.Regnet:
case config.Testnet3:
param = "testnet3"
case config.Mainnet:
param = "mainnet"
default:
return nil, fmt.Errorf("invalid bitcoin params %s", rpcConf.Params)
}

connCfg := &rpcclient.ConnConfig{
Host: rpc,
User: "smoketest",
Pass: "123",
HTTPPostMode: true,
DisableTLS: true,
Params: "testnet3",
Host: rpcConf.Host,
User: rpcConf.User,
Pass: rpcConf.Pass,
HTTPPostMode: rpcConf.HTTPPostMode,
DisableTLS: rpcConf.DisableTLS,
Params: param,
//Endpoint: "/wallet/user",
}
return rpcclient.New(connCfg, nil)
}
Expand Down
15 changes: 13 additions & 2 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package config

import (
"context"
"fmt"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
Expand Down Expand Up @@ -34,7 +35,7 @@ func RunnerFromConfig(
zevmAuth,
err := getClientsFromConfig(ctx, conf, evmUserPrivKey)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get clients from config: %w", err)
}
// initialize client to send messages to ZetaChain
zetaTxServer, err := txserver.NewZetaTxServer(
Expand All @@ -44,7 +45,7 @@ func RunnerFromConfig(
conf.ZetaChainID,
)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to initialize ZetaChain tx server: %w", err)
}

// initialize smoke test runner
Expand All @@ -71,6 +72,16 @@ func RunnerFromConfig(

// set contracts
err = setContractsFromConfig(sm, conf)
if err != nil {
return nil, fmt.Errorf("failed to set contracts from config: %w", err)
}

// set bitcoin params
chainParams, err := conf.RPCs.Bitcoin.Params.GetParams()
if err != nil {
return nil, fmt.Errorf("failed to get bitcoin params: %w", err)
}
sm.BitcoinParams = &chainParams

return sm, err
}
Expand Down
22 changes: 22 additions & 0 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import (
"github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/erc20custody.sol"
zetaeth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zeta.eth.sol"
zetaconnectoreth "github.com/zeta-chain/protocol-contracts/pkg/contracts/evm/zetaconnector.eth.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/connectorzevm.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/systemcontract.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/wzeta.sol"
"github.com/zeta-chain/protocol-contracts/pkg/contracts/zevm/zrc20.sol"
"github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-core/contracts/uniswapv2factory.sol"
uniswapv2router "github.com/zeta-chain/protocol-contracts/pkg/uniswap/v2-periphery/contracts/uniswapv2router02.sol"
Expand Down Expand Up @@ -135,6 +137,26 @@ func setContractsFromConfig(r *runner.SmokeTestRunner, conf config.Config) error
return err
}
}
if c := conf.Contracts.ZEVM.ConnectorZEVMAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid ConnectorZEVMAddr: %s", c)
}
r.ConnectorZEVMAddr = ethcommon.HexToAddress(c)
r.ConnectorZEVM, err = connectorzevm.NewZetaConnectorZEVM(r.ConnectorZEVMAddr, r.ZevmClient)
if err != nil {
return err
}
}
if c := conf.Contracts.ZEVM.WZetaAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid WZetaAddr: %s", c)
}
r.WZetaAddr = ethcommon.HexToAddress(c)
r.WZeta, err = wzeta.NewWETH9(r.WZetaAddr, r.ZevmClient)
if err != nil {
return err
}
}
if c := conf.Contracts.ZEVM.ZEVMSwapAppAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid ZEVMSwapAppAddr: %s", c)
Expand Down
Loading

0 comments on commit 7d86651

Please sign in to comment.