Skip to content

Commit

Permalink
fix(crosschain): add support to perform withdraws in ZetaChain `onR…
Browse files Browse the repository at this point in the history
…evert` call (#3348)

* update contracts

* add revert and withdraw test

* add tx response to revert deposit

* process withdraw

* tests

* add withdraw and revert check in test

* comment lint

* add tests back

* update changelog

* add unit tests

* fix test

* update condition

* fix lint
  • Loading branch information
lumtis authored Jan 22, 2025
1 parent aabb271 commit 13d1673
Show file tree
Hide file tree
Showing 14 changed files with 454 additions and 61 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Fixes

* [3374](https://github.com/zeta-chain/node/pull/3374) - remove minimum rent exempt check for SPL token withdrawals
* [3348](https://github.com/zeta-chain/node/pull/3348) - add support to perform withdraws in ZetaChain `onRevert` call

## v25.0.0

Expand Down
1 change: 1 addition & 0 deletions cmd/zetae2e/local/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ func startEVMTests(eg *errgroup.Group, conf config.Config, deployerRunner *runne
e2etests.TestETHDepositAndCallRevertWithCallName,
e2etests.TestETHWithdrawAndCallRevertName,
e2etests.TestETHWithdrawAndCallRevertWithCallName,
e2etests.TestETHWithdrawAndCallRevertWithWithdrawName,
e2etests.TestDepositAndCallOutOfGasName,
),
)
Expand Down
71 changes: 40 additions & 31 deletions e2e/e2etests/e2etests.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,38 @@ const (
/*
EVM chain tests
*/
TestETHDepositName = "eth_deposit"
TestETHDepositAndCallName = "eth_deposit_and_call"
TestETHDepositAndCallNoMessageName = "eth_deposit_and_call_no_message"
TestETHDepositAndCallRevertName = "eth_deposit_and_call_revert"
TestETHDepositAndCallRevertWithCallName = "eth_deposit_and_call_revert_with_call"
TestETHWithdrawName = "eth_withdraw"
TestETHWithdrawAndArbitraryCallName = "eth_withdraw_and_arbitrary_call"
TestETHWithdrawAndCallName = "eth_withdraw_and_call"
TestETHWithdrawAndCallNoMessageName = "eth_withdraw_and_call_no_message"
TestETHWithdrawAndCallThroughContractName = "eth_withdraw_and_call_through_contract"
TestETHWithdrawAndCallRevertName = "eth_withdraw_and_call_revert"
TestETHWithdrawAndCallRevertWithCallName = "eth_withdraw_and_call_revert_with_call"
TestDepositAndCallOutOfGasName = "deposit_and_call_out_of_gas"
TestERC20DepositName = "erc20_deposit"
TestERC20DepositAndCallName = "erc20_deposit_and_call"
TestERC20DepositAndCallNoMessageName = "erc20_deposit_and_call_no_message"
TestERC20DepositAndCallRevertName = "erc20_deposit_and_call_revert"
TestERC20DepositAndCallRevertWithCallName = "erc20_deposit_and_call_revert_with_call"
TestERC20WithdrawName = "erc20_withdraw"
TestERC20WithdrawAndArbitraryCallName = "erc20_withdraw_and_arbitrary_call"
TestERC20WithdrawAndCallName = "erc20_withdraw_and_call"
TestERC20WithdrawAndCallNoMessageName = "erc20_withdraw_and_call_no_message"
TestERC20WithdrawAndCallRevertName = "erc20_withdraw_and_call_revert"
TestERC20WithdrawAndCallRevertWithCallName = "erc20_withdraw_and_call_revert_with_call"
TestZEVMToEVMArbitraryCallName = "zevm_to_evm_arbitrary_call"
TestZEVMToEVMCallName = "zevm_to_evm_call"
TestZEVMToEVMCallThroughContractName = "zevm_to_evm_call_through_contract"
TestEVMToZEVMCallName = "evm_to_zevm_call"
TestDepositAndCallSwapName = "deposit_and_call_swap"
TestEtherWithdrawRestrictedName = "eth_withdraw_restricted"
TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential
TestETHDepositName = "eth_deposit"
TestETHDepositAndCallName = "eth_deposit_and_call"
TestETHDepositAndCallNoMessageName = "eth_deposit_and_call_no_message"
TestETHDepositAndCallRevertName = "eth_deposit_and_call_revert"
TestETHDepositAndCallRevertWithCallName = "eth_deposit_and_call_revert_with_call"
TestETHWithdrawName = "eth_withdraw"
TestETHWithdrawAndArbitraryCallName = "eth_withdraw_and_arbitrary_call"
TestETHWithdrawAndCallName = "eth_withdraw_and_call"
TestETHWithdrawAndCallNoMessageName = "eth_withdraw_and_call_no_message"
TestETHWithdrawAndCallThroughContractName = "eth_withdraw_and_call_through_contract"
TestETHWithdrawAndCallRevertName = "eth_withdraw_and_call_revert"
TestETHWithdrawAndCallRevertWithCallName = "eth_withdraw_and_call_revert_with_call"
TestETHWithdrawAndCallRevertWithWithdrawName = "eth_withdraw_and_call_revert_with_withdraw"
TestDepositAndCallOutOfGasName = "deposit_and_call_out_of_gas"
TestERC20DepositName = "erc20_deposit"
TestERC20DepositAndCallName = "erc20_deposit_and_call"
TestERC20DepositAndCallNoMessageName = "erc20_deposit_and_call_no_message"
TestERC20DepositAndCallRevertName = "erc20_deposit_and_call_revert"
TestERC20DepositAndCallRevertWithCallName = "erc20_deposit_and_call_revert_with_call"
TestERC20WithdrawName = "erc20_withdraw"
TestERC20WithdrawAndArbitraryCallName = "erc20_withdraw_and_arbitrary_call"
TestERC20WithdrawAndCallName = "erc20_withdraw_and_call"
TestERC20WithdrawAndCallNoMessageName = "erc20_withdraw_and_call_no_message"
TestERC20WithdrawAndCallRevertName = "erc20_withdraw_and_call_revert"
TestERC20WithdrawAndCallRevertWithCallName = "erc20_withdraw_and_call_revert_with_call"
TestZEVMToEVMArbitraryCallName = "zevm_to_evm_arbitrary_call"
TestZEVMToEVMCallName = "zevm_to_evm_call"
TestZEVMToEVMCallThroughContractName = "zevm_to_evm_call_through_contract"
TestEVMToZEVMCallName = "evm_to_zevm_call"
TestDepositAndCallSwapName = "deposit_and_call_swap"
TestEtherWithdrawRestrictedName = "eth_withdraw_restricted"
TestERC20DepositRestrictedName = "erc20_deposit_restricted" // #nosec G101: Potential hardcoded credentials (gosec), not a credential

/*
* Solana tests
Expand Down Expand Up @@ -295,6 +296,14 @@ var AllE2ETests = []runner.E2ETest{
},
TestETHWithdrawAndCallRevertWithCall,
),
runner.NewE2ETest(
TestETHWithdrawAndCallRevertWithWithdrawName,
"withdraw Ether from ZEVM and call a contract that reverts with a onRevert call that triggers a withdraw",
[]runner.ArgDefinition{
{Description: "amount in wei", DefaultValue: "10000000000000000"},
},
TestETHWithdrawAndCallRevertWithWithdraw,
),
runner.NewE2ETest(
TestDepositAndCallOutOfGasName,
"deposit Ether into ZEVM and call a contract that runs out of gas",
Expand Down
49 changes: 49 additions & 0 deletions e2e/e2etests/test_eth_withdraw_and_call_revert_with_withdraw.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package e2etests

import (
"math/big"

"github.com/stretchr/testify/require"
"github.com/zeta-chain/protocol-contracts/pkg/gatewayzevm.sol"

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

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

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

r.ApproveETHZRC20(r.GatewayZEVMAddr)

// perform the withdraw
tx := r.ETHWithdrawAndArbitraryCall(
r.TestDAppV2EVMAddr,
amount,
r.EncodeGasCall("revert"),
gatewayzevm.RevertOptions{
RevertAddress: r.TestDAppV2ZEVMAddr,
CallOnRevert: true,
RevertMessage: []byte("withdraw"), // call withdraw in the onRevert hook
OnRevertGasLimit: big.NewInt(0),
},
)

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

cctxWithdrawFromRevert := utils.WaitCctxMinedByInboundHash(
r.Ctx,
cctxRevert.Index,
r.CctxClient,
r.Logger,
r.CctxTimeout,
)

// check the cctx status
utils.RequireCCTXStatus(r, cctxWithdrawFromRevert, crosschaintypes.CctxStatus_OutboundMined)
}
Loading

0 comments on commit 13d1673

Please sign in to comment.