Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): improve stateful e2e testing #1538

Merged
merged 18 commits into from
Jan 10, 2024
Merged
5 changes: 1 addition & 4 deletions Dockerfile-versioned
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine
FROM golang:1.20-alpine3.18

ENV GOPATH /go
ENV GOOS=linux
Expand Down Expand Up @@ -38,10 +38,7 @@ RUN cp $GOPATH/bin/smoketest $GOPATH/bin/old/
RUN git clone https://github.com/zeta-chain/cosmos-sdk.git
RUN cd cosmos-sdk && git checkout zetavisor-v0.1.5
RUN cd cosmos-sdk/cosmovisor && make zetavisor
#
#FROM golang:1.19-alpine

#RUN apk --no-cache add openssh jq tmux vim curl bash
RUN ssh-keygen -A
WORKDIR /root

Expand Down
23 changes: 8 additions & 15 deletions Dockerfile-versioned-source
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19-alpine
FROM golang:1.20-alpine3.18

ENV GOPATH /go
ENV GOOS=linux
Expand All @@ -9,51 +9,44 @@ ARG old_version
RUN apk --no-cache add git make build-base jq openssh libusb-dev linux-headers bash curl tmux
RUN ssh-keygen -b 2048 -t rsa -f /root/.ssh/localtest.pem -q -N ""

# Build cosmovisor
RUN go install cosmossdk.io/tools/cosmovisor/cmd/[email protected]

WORKDIR /go/delivery/zeta-node

RUN mkdir -p $GOPATH/bin/old
RUN mkdir -p $GOPATH/bin/new

ENV NEW_VERSION=v42.0.0
ENV NEW_VERSION=v12.0.0

# Build new release from the current source
COPY go.mod /go/delivery/zeta-node/
COPY go.sum /go/delivery/zeta-node/
RUN cd /go/delivery/zeta-node/ && go mod download
COPY . /go/delivery/zeta-node/
RUN cd /go/delivery/zeta-node/ && make install
RUN cd /go/delivery/zeta-node/ && make install-smoketest
RUN cd /go/delivery/zeta-node/ && make install-zetae2e
RUN cp $GOPATH/bin/zetacored $GOPATH/bin/new/
RUN cp $GOPATH/bin/zetaclientd $GOPATH/bin/new/
RUN cp $GOPATH/bin/smoketest $GOPATH/bin/new/

# Checkout and build old binary
RUN git clone https://github.com/zeta-chain/node.git
RUN cd node && git fetch

RUN cd node && git checkout ${old_version}
RUN cd node && make install
RUN cd node && make install-smoketest
RUN cp $GOPATH/bin/zetacored $GOPATH/bin/old/
RUN cp $GOPATH/bin/zetaclientd $GOPATH/bin/old/
RUN cp $GOPATH/bin/smoketest $GOPATH/bin/old/

RUN git clone https://github.com/zeta-chain/cosmos-sdk.git
RUN cd cosmos-sdk && git checkout zetavisor-v0.1.5
RUN cd cosmos-sdk/cosmovisor && make zetavisor
#
#FROM golang:1.19-alpine

#RUN apk --no-cache add openssh jq tmux vim curl bash
RUN ssh-keygen -A
WORKDIR /root

RUN cp /root/.ssh/localtest.pem.pub /root/.ssh/authorized_keys

RUN cp /go/bin/zetaclientd /usr/local/bin
RUN cp /go/bin/zetacored /usr/local/bin
RUN cp /go/bin/smoketest /usr/local/bin
RUN cp /go/bin/zetavisor /usr/local/bin
RUN cp /go/bin/zetae2e /usr/local/bin
RUN cp /go/bin/cosmovisor /usr/local/bin

COPY contrib/localnet/scripts /root
COPY contrib/localnet/preparams /root/preparams
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ stateful-upgrade:

stateful-upgrade-source:
@echo "--> Starting stateful smoketest"
$(DOCKER) build --build-arg old_version=v10.1.7 -t zetanode -f ./Dockerfile-versioned-source .
$(DOCKER) build --build-arg old_version=v11.0.0-patch-core-params -t zetanode -f ./Dockerfile-versioned-source .
$(DOCKER) build -t orchestrator -f contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild .
cd contrib/localnet/ && $(DOCKER) compose -f docker-compose-stateful.yml up -d

Expand Down
2 changes: 1 addition & 1 deletion app/setup_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

const releaseVersion = "v11.0.0"
const releaseVersion = "v12.0.0"

func SetupHandlers(app *App) {
app.UpgradeKeeper.SetUpgradeHandler(releaseVersion, func(ctx sdk.Context, plan types.Plan, vm module.VersionMap) (module.VersionMap, error) {
Expand Down
2 changes: 2 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@

### Tests

* [1538](https://github.com/zeta-chain/node/pull/1538) - improve stateful e2e testing

### CI
* Removed private runners and unused GitHub Action

Expand Down
6 changes: 3 additions & 3 deletions cmd/zetaclientd/start_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ func validatePeer(seedPeer string) error {
parsedPeer := strings.Split(seedPeer, "/")

if len(parsedPeer) < 7 {
return errors.New("seed peer missing IP or ID")
return errors.New("seed peer missing IP or ID or both, seed: " + seedPeer)
}

seedIP := parsedPeer[2]
seedID := parsedPeer[6]

if net.ParseIP(seedIP) == nil {
return errors.New("invalid seed IP address")
return errors.New("invalid seed IP address format, seed: " + seedPeer)
}

if len(seedID) == 0 {
return errors.New("seed id is empty")
return errors.New("seed id is empty, seed: " + seedPeer)
}

return nil
Expand Down
21 changes: 21 additions & 0 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,24 @@ func RunnerFromConfig(

return sm, err
}

// ExportContractsFromRunner export contracts from the runner to config using a source config
func ExportContractsFromRunner(sm *runner.SmokeTestRunner, conf config.Config) config.Config {
// copy contracts from deployer runner
conf.Contracts.EVM.ZetaEthAddress = sm.ZetaEthAddr.Hex()
conf.Contracts.EVM.ConnectorEthAddr = sm.ConnectorEthAddr.Hex()
conf.Contracts.EVM.CustodyAddr = sm.ERC20CustodyAddr.Hex()
conf.Contracts.EVM.USDT = sm.USDTERC20Addr.Hex()

conf.Contracts.ZEVM.SystemContractAddr = sm.SystemContractAddr.Hex()
conf.Contracts.ZEVM.ETHZRC20Addr = sm.ETHZRC20Addr.Hex()
conf.Contracts.ZEVM.USDTZRC20Addr = sm.USDTZRC20Addr.Hex()
conf.Contracts.ZEVM.BTCZRC20Addr = sm.BTCZRC20Addr.Hex()
conf.Contracts.ZEVM.UniswapFactoryAddr = sm.UniswapV2FactoryAddr.Hex()
conf.Contracts.ZEVM.UniswapRouterAddr = sm.UniswapV2RouterAddr.Hex()
conf.Contracts.ZEVM.ZEVMSwapAppAddr = sm.ZEVMSwapAppAddr.Hex()
conf.Contracts.ZEVM.ContextAppAddr = sm.ContextAppAddr.Hex()
conf.Contracts.ZEVM.TestDappAddr = sm.TestDAppAddr.Hex()

return conf
}
28 changes: 28 additions & 0 deletions cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import (
"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"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/contracts/contextapp"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/contracts/erc20"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/contracts/zevmswap"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/runner"
)

Expand Down Expand Up @@ -133,6 +135,32 @@ func setContractsFromConfig(r *runner.SmokeTestRunner, conf config.Config) error
return err
}
}
if c := conf.Contracts.ZEVM.ZEVMSwapAppAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid ZEVMSwapAppAddr: %s", c)
}
r.ZEVMSwapAppAddr = ethcommon.HexToAddress(c)
r.ZEVMSwapApp, err = zevmswap.NewZEVMSwapApp(r.ZEVMSwapAppAddr, r.ZevmClient)
if err != nil {
return err
}
}
if c := conf.Contracts.ZEVM.ContextAppAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid ContextAppAddr: %s", c)
}
r.ContextAppAddr = ethcommon.HexToAddress(c)
r.ContextApp, err = contextapp.NewContextApp(r.ContextAppAddr, r.ZevmClient)
if err != nil {
return err
}
}
if c := conf.Contracts.ZEVM.TestDappAddr; c != "" {
if !ethcommon.IsHexAddress(c) {
return fmt.Errorf("invalid TestDappAddr: %s", c)
}
r.TestDAppAddr = ethcommon.HexToAddress(c)
}

return nil
}
83 changes: 73 additions & 10 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package local
import (
"context"
"os"
"path/filepath"
"time"

"github.com/fatih/color"
"github.com/spf13/cobra"
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"
"golang.org/x/sync/errgroup"
Expand All @@ -21,6 +23,9 @@ const (
flagTestAdmin = "test-admin"
flagTestCustom = "test-custom"
flagSkipRegular = "skip-regular"
flagSetupOnly = "setup-only"
flagConfigOut = "config-out"
flagSkipSetup = "skip-setup"
)

var (
Expand Down Expand Up @@ -70,6 +75,21 @@ func NewLocalCmd() *cobra.Command {
false,
"set to true to skip regular tests",
)
cmd.Flags().Bool(
flagSetupOnly,
false,
"set to true to only setup the networks",
)
cmd.Flags().String(
flagConfigOut,
"",
"config file to write the deployed contracts from the setup",
)
cmd.Flags().Bool(
flagSkipSetup,
false,
"set to true to skip setup",
)

return cmd
}
Expand Down Expand Up @@ -101,6 +121,18 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if err != nil {
panic(err)
}
setupOnly, err := cmd.Flags().GetBool(flagSetupOnly)
if err != nil {
panic(err)
}
configOut, err := cmd.Flags().GetString(flagConfigOut)
if err != nil {
panic(err)
}
skipSetup, err := cmd.Flags().GetBool(flagSkipSetup)
if err != nil {
panic(err)
}

testStartTime := time.Now()
logger.Print("starting tests")
Expand Down Expand Up @@ -130,8 +162,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
setCosmosConfig()

// wait for Genesis
logger.Print("⏳ wait 70s for genesis")
time.Sleep(70 * time.Second)
// if setup is skipp, we assume that the genesis is already created
if !skipSetup {
logger.Print("⏳ wait 70s for genesis")
time.Sleep(70 * time.Second)
}

// initialize deployer runner with config
deployerRunner, err := zetae2econfig.RunnerFromConfig(
Expand All @@ -150,17 +185,45 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
}

// wait for keygen to be completed
waitKeygenHeight(ctx, deployerRunner.CctxClient, logger)
// if setup is skipped, we assume that the keygen is already completed
if !skipSetup {
waitKeygenHeight(ctx, deployerRunner.CctxClient, logger)
}

// query and set the TSS
deployerRunner.SetTSSAddresses()

// setting up the networks
logger.Print("⚙️ setting up networks")
startTime := time.Now()
if !skipSetup {
logger.Print("⚙️ setting up networks")
startTime := time.Now()
deployerRunner.SetupEVM(contractsDeployed)
deployerRunner.SetZEVMContracts()
deployerRunner.MintUSDTOnEvm(10000)
logger.Print("✅ setup completed in %s", time.Since(startTime))
deployerRunner.PrintContractAddresses()
}

deployerRunner.SetTSSAddresses()
deployerRunner.SetupEVM(contractsDeployed)
deployerRunner.SetZEVMContracts()
deployerRunner.MintUSDTOnEvm(10000)
logger.Print("✅ setup completed in %s", time.Since(startTime))
// if a config output is specified, write the config
if configOut != "" {
newConfig := zetae2econfig.ExportContractsFromRunner(deployerRunner, conf)
configOut, err := filepath.Abs(configOut)
if err != nil {
panic(err)
}

// write config into stdout
if err := config.WriteConfig(configOut, newConfig); err != nil {
panic(err)
}

logger.Print("✅ config file written in %s", configOut)
}

// if setup only, quit
if setupOnly {
os.Exit(0)
}

// run tests
var eg errgroup.Group
Expand Down
8 changes: 7 additions & 1 deletion cmd/zetae2e/local/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package local

import (
"context"
"path/filepath"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -27,6 +28,11 @@ func getConfig(cmd *cobra.Command) (config.Config, error) {
return config.DefaultConfig(), nil
}

configFile, err = filepath.Abs(configFile)
if err != nil {
return config.Config{}, err
}

return config.ReadConfig(configFile)
}

Expand Down Expand Up @@ -77,7 +83,7 @@ func waitKeygenHeight(
cctxClient crosschaintypes.QueryClient,
logger *runner.Logger,
) {
// wait for keygen to be completed. ~ height 30
// wait for keygen to be completed
keygenHeight := int64(60)
logger.Print("⏳ wait height %v for keygen to be completed", keygenHeight)
for {
Expand Down
1 change: 0 additions & 1 deletion contrib/localnet/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ networks:
config:
- subnet: 172.20.0.0/24


services:
rosetta:
image: zetanode:latest
Expand Down
6 changes: 2 additions & 4 deletions contrib/localnet/orchestrator/Dockerfile-upgrade.fastbuild
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ COPY contrib/localnet/orchestrator/start-upgrade.sh /work/
COPY contrib/localnet/orchestrator/restart-zetaclientd.sh /work/
RUN chmod +x /work/*.sh


COPY --from=zeta /go/bin/old/smoketest /usr/local/bin/smoketest-old
COPY --from=zeta /go/bin/new/smoketest /usr/local/bin/smoketest-new
RUN chmod +x /usr/local/bin/smoketest-*
COPY --from=zeta /usr/local/bin/zetae2e /usr/local/bin/
RUN chmod +x /usr/local/bin/zetae2e

WORKDIR /work
6 changes: 4 additions & 2 deletions contrib/localnet/orchestrator/restart-zetaclientd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ CURRENT_HEIGHT=0

while [[ $CURRENT_HEIGHT -lt $UPGRADE_HEIGHT ]]
do
CURRENT_HEIGHT=$(curl zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"')
CURRENT_HEIGHT=$(curl -s zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"')
echo current height is "$CURRENT_HEIGHT", waiting for "$UPGRADE_HEIGHT"
sleep 5
done

echo current height is "$CURRENT_HEIGHT", restarting zetaclients
echo upgrade height reached, restarting zetaclients

for NODE in "${CLIENT_LIST[@]}"; do
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem killall zetaclientd
ssh -o "StrictHostKeyChecking no" "$NODE" -i ~/.ssh/localtest.pem "$GOPATH/bin/new/zetaclientd start < /dev/null > $HOME/zetaclient.log 2>&1 &"
Expand Down
Loading
Loading