Skip to content

Commit

Permalink
test: Solana e2e deposit and call; deposit and revert (#2726)
Browse files Browse the repository at this point in the history
* initiate Solana deposit and call

* add Solana E2E deposit_and_call_refund

* add changelog entry and adjust e2e default arguments

* added parseBigInt() helper func for E2E tests; created SOLDepositAndCall util function; misc

* go import

---------

Co-authored-by: lumtis <[email protected]>
  • Loading branch information
ws4charlie and lumtis authored Aug 19, 2024
1 parent 3d1698d commit 53883f5
Show file tree
Hide file tree
Showing 36 changed files with 258 additions and 126 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

* [2615](https://github.com/zeta-chain/node/pull/2615) - Refactor cleanup of outbound trackers

### Tests

* [2726](https://github.com/zeta-chain/node/pull/2726) - add e2e tests for deposit and call, deposit and revert

### Fixes

* [2654](https://github.com/zeta-chain/node/pull/2654) - add validation for authorization list in when validating genesis state for authorization module
Expand Down
2 changes: 2 additions & 0 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
solanaTests := []string{
e2etests.TestSolanaDepositName,
e2etests.TestSolanaWithdrawName,
e2etests.TestSolanaDepositAndCallName,
e2etests.TestSolanaDepositAndCallRefundName,
}
eg.Go(solanaTestRoutine(conf, deployerRunner, verbose, solanaTests...))
}
Expand Down
26 changes: 22 additions & 4 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ const (
/*
Solana tests
*/
TestSolanaDepositName = "solana_deposit"
TestSolanaWithdrawName = "solana_withdraw"
TestSolanaDepositName = "solana_deposit"
TestSolanaWithdrawName = "solana_withdraw"
TestSolanaDepositAndCallName = "solana_deposit_and_call"
TestSolanaDepositAndCallRefundName = "solana_deposit_and_call_refund"

/*
Bitcoin tests
Expand Down Expand Up @@ -365,18 +367,34 @@ var AllE2ETests = []runner.E2ETest{
TestSolanaDepositName,
"deposit SOL into ZEVM",
[]runner.ArgDefinition{
{Description: "amount in lamport", DefaultValue: "13370000"},
{Description: "amount in lamport", DefaultValue: "1200000"},
},
TestSolanaDeposit,
),
runner.NewE2ETest(
TestSolanaWithdrawName,
"withdraw SOL from ZEVM",
[]runner.ArgDefinition{
{Description: "amount in lamport", DefaultValue: "1336000"},
{Description: "amount in lamport", DefaultValue: "1000000"},
},
TestSolanaWithdraw,
),
runner.NewE2ETest(
TestSolanaDepositAndCallName,
"deposit SOL into ZEVM and call a contract",
[]runner.ArgDefinition{
{Description: "amount in lamport", DefaultValue: "1200000"},
},
TestSolanaDepositAndCall,
),
runner.NewE2ETest(
TestSolanaDepositAndCallRefundName,
"deposit SOL into ZEVM and call a contract that reverts; should refund",
[]runner.ArgDefinition{
{Description: "amount in lamport", DefaultValue: "1200000"},
},
TestSolanaDepositAndCallRefund,
),
/*
Bitcoin tests
*/
Expand Down
7 changes: 7 additions & 0 deletions e2e/e2etests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ func parseInt(t require.TestingT, s string) int {
return v
}

func parseBigInt(t require.TestingT, s string) *big.Int {
v, ok := big.NewInt(0).SetString(s, 10)
require.True(t, ok, "unable to parse big.Int from %q", s)

return v
}

// bigIntFromFloat64 takes float64 (e.g. 0.001) that represents btc amount
// and converts it to big.Int for downstream usage.
func btcAmountFromFloat64(t require.TestingT, amount float64) *big.Int {
Expand Down
4 changes: 1 addition & 3 deletions e2e/e2etests/test_context_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package e2etests

import (
"bytes"
"math/big"
"time"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand All @@ -17,8 +16,7 @@ func TestContextUpgrade(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

// parse the value from the provided arguments
value, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid value specified for TestContextUpgrade.")
value := parseBigInt(r, args[0])

data := make([]byte, 0, 32)
data = append(data, r.ContextAppAddr.Bytes()...)
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_donation.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand All @@ -14,8 +12,8 @@ import (
func TestDonationEther(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 TestDonationEther.")
// parse the donation amount
amount := parseBigInt(r, args[0])

txDonation, err := r.SendEther(r.TSSAddress, amount, []byte(constant.DonationMessage))
require.NoError(r, err)
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_erc20_deposit.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand All @@ -12,8 +10,8 @@ import (
func TestERC20Deposit(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 TestERC20Deposit.")
// parse the deposit amount
amount := parseBigInt(r, args[0])

hash := r.DepositERC20WithAmountAndMessage(r.EVMAddress(), amount, []byte{})

Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_erc20_deposit_restricted_address.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

Expand All @@ -13,8 +11,8 @@ import (
func TestERC20DepositRestricted(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)
// parse the deposit amount
amount := parseBigInt(r, args[0])

// deposit ERC20 to restricted address
r.DepositERC20WithAmountAndMessage(ethcommon.HexToAddress(testutils.RestrictedEVMAddressTest), amount, []byte{})
Expand Down
8 changes: 3 additions & 5 deletions e2e/e2etests/test_erc20_multiple_deposits.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ import (
func TestMultipleERC20Deposit(r *runner.E2ERunner, args []string) {
require.Len(r, args, 2)

depositAmount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)

numberOfDeposits, ok := big.NewInt(0).SetString(args[1], 10)
require.True(r, ok)
// parse the deposit amount and count
depositAmount := parseBigInt(r, args[0])
numberOfDeposits := parseBigInt(r, args[1])
require.NotZero(r, numberOfDeposits.Int64())

initialBal, err := r.ERC20ZRC20.BalanceOf(&bind.CallOpts{}, r.EVMAddress())
Expand Down
8 changes: 3 additions & 5 deletions e2e/e2etests/test_erc20_multiple_withdraws.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@ func TestMultipleERC20Withdraws(r *runner.E2ERunner, args []string) {

approvedAmount := big.NewInt(1e18)

withdrawalAmount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)
// parse the withdrawal amount and number of withdrawals
withdrawalAmount := parseBigInt(r, args[0])
require.Equal(
r,
-1,
withdrawalAmount.Cmp(approvedAmount),
"Invalid withdrawal amount specified for TestMultipleWithdraws.",
)

numberOfWithdrawals, ok := big.NewInt(0).SetString(args[1], 10)
require.True(r, ok)
numberOfWithdrawals := parseBigInt(r, args[1])
require.NotEmpty(r, numberOfWithdrawals.Int64())

// calculate total withdrawal to ensure it doesn't exceed approved amount.
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_eth_deposit.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"

"github.com/zeta-chain/zetacore/e2e/runner"
Expand All @@ -13,8 +11,8 @@ import (
func TestEtherDeposit(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 TestEtherDeposit.")
// parse the deposit amount
amount := parseBigInt(r, args[0])

hash := r.DepositEtherWithAmount(amount) // in wei
// wait for the cctx to be mined
Expand Down
21 changes: 4 additions & 17 deletions e2e/e2etests/test_eth_deposit_call.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package e2etests

import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
ethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/stretchr/testify/require"

Expand All @@ -17,8 +14,8 @@ import (
func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

value, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestEtherDepositAndCall.")
// parse deposit amount
value := parseBigInt(r, args[0])

r.Logger.Info("Deploying example contract")
exampleAddr, _, exampleContract, err := testcontract.DeployExample(r.ZEVMAuth, r.ZEVMClient)
Expand Down Expand Up @@ -57,16 +54,7 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {
utils.RequireCCTXStatus(r, cctx, types.CctxStatus_OutboundMined)

// Checking example contract has been called, bar value should be set to amount
bar, err := exampleContract.Bar(&bind.CallOpts{})
require.NoError(r, err)
require.Equal(
r,
0,
bar.Cmp(value),
"cross-chain call failed bar value %s should be equal to amount %s",
bar.String(),
value.String(),
)
utils.MustHaveCalledExampleContract(r, exampleContract, value)
r.Logger.Info("Cross-chain call succeeded")

r.Logger.Info("Deploying reverter contract")
Expand Down Expand Up @@ -100,6 +88,5 @@ func TestEtherDepositAndCall(r *runner.E2ERunner, args []string) {
r.Logger.Info("Cross-chain call to reverter reverted")

// check the status message contains revert error hash in case of revert
// 0xbfb4ebcf is the hash of "Foo()"
require.Contains(r, cctx.CctxStatus.StatusMessage, "0xbfb4ebcf")
require.Contains(r, cctx.CctxStatus.StatusMessage, utils.ErrHashRevertFoo)
}
4 changes: 2 additions & 2 deletions e2e/e2etests/test_eth_deposit_refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func TestEtherDepositAndCallRefund(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

value, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok, "Invalid amount specified for TestEtherDepositAndCallRefund.")
// parse the deposit amount
value := parseBigInt(r, args[0])

evmClient := r.EVMClient

Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_evm_to_zevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
func TestMessagePassingEVMtoZEVM(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 TestMessagePassingEVMtoZEVM.")
// parse the amount
amount := parseBigInt(r, args[0])

// Set destination details
zEVMChainID, err := r.ZEVMClient.ChainID(r.Ctx)
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_evm_to_zevm_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ func TestMessagePassingEVMtoZEVMRevert(r *runner.E2ERunner, args []string) {
fungibleEthAddress := ethcommon.HexToAddress(fungibleModuleAddress)
require.True(r, fungibleEthAddress != ethcommon.Address{}, "invalid fungible module address")

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)
// parse the amount
amount := parseBigInt(r, args[0])

// Set destination details
zEVMChainID, err := r.ZEVMClient.ChainID(r.Ctx)
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_message_passing_evm_to_zevm_revert_fail.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"

Expand All @@ -15,8 +13,8 @@ import (
func TestMessagePassingEVMtoZEVMRevertFail(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 TestMessagePassingEVMtoZEVMRevertFail.")
// parse the amount
amount := parseBigInt(r, args[0])

// Deploying a test contract not containing a logic for reverting the cctx
testDappNoRevertEVMAddr, tx, testDappNoRevertEVM, err := testdappnorevert.DeployTestDAppNoRevert(
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_external_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import (
func TestMessagePassingExternalChains(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 TestMessagePassing.")
// parse the amount
amount := parseBigInt(r, args[0])

chainID, err := r.EVMClient.ChainID(r.Ctx)
require.NoError(r, err)
Expand Down
6 changes: 2 additions & 4 deletions e2e/e2etests/test_message_passing_external_chains_revert.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package e2etests

import (
"math/big"

banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
ethcommon "github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"
Expand All @@ -19,8 +17,8 @@ import (
func TestMessagePassingRevertSuccessExternalChains(r *runner.E2ERunner, args []string) {
require.Len(r, args, 1)

amount, ok := big.NewInt(0).SetString(args[0], 10)
require.True(r, ok)
// parse the amount
amount := parseBigInt(r, args[0])

chainID, err := r.EVMClient.ChainID(r.Ctx)
require.NoError(r, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
func TestMessagePassingRevertFailExternalChains(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 TestMessagePassingRevertFail.")
// parse the amount
amount := parseBigInt(r, args[0])

chainID, err := r.EVMClient.ChainID(r.Ctx)
require.NoError(r, err)
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_zevm_to_evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
func TestMessagePassingZEVMtoEVM(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 TestMessagePassingZEVMtoEVM.")
// parse the amount
amount := parseBigInt(r, args[0])

// Set destination details
EVMChainID, err := r.EVMClient.ChainID(r.Ctx)
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_zevm_to_evm_revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
func TestMessagePassingZEVMtoEVMRevert(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 TestMessagePassingZEVMtoEVMRevert.")
// parse the amount
amount := parseBigInt(r, args[0])

// Set destination details
EVMChainID, err := r.EVMClient.ChainID(r.Ctx)
Expand Down
4 changes: 2 additions & 2 deletions e2e/e2etests/test_message_passing_zevm_to_evm_revert_fail.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (
func TestMessagePassingZEVMtoEVMRevertFail(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 TestMessagePassingZEVMtoEVMRevertFail.")
// parse the amount
amount := parseBigInt(r, args[0])

// Deploying a test contract not containing a logic for reverting the cctx
testDappNoRevertAddr, tx, testDappNoRevert, err := testdappnorevert.DeployTestDAppNoRevert(
Expand Down
Loading

0 comments on commit 53883f5

Please sign in to comment.