Skip to content

Commit

Permalink
deposit and withdraw test
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Nov 6, 2024
1 parent b0bb05b commit b638cc5
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 59 deletions.
119 changes: 60 additions & 59 deletions cmd/zetae2e/local/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,67 +16,68 @@ import (
func startV2Tests(eg *errgroup.Group, conf config.Config, deployerRunner *runner.E2ERunner, verbose bool) {
// Test happy paths for gas token workflow
eg.Go(v2TestRoutine(conf, "eth", conf.AdditionalAccounts.UserV2Ether, color.FgHiGreen, deployerRunner, verbose,
e2etests.TestV2ETHDepositName,
e2etests.TestV2ETHDepositAndCallName,
e2etests.TestV2ETHWithdrawName,
e2etests.TestV2ETHWithdrawAndArbitraryCallName,
e2etests.TestV2ETHWithdrawAndCallName,
e2etests.TestV2ETHWithdrawAndCallThroughContractName,
e2etests.TestV2ZEVMToEVMArbitraryCallName,
e2etests.TestV2ZEVMToEVMCallName,
e2etests.TestV2ZEVMToEVMCallThroughContractName,
e2etests.TestV2EVMToZEVMCallName,
e2etests.TestV2ETHDepositAndCallNoMessageName,
e2etests.TestV2ETHWithdrawAndCallNoMessageName,
//e2etests.TestV2ETHDepositName,
//e2etests.TestV2ETHDepositAndCallName,
//e2etests.TestV2ETHWithdrawName,
//e2etests.TestV2ETHWithdrawAndArbitraryCallName,
//e2etests.TestV2ETHWithdrawAndCallName,
//e2etests.TestV2ETHWithdrawAndCallThroughContractName,
//e2etests.TestV2ZEVMToEVMArbitraryCallName,
//e2etests.TestV2ZEVMToEVMCallName,
//e2etests.TestV2ZEVMToEVMCallThroughContractName,
//e2etests.TestV2EVMToZEVMCallName,
//e2etests.TestV2ETHDepositAndCallNoMessageName,
//e2etests.TestV2ETHWithdrawAndCallNoMessageName,
e2etests.TestDepositAndWithdrawName,
))

// Test happy paths for erc20 token workflow
eg.Go(v2TestRoutine(conf, "erc20", conf.AdditionalAccounts.UserV2ERC20, color.FgHiBlue, deployerRunner, verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName,
e2etests.TestV2ERC20DepositAndCallName,
e2etests.TestV2ERC20WithdrawName,
e2etests.TestV2ERC20WithdrawAndArbitraryCallName,
e2etests.TestV2ERC20WithdrawAndCallName,
e2etests.TestV2ERC20DepositAndCallNoMessageName,
))

// Test revert cases for gas token workflow
eg.Go(
v2TestRoutine(
conf,
"eth-revert",
conf.AdditionalAccounts.UserV2EtherRevert,
color.FgHiYellow,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM and withdraw
e2etests.TestV2ETHDepositAndCallRevertName,
e2etests.TestV2ETHDepositAndCallRevertWithCallName,
e2etests.TestV2ETHWithdrawAndCallRevertName,
e2etests.TestV2ETHWithdrawAndCallRevertWithCallName,
),
)

// Test revert cases for erc20 token workflow
eg.Go(
v2TestRoutine(
conf,
"erc20-revert",
conf.AdditionalAccounts.UserV2ERC20Revert,
color.FgHiRed,
deployerRunner,
verbose,
e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
e2etests.TestV2ERC20DepositName, // necessary to have assets to withdraw
e2etests.TestOperationAddLiquidityETHName, // liquidity with gas and ERC20 are necessary for reverts
e2etests.TestOperationAddLiquidityERC20Name,
e2etests.TestV2ERC20DepositAndCallRevertName,
e2etests.TestV2ERC20DepositAndCallRevertWithCallName,
e2etests.TestV2ERC20WithdrawAndCallRevertName,
e2etests.TestV2ERC20WithdrawAndCallRevertWithCallName,
),
)
//// Test happy paths for erc20 token workflow
//eg.Go(v2TestRoutine(conf, "erc20", conf.AdditionalAccounts.UserV2ERC20, color.FgHiBlue, deployerRunner, verbose,
// e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
// e2etests.TestV2ERC20DepositName,
// e2etests.TestV2ERC20DepositAndCallName,
// e2etests.TestV2ERC20WithdrawName,
// e2etests.TestV2ERC20WithdrawAndArbitraryCallName,
// e2etests.TestV2ERC20WithdrawAndCallName,
// e2etests.TestV2ERC20DepositAndCallNoMessageName,
//))
//
//// Test revert cases for gas token workflow
//eg.Go(
// v2TestRoutine(
// conf,
// "eth-revert",
// conf.AdditionalAccounts.UserV2EtherRevert,
// color.FgHiYellow,
// deployerRunner,
// verbose,
// e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM and withdraw
// e2etests.TestV2ETHDepositAndCallRevertName,
// e2etests.TestV2ETHDepositAndCallRevertWithCallName,
// e2etests.TestV2ETHWithdrawAndCallRevertName,
// e2etests.TestV2ETHWithdrawAndCallRevertWithCallName,
// ),
//)
//
//// Test revert cases for erc20 token workflow
//eg.Go(
// v2TestRoutine(
// conf,
// "erc20-revert",
// conf.AdditionalAccounts.UserV2ERC20Revert,
// color.FgHiRed,
// deployerRunner,
// verbose,
// e2etests.TestV2ETHDepositName, // necessary to pay fees on ZEVM
// e2etests.TestV2ERC20DepositName, // necessary to have assets to withdraw
// e2etests.TestOperationAddLiquidityETHName, // liquidity with gas and ERC20 are necessary for reverts
// e2etests.TestOperationAddLiquidityERC20Name,
// e2etests.TestV2ERC20DepositAndCallRevertName,
// e2etests.TestV2ERC20DepositAndCallRevertWithCallName,
// e2etests.TestV2ERC20WithdrawAndCallRevertName,
// e2etests.TestV2ERC20WithdrawAndCallRevertWithCallName,
// ),
//)
}

// v2TestRoutine runs v2 related e2e tests
Expand Down
9 changes: 9 additions & 0 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const (
TestV2ETHDepositName = "v2_eth_deposit"
TestV2ETHDepositAndCallName = "v2_eth_deposit_and_call"
TestV2ETHDepositAndCallNoMessageName = "v2_eth_deposit_and_call_no_message"
TestDepositAndWithdrawName = "deposit_and_withdraw"
TestV2ETHDepositAndCallRevertName = "v2_eth_deposit_and_call_revert"
TestV2ETHDepositAndCallRevertWithCallName = "v2_eth_deposit_and_call_revert_with_call"
TestV2ETHWithdrawName = "v2_eth_withdraw"
Expand Down Expand Up @@ -824,6 +825,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestV2ETHDepositAndCallNoMessage,
),
runner.NewE2ETest(
TestDepositAndWithdrawName,
"makes a depositAndCall that trigger a withdrawal to the origin chain",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
},
TestDepositAndWithdraw,
),
runner.NewE2ETest(
TestV2ETHDepositAndCallRevertName,
"deposit Ether into ZEVM and call a contract using V2 contract that reverts",
Expand Down
37 changes: 37 additions & 0 deletions e2e/e2etests/test_deposit_and_withdraw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package e2etests

import (
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/v2/pkg/gatewayevm.sol"

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

// TestDepositAndWithdraw makes a depositAndCall that trigger a withdrawal to the origin chain
func TestDepositAndWithdraw(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")

withdrawMessage, err := r.TestDAppV2ZEVM.WITHDRAW(&bind.CallOpts{})
require.NoError(r, err)

// perform the deposit and call to the TestDAppV2ZEVMAddr
tx := r.V2ETHDepositAndCall(
r.TestDAppV2ZEVMAddr,
amount,
[]byte(withdrawMessage),
gatewayevm.RevertOptions{OnRevertGasLimit: big.NewInt(0)},
)

// wait for the cctx to be mined
cctx := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctx, "deposit")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctx.CctxStatus.Status)
}

0 comments on commit b638cc5

Please sign in to comment.