Skip to content

Commit

Permalink
Merge branch 'develop' into unify-docker-images
Browse files Browse the repository at this point in the history
  • Loading branch information
gzukel authored May 13, 2024
2 parents eb1d29e + dd4ca91 commit 01a7b2b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
* [2059](https://github.com/zeta-chain/node/pull/2059) - Remove unused params from all functions in zetanode
* [2071](https://github.com/zeta-chain/node/pull/2071) - Modify chains struct to add all chain related information
* [2076](https://github.com/zeta-chain/node/pull/2076) - automatically deposit native zeta to an address if it doesn't exist on ZEVM.
* [2169](https://github.com/zeta-chain/node/pull/2169) - Limit zEVM revert transactions to coin type ZETA

### Features

Expand Down
27 changes: 27 additions & 0 deletions x/crosschain/keeper/process_outbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,33 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) {
require.Equal(t, cctx.GetCurrentOutTxParam().TxFinalizationStatus, types.TxFinalizationStatus_Executed)
})

t.Run("set failed zevm outbound of cointype ERC20 to aborted", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
cctx := sample.CrossChainTx(t, "test")
cctx.InboundTxParams.CoinType = coin.CoinType_ERC20
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
err := k.ProcessFailedOutbound(ctx, cctx, sample.String())
require.NoError(t, err)
require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_Aborted)
require.Equal(t, cctx.GetCurrentOutTxParam().TxFinalizationStatus, types.TxFinalizationStatus_Executed)
})

t.Run("set failed zevm outbound of cointype Gas to aborted", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
cctx := sample.CrossChainTx(t, "test")
cctx.InboundTxParams.CoinType = coin.CoinType_Gas
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
err := k.ProcessFailedOutbound(ctx, cctx, sample.String())
require.NoError(t, err)
require.Equal(t, cctx.CctxStatus.Status, types.CctxStatus_Aborted)
require.Equal(t, cctx.GetCurrentOutTxParam().TxFinalizationStatus, types.TxFinalizationStatus_Executed)
})

t.Run("successfully process failed outbound if original sender is a address", func(t *testing.T) {
k, ctx, sdkk, _ := keepertest.CrosschainKeeper(t)
receiver := sample.EthAddress()
cctx := GetERC20Cctx(t, receiver, chains.GoerliChain, "", big.NewInt(42))
cctx.InboundTxParams.CoinType = coin.CoinType_Zeta
err := sdkk.EvmKeeper.SetAccount(ctx, ethcommon.HexToAddress(cctx.InboundTxParams.Sender), *statedb.NewEmptyAccount())
require.NoError(t, err)
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
Expand All @@ -63,6 +86,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
receiver := sample.EthAddress()
cctx := GetERC20Cctx(t, receiver, chains.GoerliChain, "", big.NewInt(42))
cctx.InboundTxParams.CoinType = coin.CoinType_Zeta
cctx.Index = ""
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
err := k.ProcessFailedOutbound(ctx, cctx, sample.String())
Expand All @@ -73,6 +97,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
cctx := sample.CrossChainTx(t, "test")
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
cctx.InboundTxParams.CoinType = coin.CoinType_Zeta
err := k.ProcessFailedOutbound(ctx, cctx, sample.String())
require.ErrorContains(t, err, "failed AddRevertOutbound")
})
Expand All @@ -85,6 +110,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) {
receiver := sample.EthAddress()
errorFailedZETARevertAndCallContract := errors.New("test", 999, "failed ZETARevertAndCallContract")
cctx := GetERC20Cctx(t, receiver, chains.GoerliChain, "", big.NewInt(42))
cctx.InboundTxParams.CoinType = coin.CoinType_Zeta
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet.ChainId
fungibleMock.On("ZETARevertAndCallContract", mock.Anything,
ethcommon.HexToAddress(cctx.InboundTxParams.Sender),
Expand All @@ -103,6 +129,7 @@ func TestKeeper_ProcessFailedOutbound(t *testing.T) {
_ = zk.FungibleKeeper.GetAuthKeeper().GetModuleAccount(ctx, fungibletypes.ModuleName)

cctx := GetERC20Cctx(t, sample.EthAddress(), chains.GoerliChain, "", big.NewInt(42))
cctx.InboundTxParams.CoinType = coin.CoinType_Zeta
cctx.RelayedMessage = base64.StdEncoding.EncodeToString([]byte("sample message"))

deploySystemContracts(t, ctx, zk.FungibleKeeper, sdkk.EvmKeeper)
Expand Down
18 changes: 15 additions & 3 deletions x/crosschain/keeper/processs_outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,21 @@ func (k Keeper) ProcessFailedOutbound(ctx sdk.Context, cctx *types.CrossChainTx,
cctx.GetCurrentOutTxParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("Outbound failed")
} else if chains.IsZetaChain(cctx.InboundTxParams.SenderChainId) {
err := k.processFailedOutboundForZEVMTx(ctx, cctx)
if err != nil {
return cosmoserrors.Wrap(err, "ProcessFailedOutboundForZEVMTx")
switch cctx.InboundTxParams.CoinType {
// Try revert if the coin-type is ZETA
case coin.CoinType_Zeta:
{
err := k.processFailedOutboundForZEVMTx(ctx, cctx)
if err != nil {
return cosmoserrors.Wrap(err, "ProcessFailedOutboundForZEVMTx")
}
}
// For all other coin-types, we do not revert, the cctx is aborted
default:
{
cctx.GetCurrentOutTxParam().TxFinalizationStatus = types.TxFinalizationStatus_Executed
cctx.SetAbort("Outbound failed")
}
}
} else {
err := k.processFailedOutBoundForExternalChainTx(ctx, cctx, oldStatus)
Expand Down

0 comments on commit 01a7b2b

Please sign in to comment.