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: add tx priority checks to e2e tests #2184

Merged
merged 23 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
### Tests

* [2047](https://github.com/zeta-chain/node/pull/2047) - fix liquidity cap advanced test
* [2184](https://github.com/zeta-chain/node/pull/2184) - add tx priority checks to e2e tests

### Fixes

Expand Down
15 changes: 15 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,23 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
eg.Go(miscTestRoutine(conf, deployerRunner, verbose, e2etests.TestMyTestName))
}

// while tests are executed, monitor blocks in parallel to check if system txs are on top and they have biggest priority
txPriorityErrCh := make(chan error, 1)
ctx, monitorPriorityCancel := context.WithCancel(context.Background())
go MonitorTxPriorityInBlocks(ctx, conf, txPriorityErrCh)

if err := eg.Wait(); err != nil {
deployerRunner.CtxCancel()
monitorPriorityCancel()
logger.Print("❌ %v", err)
logger.Print("❌ e2e tests failed after %s", time.Since(testStartTime).String())
os.Exit(1)
}

// if all tests pass, cancel txs priority monitoring and check if tx priority is not correct in some blocks
logger.Print("⏳ e2e tests passed, checking tx priority")
monitorPriorityCancel()
if err := <-txPriorityErrCh; err != nil {
logger.Print("❌ %v", err)
logger.Print("❌ e2e tests failed after %s", time.Since(testStartTime).String())
os.Exit(1)
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetae2e/local/performance.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func ethereumDepositPerformanceRoutine(
}

if err := r.RunE2ETests(tests); err != nil {
return fmt.Errorf("misc tests failed: %v", err)
return fmt.Errorf("ethereum deposit performance test failed: %v", err)
}

r.Logger.Print("🍾 Ethereum deposit performance test completed in %s", time.Since(startTime).String())
Expand Down Expand Up @@ -117,7 +117,7 @@ func ethereumWithdrawPerformanceRoutine(
}

if err := r.RunE2ETests(tests); err != nil {
return fmt.Errorf("misc tests failed: %v", err)
return fmt.Errorf("ethereum withdraw performance test failed: %v", err)
}

r.Logger.Print("🍾 Ethereum withdraw performance test completed in %s", time.Since(startTime).String())
Expand Down
52 changes: 52 additions & 0 deletions cmd/zetae2e/local/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package local

import (
"context"
"errors"
lumtis marked this conversation as resolved.
Show resolved Hide resolved
"strings"

"path/filepath"
"time"

rpchttp "github.com/cometbft/cometbft/rpc/client/http"
sdk "github.com/cosmos/cosmos-sdk/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -100,3 +103,52 @@ func waitKeygenHeight(
logger.Info("Last ZetaHeight: %d", response.Height)
}
}

func MonitorTxPriorityInBlocks(ctx context.Context, conf config.Config, errCh chan error) {
rpc, err := rpchttp.New(conf.RPCs.ZetaCoreRPC, "/websocket")
if err != nil {
errCh <- err
}

ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
for {
skosito marked this conversation as resolved.
Show resolved Hide resolved
select {
case <-ctx.Done():
errCh <- nil
case <-ticker.C:
block, err := rpc.Block(ctx, nil)
if err != nil {
errCh <- err
}

// iterate txs events and check if some MsgEthereumTx is included above crosschain and observer txs
nonSystemTxFound := false
for _, tx := range block.Block.Txs {
txRes, err := rpc.Tx(context.Background(), tx.Hash(), false)
skosito marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
continue
}

for _, ev := range txRes.TxResult.Events {
for _, attr := range ev.Attributes {
if attr.Key == "msg_type_url" {
if strings.Contains(attr.Value, "zetachain.zetacore.crosschain.MsgVote") ||
strings.Contains(attr.Value, "zetachain.zetacore.observer.MsgVote") ||
strings.Contains(attr.Value, "zetachain.zetacore.observer.MsgAddBlameVote") {
skosito marked this conversation as resolved.
Show resolved Hide resolved
if nonSystemTxFound {
skosito marked this conversation as resolved.
Show resolved Hide resolved
errCh <- errors.New("wrong tx priority, system tx not on top")
}
}
}
if attr.Key == "action" {
if strings.Contains(attr.Value, "ethermint.evm.v1.MsgEthereumTx") {
nonSystemTxFound = true
}
}
lumtis marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}
}
Loading