Skip to content

Commit

Permalink
test(e2e): improve E2E reliability for tests on live network (#3061)
Browse files Browse the repository at this point in the history
* test(e2e): reduce gas limit used for withdraw and call

* try 200k

* 250k

* use random string for payloads

* fix lint

* renaming

* allow test with no args

* fix lint
  • Loading branch information
lumtis authored Oct 30, 2024
1 parent 043e776 commit 6ef5c57
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 94 deletions.
20 changes: 11 additions & 9 deletions cmd/zetae2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,20 +155,22 @@ func runE2ETest(cmd *cobra.Command, args []string) error {

// parseCmdArgsToE2ETestRunConfig parses command-line arguments into a slice of E2ETestRunConfig structs.
func parseCmdArgsToE2ETestRunConfig(args []string) ([]runner.E2ETestRunConfig, error) {
tests := []runner.E2ETestRunConfig{}
tests := make([]runner.E2ETestRunConfig, 0, len(args))

for _, arg := range args {
parts := strings.SplitN(arg, ":", 2)
if len(parts) != 2 {
return nil, errors.New("command arguments should be in format: testName:testArgs")
}
if parts[0] == "" {
testName := parts[0]
if testName == "" {
return nil, errors.New("missing testName")
}
testName := parts[0]
testArgs := []string{}
if parts[1] != "" {
testArgs = strings.Split(parts[1], ",")

var testArgs []string
if len(parts) > 1 {
if parts[1] != "" {
testArgs = strings.Split(parts[1], ",")
}
}

tests = append(tests, runner.E2ETestRunConfig{
Name: testName,
Args: testArgs,
Expand Down
11 changes: 11 additions & 0 deletions e2e/e2etests/helpers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package e2etests

import (
"crypto/rand"
"encoding/hex"
"math/big"
"strconv"

Expand All @@ -20,6 +22,15 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

// randomPayload generates a random payload to be used in gateway calls for testing purposes
func randomPayload(r *runner.E2ERunner) string {
bytes := make([]byte, 50)
_, err := rand.Read(bytes)
require.NoError(r, err)

return hex.EncodeToString(bytes)
}

func withdrawBTCZRC20(r *runner.E2ERunner, to btcutil.Address, amount *big.Int) *btcjson.TxRawResult {
tx, err := r.BTCZRC20.Approve(
r.ZEVMAuth,
Expand Down
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_erc20_deposit_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageDepositERC20 = "this is a test ERC20 deposit and call payload"

func TestV2ERC20DepositAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

Expand All @@ -22,7 +20,9 @@ func TestV2ERC20DepositAndCall(r *runner.E2ERunner, args []string) {

r.ApproveERC20OnEVM(r.GatewayEVMAddr)

r.AssertTestDAppZEVMCalled(false, payloadMessageDepositERC20, amount)
payload := randomPayload(r)

r.AssertTestDAppZEVMCalled(false, payload, amount)

oldBalance, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.TestDAppV2ZEVMAddr)
require.NoError(r, err)
Expand All @@ -31,7 +31,7 @@ func TestV2ERC20DepositAndCall(r *runner.E2ERunner, args []string) {
tx := r.V2ERC20DepositAndCall(
r.TestDAppV2ZEVMAddr,
amount,
[]byte(payloadMessageDepositERC20),
[]byte(payload),
gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -41,7 +41,7 @@ func TestV2ERC20DepositAndCall(r *runner.E2ERunner, args []string) {
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

// check the payload was received on the contract
r.AssertTestDAppZEVMCalled(true, payloadMessageDepositERC20, amount)
r.AssertTestDAppZEVMCalled(true, payload, amount)

// check the balance was updated
newBalance, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.TestDAppV2ZEVMAddr)
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2etests/test_v2_erc20_deposit_and_call_revert_with_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageDepositOnRevertERC20 = "this is a test ERC20 deposit and call on revert"

func TestV2ERC20DepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

Expand All @@ -22,13 +20,15 @@ func TestV2ERC20DepositAndCallRevertWithCall(r *runner.E2ERunner, args []string)

r.ApproveERC20OnEVM(r.GatewayEVMAddr)

r.AssertTestDAppEVMCalled(false, payloadMessageDepositOnRevertERC20, amount)
payload := randomPayload(r)

r.AssertTestDAppEVMCalled(false, payload, amount)

// perform the deposit
tx := r.V2ERC20DepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{
RevertAddress: r.TestDAppV2EVMAddr,
CallOnRevert: true,
RevertMessage: []byte(payloadMessageDepositOnRevertERC20),
RevertMessage: []byte(payload),
OnRevertGasLimit: big.NewInt(200000),
})

Expand All @@ -38,12 +38,12 @@ func TestV2ERC20DepositAndCallRevertWithCall(r *runner.E2ERunner, args []string)
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

// check the payload was received on the contract
r.AssertTestDAppEVMCalled(true, payloadMessageDepositOnRevertERC20, big.NewInt(0))
r.AssertTestDAppEVMCalled(true, payload, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageDepositOnRevertERC20),
[]byte(payload),
)
require.NoError(r, err)
require.Equal(r, r.EVMAuth.From, senderForMsg)
Expand Down
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_erc20_withdraw_and_arbitrary_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageWithdrawERC20 = "this is a test ERC20 withdraw and call payload"

func TestV2ERC20WithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ERC20WithdrawAndCall")

r.AssertTestDAppEVMCalled(false, payloadMessageWithdrawERC20, amount)
payload := randomPayload(r)

r.AssertTestDAppEVMCalled(false, payload, amount)

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)
Expand All @@ -28,7 +28,7 @@ func TestV2ERC20WithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) {
tx := r.V2ERC20WithdrawAndArbitraryCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeERC20Call(r.ERC20Addr, amount, payloadMessageWithdrawERC20),
r.EncodeERC20Call(r.ERC20Addr, amount, payload),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -37,5 +37,5 @@ func TestV2ERC20WithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) {
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

r.AssertTestDAppEVMCalled(true, payloadMessageWithdrawERC20, amount)
r.AssertTestDAppEVMCalled(true, payload, amount)
}
12 changes: 6 additions & 6 deletions e2e/e2etests/test_v2_erc20_withdraw_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageWithdrawAuthenticatedCallERC20 = "this is a test ERC20 withdraw and authenticated call payload"

func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, _ []string) {
previousGasLimit := r.ZEVMAuth.GasLimit
r.ZEVMAuth.GasLimit = 10000000
Expand All @@ -25,7 +23,9 @@ func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, _ []string) {
// without decoding the payload and amount handling for erc20, purpose of test is to verify correct sender and payload are used
amount := big.NewInt(10000)

r.AssertTestDAppEVMCalled(false, payloadMessageWithdrawAuthenticatedCallERC20, amount)
payload := randomPayload(r)

r.AssertTestDAppEVMCalled(false, payload, amount)

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)
Expand All @@ -34,7 +34,7 @@ func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, _ []string) {
tx := r.V2ERC20WithdrawAndCall(
r.TestDAppV2EVMAddr,
amount,
[]byte(payloadMessageWithdrawAuthenticatedCallERC20),
[]byte(payload),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -43,12 +43,12 @@ func TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, _ []string) {
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

r.AssertTestDAppEVMCalled(true, payloadMessageWithdrawAuthenticatedCallERC20, big.NewInt(0))
r.AssertTestDAppEVMCalled(true, payload, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageWithdrawAuthenticatedCallERC20),
[]byte(payload),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2etests/test_v2_erc20_withdraw_and_call_revert_with_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageWithdrawOnRevertERC20 = "this is a test ERC20 withdraw and call on revert"

func TestV2ERC20WithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ERC20WithdrawAndCallRevertWithCall")

r.AssertTestDAppZEVMCalled(false, payloadMessageWithdrawOnRevertERC20, amount)
payload := randomPayload(r)

r.AssertTestDAppZEVMCalled(false, payload, amount)

r.ApproveERC20ZRC20(r.GatewayZEVMAddr)
r.ApproveETHZRC20(r.GatewayZEVMAddr)
Expand All @@ -33,7 +33,7 @@ func TestV2ERC20WithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string
gatewayzevm.RevertOptions{
RevertAddress: r.TestDAppV2ZEVMAddr,
CallOnRevert: true,
RevertMessage: []byte(payloadMessageWithdrawOnRevertERC20),
RevertMessage: []byte(payload),
OnRevertGasLimit: big.NewInt(0),
},
)
Expand All @@ -43,12 +43,12 @@ func TestV2ERC20WithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

r.AssertTestDAppZEVMCalled(true, payloadMessageWithdrawOnRevertERC20, big.NewInt(0))
r.AssertTestDAppZEVMCalled(true, payload, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2ZEVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageWithdrawOnRevertERC20),
[]byte(payload),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
Expand Down
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_eth_deposit_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageDepositETH = "this is a test ETH deposit and call payload"

func TestV2ETHDepositAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ETHDepositAndCall")

r.AssertTestDAppZEVMCalled(false, payloadMessageDepositETH, amount)
payload := randomPayload(r)

r.AssertTestDAppZEVMCalled(false, payload, amount)

oldBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.TestDAppV2ZEVMAddr)
require.NoError(r, err)
Expand All @@ -29,7 +29,7 @@ func TestV2ETHDepositAndCall(r *runner.E2ERunner, args []string) {
tx := r.V2ETHDepositAndCall(
r.TestDAppV2ZEVMAddr,
amount,
[]byte(payloadMessageDepositETH),
[]byte(payload),
gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -39,7 +39,7 @@ func TestV2ETHDepositAndCall(r *runner.E2ERunner, args []string) {
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

// check the payload was received on the contract
r.AssertTestDAppZEVMCalled(true, payloadMessageDepositETH, amount)
r.AssertTestDAppZEVMCalled(true, payload, amount)

// check the balance was updated
newBalance, err := r.ETHZRC20.BalanceOf(&bind.CallOpts{}, r.TestDAppV2ZEVMAddr)
Expand Down
12 changes: 6 additions & 6 deletions e2e/e2etests/test_v2_eth_deposit_and_call_revert_with_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageDepositOnRevertETH = "this is a test ETH deposit and call on revert"

func TestV2ETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

Expand All @@ -22,13 +20,15 @@ func TestV2ETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {

r.ApproveERC20OnEVM(r.GatewayEVMAddr)

r.AssertTestDAppEVMCalled(false, payloadMessageDepositOnRevertETH, amount)
payload := randomPayload(r)

r.AssertTestDAppEVMCalled(false, payload, amount)

// perform the deposit
tx := r.V2ETHDepositAndCall(r.TestDAppV2ZEVMAddr, amount, []byte("revert"), gatewayevm.RevertOptions{
RevertAddress: r.TestDAppV2EVMAddr,
CallOnRevert: true,
RevertMessage: []byte(payloadMessageDepositOnRevertETH),
RevertMessage: []byte(payload),
OnRevertGasLimit: big.NewInt(200000),
})

Expand All @@ -38,12 +38,12 @@ func TestV2ETHDepositAndCallRevertWithCall(r *runner.E2ERunner, args []string) {
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

// check the payload was received on the contract
r.AssertTestDAppEVMCalled(true, payloadMessageDepositOnRevertETH, big.NewInt(0))
r.AssertTestDAppEVMCalled(true, payload, big.NewInt(0))

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageDepositOnRevertETH),
[]byte(payload),
)
require.NoError(r, err)
require.Equal(r, r.EVMAuth.From, senderForMsg)
Expand Down
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_eth_withdraw_and_arbitrary_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

const payloadMessageWithdrawETH = "this is a test ETH withdraw and call payload"

func TestV2ETHWithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndCall")

r.AssertTestDAppEVMCalled(false, payloadMessageWithdrawETH, amount)
payload := randomPayload(r)

r.AssertTestDAppEVMCalled(false, payload, amount)

r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.V2ETHWithdrawAndArbitraryCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeGasCall(payloadMessageWithdrawETH),
r.EncodeGasCall(payload),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -36,5 +36,5 @@ func TestV2ETHWithdrawAndArbitraryCall(r *runner.E2ERunner, args []string) {
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)

r.AssertTestDAppEVMCalled(true, payloadMessageWithdrawETH, amount)
r.AssertTestDAppEVMCalled(true, payload, amount)
}
Loading

0 comments on commit 6ef5c57

Please sign in to comment.