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): backport improve E2E reliability for tests on live network to v20 branch #3069

Merged
merged 5 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/zetae2e/config/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func setContractsFromConfig(r *runner.E2ERunner, conf config.Config) error {
if err != nil {
return fmt.Errorf("invalid TestDAppV2Addr: %w", err)
}
r.TestDAppV2ZEVM, err = testdappv2.NewTestDAppV2(r.TestDAppV2ZEVMAddr, r.EVMClient)
r.TestDAppV2ZEVM, err = testdappv2.NewTestDAppV2(r.TestDAppV2ZEVMAddr, r.ZEVMClient)
if err != nil {
return err
}
Expand Down
20 changes: 11 additions & 9 deletions cmd/zetae2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,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 @@ -16,6 +18,15 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/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/zetacore/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
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/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 @@ -21,13 +19,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 @@ -37,5 +37,5 @@ 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))
}
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_erc20_withdraw_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

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

func TestV2ERC20WithdrawAndCall(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 TestV2ERC20WithdrawAndCall(r *runner.E2ERunner, args []string) {
tx := r.V2ERC20WithdrawAndCall(
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 TestV2ERC20WithdrawAndCall(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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/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 @@ -32,7 +32,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 @@ -42,5 +42,5 @@ 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))
}
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/zetacore/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
10 changes: 5 additions & 5 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 @@ -11,8 +11,6 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/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 @@ -21,13 +19,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 @@ -37,5 +37,5 @@ 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))
}
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_eth_withdraw_and_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

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

func TestV2ETHWithdrawAndCall(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.V2ETHWithdrawAndCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeGasCall(payloadMessageWithdrawETH),
r.EncodeGasCall(payload),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -36,5 +36,5 @@ func TestV2ETHWithdrawAndCall(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)
}
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_eth_withdraw_and_call_revert_with_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const payloadMessageWithdrawOnRevertETH = "this is a test ETH withdraw and call on revert"

func TestV2ETHWithdrawAndCallRevertWithCall(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 TestV2ETHWithdrawAndCallRevertWithCall")

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

r.AssertTestDAppZEVMCalled(false, payload, amount)

r.ApproveETHZRC20(r.GatewayZEVMAddr)

Expand All @@ -31,7 +31,7 @@ func TestV2ETHWithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string)
gatewayzevm.RevertOptions{
RevertAddress: r.TestDAppV2ZEVMAddr,
CallOnRevert: true,
RevertMessage: []byte(payloadMessageWithdrawOnRevertETH),
RevertMessage: []byte(payload),
OnRevertGasLimit: big.NewInt(0),
},
)
Expand All @@ -41,5 +41,5 @@ func TestV2ETHWithdrawAndCallRevertWithCall(r *runner.E2ERunner, args []string)
r.Logger.CCTX(*cctx, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)

r.AssertTestDAppZEVMCalled(true, payloadMessageWithdrawOnRevertETH, big.NewInt(0))
r.AssertTestDAppZEVMCalled(true, payload, big.NewInt(0))
}
10 changes: 5 additions & 5 deletions e2e/e2etests/test_v2_evm_to_zevm_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import (
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"
)

const payloadMessageZEVMCall = "this is a test ZEVM call payload"

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

r.AssertTestDAppZEVMCalled(false, payloadMessageZEVMCall, big.NewInt(0))
payload := randomPayload(r)

r.AssertTestDAppZEVMCalled(false, payload, big.NewInt(0))

// perform the withdraw
tx := r.V2EVMToZEMVCall(
r.TestDAppV2ZEVMAddr,
[]byte(payloadMessageZEVMCall),
[]byte(payload),
gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

Expand All @@ -31,5 +31,5 @@ func TestV2EVMToZEVMCall(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, payloadMessageZEVMCall, big.NewInt(0))
r.AssertTestDAppZEVMCalled(true, payload, big.NewInt(0))
}
Loading
Loading