Skip to content

Commit

Permalink
add deposit call revert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Feb 28, 2025
1 parent 45023e4 commit 9ddf7db
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ start-ton-test: e2e-images

start-sui-test: e2e-images
@echo "--> Starting sui test"
export E2E_ARGS="--skip-regular --test-sui --verbose" && \
export E2E_ARGS="--skip-regular --test-sui" && \
cd contrib/localnet/ && $(DOCKER_COMPOSE) --profile sui up -d

start-legacy-test: e2e-images
Expand Down
6 changes: 4 additions & 2 deletions cmd/zetae2e/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,11 @@ func localE2ETest(cmd *cobra.Command, _ []string) {
if testSui {
suiTests := []string{
e2etests.TestSuiDepositName,
//e2etests.TestSuiDepositAndCallName,
e2etests.TestSuiDepositAndCallRevertName,
e2etests.TestSuiDepositAndCallName,
e2etests.TestSuiTokenDepositName,
//e2etests.TestSuiTokenDepositAndCallName,
e2etests.TestSuiTokenDepositAndCallName,
e2etests.TestSuiTokenDepositAndCallRevertName,
e2etests.TestSuiWithdrawName,
e2etests.TestSuiTokenWithdrawName,
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/zetae2e/local/sui.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func suiTestRoutine(
suiRunner.RequestSuiFromFaucet(conf.RPCs.SuiFaucet, suiRunnerSigner.Address())

// mint fungible tokens to the account
txRes := deployerRunner.SuiMintUSDC("10000000", suiRunnerSigner.Address())
txRes := deployerRunner.SuiMintUSDC("100000000000", suiRunnerSigner.Address())

deployerRunner.Logger.Info("Sui USDC mint tx: %s", txRes.Digest)

Expand Down
34 changes: 27 additions & 7 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ const (
/*
Sui tests
*/
TestSuiDepositName = "sui_deposit"
TestSuiDepositAndCallName = "sui_deposit_and_call"
TestSuiTokenDepositName = "sui_token_deposit" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiTokenDepositAndCallName = "sui_token_deposit_and_call" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiWithdrawName = "sui_withdraw"
TestSuiTokenWithdrawName = "sui_token_withdraw" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiDepositName = "sui_deposit"
TestSuiDepositAndCallName = "sui_deposit_and_call"
TestSuiDepositAndCallRevertName = "sui_deposit_and_call_revert"
TestSuiTokenDepositName = "sui_token_deposit" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiTokenDepositAndCallName = "sui_token_deposit_and_call" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiTokenDepositAndCallRevertName = "sui_token_deposit_and_call_revert" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestSuiWithdrawName = "sui_withdraw"
TestSuiTokenWithdrawName = "sui_token_withdraw" // #nosec G101: Potential hardcoded credentials (gosec), not a credential

/*
Bitcoin tests
Expand Down Expand Up @@ -709,11 +711,20 @@ var AllE2ETests = []runner.E2ETest{
TestSuiDepositAndCall,
runner.WithMinimumVersion("v29.0.0"),
),
runner.NewE2ETest(
TestSuiDepositAndCallRevertName,
"deposit SUI into ZEVM and call a contract that reverts",
[]runner.ArgDefinition{
{Description: "amount in mist", DefaultValue: "10000000000"},
},
TestSuiDepositAndCallRevert,
runner.WithMinimumVersion("v29.0.0"),
),
runner.NewE2ETest(
TestSuiTokenDepositName,
"deposit fungible token SUI into ZEVM",
[]runner.ArgDefinition{
{Description: "amount in base unit", DefaultValue: "1000000"},
{Description: "amount in base unit", DefaultValue: "10000000000"},
},
TestSuiTokenDeposit,
runner.WithMinimumVersion("v29.0.0"),
Expand All @@ -727,6 +738,15 @@ var AllE2ETests = []runner.E2ETest{
TestSuiTokenDepositAndCall,
runner.WithMinimumVersion("v29.0.0"),
),
runner.NewE2ETest(
TestSuiTokenDepositAndCallRevertName,
"deposit fungible token into ZEVM and call a contract that reverts",
[]runner.ArgDefinition{
{Description: "amount in base unit", DefaultValue: "10000000000"},
},
TestSuiTokenDepositAndCallRevert,
runner.WithMinimumVersion("v29.0.0"),
),
runner.NewE2ETest(
TestSuiWithdrawName,
"withdraw SUI from ZEVM",
Expand Down
29 changes: 29 additions & 0 deletions e2e/e2etests/test_sui_deposit_and_call_revert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package e2etests

import (
"cosmossdk.io/math"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/pkg/coin"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

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

amount := utils.ParseBigInt(r, args[0])

// make the deposit transaction
resp := r.SuiDepositAndCallSUI(r.TestDAppV2ZEVMAddr, math.NewUintFromBigInt(amount), []byte("revert"))

r.Logger.Info("Sui deposit and call tx: %s", resp.Digest)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, resp.Digest, r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "deposit")
require.EqualValues(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)
require.EqualValues(r, coin.CoinType_Gas, cctx.InboundParams.CoinType)
require.True(r, cctx.InboundParams.IsCrossChainCall)
}
37 changes: 37 additions & 0 deletions e2e/e2etests/test_sui_token_deposit_and_call_revert.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package e2etests

import (
"math/big"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"

"github.com/zeta-chain/node/e2e/runner"
"github.com/zeta-chain/node/e2e/utils"
"github.com/zeta-chain/node/pkg/coin"
crosschaintypes "github.com/zeta-chain/node/x/crosschain/types"
)

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

amount := utils.ParseBigInt(r, args[0])

// add liquidity in pool to allow revert fee to be paid
zetaAmount := big.NewInt(1e18)
zrc20Amount := big.NewInt(9000000000)
r.AddLiquiditySUI(zetaAmount, zrc20Amount)
r.AddLiquiditySuiFungibleToken(zetaAmount, zrc20Amount)

// make the deposit transaction
resp := r.SuiFungibleTokenDepositAndCall(r.TestDAppV2ZEVMAddr, math.NewUintFromBigInt(amount), []byte("revert"))

r.Logger.Info("Sui deposit and call tx: %s", resp.Digest)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, resp.Digest, r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "deposit")
require.EqualValues(r, crosschaintypes.CctxStatus_Reverted, cctx.CctxStatus.Status)
require.EqualValues(r, coin.CoinType_ERC20, cctx.InboundParams.CoinType)
require.EqualValues(r, amount.Uint64(), cctx.InboundParams.Amount.Uint64())
}
12 changes: 12 additions & 0 deletions e2e/runner/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ func (r *E2ERunner) AddLiquiditySPL(amountZETA, amountSPL *big.Int) {
r.addLiquidity(r.SPLZRC20Addr, amountZETA, amountSPL)
}

// AddLiquiditySUI adds liquidity token to the uniswap pool ZETA/SUI
func (r *E2ERunner) AddLiquiditySUI(amountZETA, amountSUI *big.Int) {
r.SuiApproveSUIZRC20(r.UniswapV2RouterAddr)
r.addLiquidity(r.SUIZRC20Addr, amountZETA, amountSUI)
}

// AddLiquiditySuiFungibleToken adds liquidity token to the uniswap pool ZETA/SuiFungibleToken
func (r *E2ERunner) AddLiquiditySuiFungibleToken(amountZETA, amountToken *big.Int) {
r.SuiApproveFungibleTokenZRC20(r.UniswapV2RouterAddr)
r.addLiquidity(r.SuiTokenZRC20Addr, amountZETA, amountToken)
}

// addLiquidity adds liquidity token to the uniswap pool ZETA/token
// we use the provided amount of ZETA and token to add liquidity as wanted amount
// 0 is used for the minimum amount of ZETA and token
Expand Down
4 changes: 3 additions & 1 deletion zetaclient/chains/sui/signer/signer_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ func (s *Signer) buildWithdrawal(ctx context.Context, cctx *cctypes.CrossChainTx
return tx, errors.Errorf("invalid protocol version %q", cctx.ProtocolContractVersion)
case cctx.InboundParams == nil:
return tx, errors.New("inbound params are nil")
case cctx.InboundParams.IsCrossChainCall:
case cctx.InboundParams.IsCrossChainCall && cctx.CctxStatus.Status == cctypes.CctxStatus_PendingOutbound:
// NOTE: we check for pending outbound status, reverting cross-chain calls are treated as regular withdraws
return tx, errors.New("withdrawAndCall is not supported yet")
case params.CoinType == coin.CoinType_Gas:
coinType = string(sui.SUI)
case params.CoinType == coin.CoinType_ERC20:
// NOTE: 0x prefix is required for coin type other than SUI
coinType = "0x" + cctx.InboundParams.Asset
default:
return tx, errors.Errorf("unsupported coin type %q", params.CoinType.String())
Expand Down

0 comments on commit 9ddf7db

Please sign in to comment.