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 E2E reliability for tests on live network #3061

Merged
merged 8 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
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
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
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)
}
12 changes: 6 additions & 6 deletions e2e/e2etests/test_v2_eth_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 payloadMessageAuthenticatedWithdrawETH = "this is a test ETH withdraw and authenticated call payload"

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

Expand All @@ -26,15 +24,17 @@ func TestV2ETHWithdrawAndCall(r *runner.E2ERunner, args []string) {
amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestV2ETHWithdrawAndCall")

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

r.AssertTestDAppEVMCalled(false, payload, amount)

r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.V2ETHWithdrawAndCall(
r.TestDAppV2EVMAddr,
amount,
[]byte(payloadMessageAuthenticatedWithdrawETH),
[]byte(payload),
gatewayzevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

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

r.AssertTestDAppEVMCalled(true, payloadMessageAuthenticatedWithdrawETH, amount)
r.AssertTestDAppEVMCalled(true, payload, amount)

// check expected sender was used
senderForMsg, err := r.TestDAppV2EVM.SenderWithMessage(
&bind.CallOpts{},
[]byte(payloadMessageAuthenticatedWithdrawETH),
[]byte(payload),
)
require.NoError(r, err)
require.Equal(r, r.ZEVMAuth.From, senderForMsg)
Expand Down
Loading
Loading