Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
lumtis committed Mar 3, 2025
1 parent 822722f commit 9bd5f77
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
50 changes: 50 additions & 0 deletions x/crosschain/keeper/cctx_gateway_zevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 9 additions & 5 deletions zetaclient/chains/bitcoin/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -181,21 +182,23 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) {
"5a0110032d07a9cbd57dcca3e2cf966c88bc874445b6e3b60d68656c6c6f207361746f736869",
),
},
observationStatus: crosschaintypes.InboundStatus_SUCCESS,
},
{
name: "should return vote for legacy memo",
event: &observer.BTCInboundEvent{
// 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",
Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 9bd5f77

Please sign in to comment.