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): add deposit and withdraw test #3114

Closed
wants to merge 19 commits into from
125 changes: 63 additions & 62 deletions cmd/zetae2e/local/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,69 +16,70 @@ 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,
e2etests.TestV2ERC20WithdrawAndCallNoMessageName,
))

// 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,
e2etests.TestDepositAndCallOutOfGasName,
),
)

// 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,
// e2etests.TestV2ERC20WithdrawAndCallNoMessageName,
//))
//
//// 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,
// e2etests.TestDepositAndCallOutOfGasName,
// ),
//)
//
//// 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 @@ -142,6 +142,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 @@ -843,6 +844,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
46 changes: 46 additions & 0 deletions e2e/e2etests/test_deposit_and_withdraw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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
cctxDeposit := utils.WaitCctxMinedByInboundHash(r.Ctx, tx.Hash().Hex(), r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctxDeposit, "deposit")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctxDeposit.CctxStatus.Status)

gasleft, err := r.TestDAppV2ZEVM.GetAmountWithMessage(&bind.CallOpts{}, "gasleft")
require.NoError(r, err)
r.Logger.Print("gasleft: %s", gasleft)

// first cctx should trigger a new cctx for the withdrawal
cctxWithdraw := utils.WaitCctxMinedByInboundHash(r.Ctx, cctxDeposit.Index, r.CctxClient, r.Logger, r.CctxTimeout)
r.Logger.CCTX(*cctxWithdraw, "withdraw")
require.Equal(r, crosschaintypes.CctxStatus_OutboundMined, cctxWithdraw.CctxStatus.Status)
}
42 changes: 37 additions & 5 deletions pkg/contracts/testdappv2/TestDAppV2.abi
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
[
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "",
"type": "string"
},
{
"indexed": false,
"internalType": "string",
"name": "",
"type": "string"
}
],
"name": "HelloEvent",
"type": "event"
},
{
"inputs": [],
"name": "NO_MESSAGE_CALL",
Expand All @@ -12,6 +31,19 @@
"stateMutability": "view",
"type": "function"
},
{
"inputs": [],
"name": "WITHDRAW",
"outputs": [
{
"internalType": "string",
"name": "",
"type": "string"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
Expand Down Expand Up @@ -163,13 +195,13 @@
"type": "uint256"
}
],
"internalType": "struct TestDAppV2.zContext",
"name": "_context",
"internalType": "struct zContext",
"name": "context",
"type": "tuple"
},
{
"internalType": "address",
"name": "_zrc20",
"name": "zrc20",
"type": "address"
},
{
Expand Down Expand Up @@ -198,7 +230,7 @@
"type": "address"
}
],
"internalType": "struct TestDAppV2.MessageContext",
"internalType": "struct MessageContext",
"name": "messageContext",
"type": "tuple"
},
Expand Down Expand Up @@ -244,7 +276,7 @@
"type": "bytes"
}
],
"internalType": "struct TestDAppV2.RevertContext",
"internalType": "struct RevertContext",
"name": "revertContext",
"type": "tuple"
}
Expand Down
Loading
Loading