Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed May 12, 2024
1 parent 7c73040 commit 88e93b2
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 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("successfully process failed outbound set to aborted for type zevm tx of cointype ERC20", 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("successfully process failed outbound set to aborted for type zevm tx of cointype Gas", 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,8 @@ 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.CoinType = coin.CoinType_Zeta
cctx.InboundTxParams.SenderChainId = chains.ZetaChainMainnet().ChainId
fungibleMock.On("ZETARevertAndCallContract", mock.Anything,
ethcommon.HexToAddress(cctx.InboundTxParams.Sender),
Expand All @@ -103,6 +130,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

0 comments on commit 88e93b2

Please sign in to comment.