Skip to content

Commit

Permalink
refactor(smoke-test): smoke test general improvements: optimize exe…
Browse files Browse the repository at this point in the history
…cution, clean up outputs, introduce zetae2e CLI (#1438)

* create logger type

* replace printf with logger

* fix logger

* changelogs

* improve setup methods

* goimport

* fix multiple deposits

* some smoke tests optimizations

* some tests

* fix lint

* change deployer address

* simplify runner init

* use const for test names

* allow anther account to run smoke tests

* fix runner setup

* fix accounting

* erc20 tests in a go routine

* imports

* fix lint and fix concurrency

* improve logger

* goimport

* use errgroup and handle panic in routine

* add tests for zeta in routine

* add more info in panic logs

* add ethers and bitcoin tests

* comment out multiple deposit test

* lint issue

* gosec issue

* add logs on test completion

* fix Zeta test

* add output for lint

* replace panic with error for smoke test fail

* comment out some tests

* fix false positive

* fix test swap setup

* fix color

* make token sending parallel

* file for test types

* fix some tests

* add admin tests

* optimize test execution

* add flags for admin and custom test

* set back genesis time

* remove additional sleep

* fix bitcoin test

* remove commented code

* some tests in the CI

* set right values for btc timeout

* change core params

* add block header test

* goimport

* use context object

* add header check in smoke test beggining

* fix lint

* initialize zeta2e2 cli

* use zetae2e cli for tests

* add padding in logger

* test removing mount in dockerfile

* increase cctx timeout

* update workflow machine

* update option order

* fix typo

* test unifying docker compose command

* test new approach for logs

* initialize run command

* make generate

* revert workflow config

* run command

* fix gas limit

* add testnet test

* remove headers

* change some numbers

* simplify WaitCctxsMinedByInTxHash logic

* goimports

* bring back header check

* add custom timeout for cctx and receipts

* disable header test and increase timeout

* increase confirmation count

* increase tickers

* confirmation to 2

* accounting

* lint timeout
  • Loading branch information
lumtis authored Jan 2, 2024
1 parent 95e6b0b commit 6d6cc21
Show file tree
Hide file tree
Showing 84 changed files with 4,531 additions and 1,997 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ jobs:
run: rm -rf *

smoke-test:
runs-on: ["zeta-runners"] # 25 minutes
timeout-minutes: 35
runs-on: ["zeta-runners"]
timeout-minutes: 25
steps:
- uses: actions/checkout@v3

Expand All @@ -104,16 +104,19 @@ jobs:
skip_aws_cli: "true"
skip_docker_compose: "false"

- name: Login to Docker Hub
uses: docker/login-action@v2
if: github.event.repository.full_name == 'zetachain-chain/node'
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_READ_ONLY }}
# - name: Login to Docker Hub
# uses: docker/login-action@v2
# if: github.event.repository.full_name == 'zetachain-chain/node'
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_READ_ONLY }}

- name: Start Private Network
- name: Build zetanode
run: |
make zetanode
- name: Start Private Network
run: |
cd contrib/localnet/
docker compose up -d zetacore0 zetacore1 zetaclient0 zetaclient1 eth bitcoin
Expand All @@ -125,7 +128,6 @@ jobs:
echo "Smoke Test Failed"
exit 1
fi
sleep 10
- name: Stop Private Network
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sast-linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
with:
version: v1.54
skip-cache: true
args: --timeout=20m
args: --out-format=json

nosec_alert:
runs-on: ubuntu-latest
Expand Down
17 changes: 10 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,17 @@ RUN ssh-keygen -b 2048 -t rsa -f /root/.ssh/localtest.pem -q -N ""
WORKDIR /go/delivery/zeta-node
COPY go.mod .
COPY go.sum .
RUN --mount=type=cache,target=/root/.cache/go-build \
go mod download
#RUN --mount=type=cache,target=/root/.cache/go-build \
# go mod download
RUN go mod download
COPY . .

RUN --mount=type=cache,target=/root/.cache/go-build \
make install
RUN --mount=type=cache,target=/root/.cache/go-build \
make install-smoketest
#RUN --mount=type=cache,target=/root/.cache/go-build \
# make install
#RUN --mount=type=cache,target=/root/.cache/go-build \
# make install-zetae2e
RUN make install
RUN make install-zetae2e
#
#FROM golang:1.20-alpine

Expand All @@ -29,7 +32,7 @@ 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/zetae2e /usr/local/bin

COPY contrib/localnet/scripts /root
COPY contrib/localnet/preparams /root/preparams
Expand Down
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ build-testnet-ubuntu: go.sum

install: go.sum
@echo "--> Installing zetacored & zetaclientd"
@go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetacored
@go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetacored
@go install -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd

install-zetaclient: go.sum
@echo "--> Installing zetaclientd"
Expand All @@ -99,10 +99,6 @@ install-zetaclient-race-test-only-build: go.sum
@echo "--> Installing zetaclientd"
@go install -race -mod=readonly $(BUILD_FLAGS) ./cmd/zetaclientd

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

###############################################################################
### Local network ###
###############################################################################
Expand Down Expand Up @@ -182,10 +178,25 @@ mocks:
generate: proto openapi specs typescript docs-zetacored
.PHONY: generate

###############################################################################
### E2E tests ###
###############################################################################

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

###############################################################################
### Smoke tests ###
###############################################################################

# Note: smoke tests are deprecated and will be removed in the future, replaced with e2e tests

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

zetanode:
@echo "Building zetanode"
$(DOCKER) build -t zetanode -f ./Dockerfile .
Expand Down
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* Add pagination to queries which iterate over large data sets InTxTrackerAll ,PendingNoncesAll ,AllBlameRecord ,TssHistory
* GetTssAddress now returns only the current tss address for ETH and BTC
* Add a new query GetTssAddressesByFinalizedBlockHeight to get any other tss addresses for a finalized block height
* Add logger to smoke tests

### Chores

Expand Down
120 changes: 120 additions & 0 deletions cmd/zetae2e/config/clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package config

import (
"context"

"google.golang.org/grpc"

"github.com/btcsuite/btcd/rpcclient"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/zeta-chain/zetacore/contrib/localnet/orchestrator/smoketest/config"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"
observertypes "github.com/zeta-chain/zetacore/x/observer/types"
)

// getClientsFromConfig get clients from config
func getClientsFromConfig(ctx context.Context, conf config.Config, evmPrivKey string) (
*rpcclient.Client,
*ethclient.Client,
*bind.TransactOpts,
crosschaintypes.QueryClient,
fungibletypes.QueryClient,
authtypes.QueryClient,
banktypes.QueryClient,
observertypes.QueryClient,
*ethclient.Client,
*bind.TransactOpts,
error,
) {
btcRPCClient, err := getBtcClient(conf.RPCs.Bitcoin)
if err != nil {
return nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, 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
}
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
}
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 btcRPCClient,
goerliClient,
goerliAuth,
cctxClient,
fungibleClient,
authClient,
bankClient,
observerClient,
zevmClient,
zevmAuth,
nil
}

// getBtcClient get btc client
func getBtcClient(rpc string) (*rpcclient.Client, error) {
connCfg := &rpcclient.ConnConfig{
Host: rpc,
User: "smoketest",
Pass: "123",
HTTPPostMode: true,
DisableTLS: true,
Params: "testnet3",
}
return rpcclient.New(connCfg, nil)
}

// getEVMClient get goerli client
func getEVMClient(ctx context.Context, rpc, privKey string) (*ethclient.Client, *bind.TransactOpts, error) {
evmClient, err := ethclient.Dial(rpc)
if err != nil {
return nil, nil, err
}

chainid, err := evmClient.ChainID(ctx)
if err != nil {
return nil, nil, err
}
deployerPrivkey, err := crypto.HexToECDSA(privKey)
if err != nil {
return nil, nil, err
}
evmAuth, err := bind.NewKeyedTransactorWithChainID(deployerPrivkey, chainid)
if err != nil {
return nil, nil, err
}

return evmClient, evmAuth, nil
}

// getZetaClients get zeta clients
func getZetaClients(rpc string) (
crosschaintypes.QueryClient,
fungibletypes.QueryClient,
authtypes.QueryClient,
banktypes.QueryClient,
observertypes.QueryClient,
error,
) {
grpcConn, err := grpc.Dial(rpc, grpc.WithInsecure())
if err != nil {
return nil, nil, nil, nil, nil, err
}

cctxClient := crosschaintypes.NewQueryClient(grpcConn)
fungibleClient := fungibletypes.NewQueryClient(grpcConn)
authClient := authtypes.NewQueryClient(grpcConn)
bankClient := banktypes.NewQueryClient(grpcConn)
observerClient := observertypes.NewQueryClient(grpcConn)

return cctxClient, fungibleClient, authClient, bankClient, observerClient, nil
}
76 changes: 76 additions & 0 deletions cmd/zetae2e/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package config

import (
"context"

ethcommon "github.com/ethereum/go-ethereum/common"
"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/txserver"
)

// RunnerFromConfig create test runner from config
func RunnerFromConfig(
ctx context.Context,
name string,
ctxCancel context.CancelFunc,
conf config.Config,
evmUserAddr ethcommon.Address,
evmUserPrivKey string,
zetaUserName string,
zetaUserMnemonic string,
logger *runner.Logger,
) (*runner.SmokeTestRunner, error) {
// initialize clients
btcRPCClient,
goerliClient,
goerliAuth,
cctxClient,
fungibleClient,
authClient,
bankClient,
observerClient,
zevmClient,
zevmAuth,
err := getClientsFromConfig(ctx, conf, evmUserPrivKey)
if err != nil {
return nil, err
}
// initialize client to send messages to ZetaChain
zetaTxServer, err := txserver.NewZetaTxServer(
conf.RPCs.ZetaCoreRPC,
[]string{zetaUserName},
[]string{zetaUserMnemonic},
conf.ZetaChainID,
)
if err != nil {
return nil, err
}

// initialize smoke test runner
sm := runner.NewSmokeTestRunner(
ctx,
name,
ctxCancel,
evmUserAddr,
evmUserPrivKey,
zetaUserMnemonic,
goerliClient,
zevmClient,
cctxClient,
zetaTxServer,
fungibleClient,
authClient,
bankClient,
observerClient,
goerliAuth,
zevmAuth,
btcRPCClient,
logger,
)

// set contracts
err = setContractsFromConfig(sm, conf)

return sm, err
}
Loading

0 comments on commit 6d6cc21

Please sign in to comment.