Skip to content

Commit 9bd5f77

Browse files
committed
fix unit test
1 parent 822722f commit 9bd5f77

File tree

2 files changed

+59
-5
lines changed

2 files changed

+59
-5
lines changed

x/crosschain/keeper/cctx_gateway_zevm_test.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,56 @@ func TestKeeper_InitiateOutboundZEVM(t *testing.T) {
8282
require.Equal(t, types.CctxStatus_Aborted, newStatus)
8383
})
8484

85+
t.Run("should return aborted status on unknown inbound status", func(t *testing.T) {
86+
// ARRANGE
87+
k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
88+
UseFungibleMock: true,
89+
})
90+
gatewayZEVM := keeper.NewCCTXGatewayZEVM(*k)
91+
92+
// mock up CCTX data
93+
cctx := sample.CrossChainTx(t, "test")
94+
cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingOutbound}
95+
cctx.InboundParams.Status = types.InboundStatus(1000)
96+
97+
// ACT
98+
// call InitiateOutbound
99+
newStatus, err := gatewayZEVM.InitiateOutbound(
100+
ctx,
101+
keeper.InitiateOutboundConfig{CCTX: cctx, ShouldPayGas: true},
102+
)
103+
104+
// ASSERT
105+
require.NoError(t, err)
106+
require.Equal(t, types.CctxStatus_Aborted, cctx.CctxStatus.Status)
107+
require.Equal(t, types.CctxStatus_Aborted, newStatus)
108+
})
109+
110+
//t.Run("should return reverted status on invalid memo inbound status", func(t *testing.T) {
111+
// // ARRANGE
112+
// k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{
113+
// UseFungibleMock: true,
114+
// })
115+
// gatewayZEVM := keeper.NewCCTXGatewayZEVM(*k)
116+
//
117+
// // mock up CCTX data
118+
// cctx := sample.CrossChainTx(t, "test")
119+
// cctx.CctxStatus = &types.Status{Status: types.CctxStatus_PendingOutbound}
120+
// cctx.InboundParams.Status = types.InboundStatus_INVALID_MEMO
121+
//
122+
// // ACT
123+
// // call InitiateOutbound
124+
// newStatus, err := gatewayZEVM.InitiateOutbound(
125+
// ctx,
126+
// keeper.InitiateOutboundConfig{CCTX: cctx, ShouldPayGas: true},
127+
// )
128+
//
129+
// // ASSERT
130+
// require.NoError(t, err)
131+
// require.Equal(t, types.CctxStatus_Reverted, cctx.CctxStatus.Status)
132+
// require.Equal(t, types.CctxStatus_Reverted, newStatus)
133+
//})
134+
85135
t.Run(
86136
"should return aborted status on 'error during deposit that is not smart contract revert'",
87137
func(t *testing.T) {

zetaclient/chains/bitcoin/observer/inbound_test.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) {
167167

168168
// test cases
169169
tests := []struct {
170-
name string
171-
event *observer.BTCInboundEvent
172-
nilVote bool
170+
name string
171+
event *observer.BTCInboundEvent
172+
observationStatus crosschaintypes.InboundStatus
173+
nilVote bool
173174
}{
174175
{
175176
name: "should return vote for standard memo",
@@ -181,21 +182,23 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) {
181182
"5a0110032d07a9cbd57dcca3e2cf966c88bc874445b6e3b60d68656c6c6f207361746f736869",
182183
),
183184
},
185+
observationStatus: crosschaintypes.InboundStatus_SUCCESS,
184186
},
185187
{
186188
name: "should return vote for legacy memo",
187189
event: &observer.BTCInboundEvent{
188190
// raw address + payload
189191
MemoBytes: testutil.HexToBytes(t, "2d07a9cbd57dcca3e2cf966c88bc874445b6e3b668656c6c6f207361746f736869"),
190192
},
193+
observationStatus: crosschaintypes.InboundStatus_SUCCESS,
191194
},
192195
{
193-
name: "should return nil if unable to decode memo",
196+
name: "should return vote for invalid memo",
194197
event: &observer.BTCInboundEvent{
195198
// standard memo that carries payload only, receiver address is empty
196199
MemoBytes: testutil.HexToBytes(t, "5a0110020d68656c6c6f207361746f736869"),
197200
},
198-
nilVote: true,
201+
observationStatus: crosschaintypes.InboundStatus_INVALID_MEMO,
199202
},
200203
{
201204
name: "should return nil on donation message",
@@ -221,6 +224,7 @@ func Test_GetInboundVoteFromBtcEvent(t *testing.T) {
221224
require.Nil(t, msg)
222225
} else {
223226
require.NotNil(t, msg)
227+
require.EqualValues(t, tt.observationStatus, msg.Status)
224228
}
225229
})
226230
}

0 commit comments

Comments
 (0)