From 9bd5f7779b73f459c135272abc3a790c224d2153 Mon Sep 17 00:00:00 2001 From: lumtis Date: Mon, 3 Mar 2025 13:05:07 +0100 Subject: [PATCH] fix unit test --- x/crosschain/keeper/cctx_gateway_zevm_test.go | 50 +++++++++++++++++++ .../chains/bitcoin/observer/inbound_test.go | 14 ++++-- 2 files changed, 59 insertions(+), 5 deletions(-) diff --git a/x/crosschain/keeper/cctx_gateway_zevm_test.go b/x/crosschain/keeper/cctx_gateway_zevm_test.go index 8a526a7884..d7e8f76902 100644 --- a/x/crosschain/keeper/cctx_gateway_zevm_test.go +++ b/x/crosschain/keeper/cctx_gateway_zevm_test.go @@ -82,6 +82,56 @@ func TestKeeper_InitiateOutboundZEVM(t *testing.T) { require.Equal(t, types.CctxStatus_Aborted, newStatus) }) + t.Run("should return aborted status on unknown inbound status", func(t *testing.T) { + // ARRANGE + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseFungibleMock: true, + }) + gatewayZEVM := keeper.NewCCTXGatewayZEVM(*k) + + // mock up CCTX data + cctx := sample.CrossChainTx(t, "test") + cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingOutbound} + cctx.InboundParams.Status = types.InboundStatus(1000) + + // ACT + // call InitiateOutbound + newStatus, err := gatewayZEVM.InitiateOutbound( + ctx, + keeper.InitiateOutboundConfig{CCTX: cctx, ShouldPayGas: true}, + ) + + // ASSERT + require.NoError(t, err) + require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status) + require.Equal(t, types.CctxStatus_Aborted, newStatus) + }) + + //t.Run("should return reverted status on invalid memo inbound status", func(t *testing.T) { + // // ARRANGE + // k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + // UseFungibleMock: true, + // }) + // gatewayZEVM := keeper.NewCCTXGatewayZEVM(*k) + // + // // mock up CCTX data + // cctx := sample.CrossChainTx(t, "test") + // cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingOutbound} + // cctx.InboundParams.Status = types.InboundStatus_INVALID_MEMO + // + // // ACT + // // call InitiateOutbound + // newStatus, err := gatewayZEVM.InitiateOutbound( + // ctx, + // keeper.InitiateOutboundConfig{CCTX: cctx, ShouldPayGas: true}, + // ) + // + // // ASSERT + // require.NoError(t, err) + // require.Equal(t, types.CctxStatus_Reverted, cctx.CctxStatus.Status) + // require.Equal(t, types.CctxStatus_Reverted, newStatus) + //}) + t.Run( "should return aborted status on 'error during deposit that is not smart contract revert'", func(t *testing.T) { diff --git a/zetaclient/chains/bitcoin/observer/inbound_test.go b/zetaclient/chains/bitcoin/observer/inbound_test.go index 6236bf22c3..0c2d70a343 100644 --- a/zetaclient/chains/bitcoin/observer/inbound_test.go +++ b/zetaclient/chains/bitcoin/observer/inbound_test.go @@ -167,9 +167,10 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) { // test cases tests := []struct { - name string - event *observer.BTCInboundEvent - nilVote bool + name string + event *observer.BTCInboundEvent + observationStatus crosschaintypes.InboundStatus + nilVote bool }{ { name: "should return vote for standard memo", @@ -181,6 +182,7 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) { "5a0110032d07a9cbd57dcca3e2cf966c88bc874445b6e3b60d68656c6c6f207361746f736869", ), }, + observationStatus: crosschaintypes.InboundStatus_SUCCESS, }, { name: "should return vote for legacy memo", @@ -188,14 +190,15 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) { // raw address + payload MemoBytes: testutil.HexToBytes(t, "2d07a9cbd57dcca3e2cf966c88bc874445b6e3b668656c6c6f207361746f736869"), }, + observationStatus: crosschaintypes.InboundStatus_SUCCESS, }, { - name: "should return nil if unable to decode memo", + name: "should return vote for invalid memo", event: &observer.BTCInboundEvent{ // standard memo that carries payload only, receiver address is empty MemoBytes: testutil.HexToBytes(t, "5a0110020d68656c6c6f207361746f736869"), }, - nilVote: true, + observationStatus: crosschaintypes.InboundStatus_INVALID_MEMO, }, { name: "should return nil on donation message", @@ -221,6 +224,7 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) { require.Nil(t, msg) } else { require.NotNil(t, msg) + require.EqualValues(t, tt.observationStatus, msg.Status) } }) }