From 807d644516a5799a7a1337564c21dda67fe076d3 Mon Sep 17 00:00:00 2001 From: skosito Date: Tue, 2 Apr 2024 16:32:01 +0200 Subject: [PATCH] Add more tests --- .../keeper/msg_server_vote_inbound_tx_test.go | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go index 25d5615056..7f6baadfb8 100644 --- a/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go +++ b/x/crosschain/keeper/msg_server_vote_inbound_tx_test.go @@ -2,12 +2,14 @@ package keeper_test import ( "encoding/hex" + "errors" "math/big" "testing" sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" ethcommon "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" "github.com/zeta-chain/zetacore/pkg/chains" "github.com/zeta-chain/zetacore/pkg/coin" @@ -160,6 +162,64 @@ func TestKeeper_VoteOnObservedInboundTx(t *testing.T) { _, found = zk.ObserverKeeper.GetBallot(ctx, msg2.Digest()) require.False(t, found) }) + + t.Run("should error if vote on inbound ballot fails", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseObserverMock: true, + }) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("VoteOnInboundBallot", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(true, false, errors.New("err")) + msgServer := keeper.NewMsgServerImpl(*k) + to, from := int64(1337), int64(101) + + msg := sample.InboundVote(0, from, to) + res, err := msgServer.VoteOnObservedInboundTx( + ctx, + &msg, + ) + require.Error(t, err) + require.Nil(t, res) + }) + + t.Run("should return if not finalized", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseObserverMock: true, + }) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("VoteOnInboundBallot", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(false, false, nil) + msgServer := keeper.NewMsgServerImpl(*k) + to, from := int64(1337), int64(101) + + msg := sample.InboundVote(0, from, to) + res, err := msgServer.VoteOnObservedInboundTx( + ctx, + &msg, + ) + require.NoError(t, err) + require.Empty(t, res) + }) + + t.Run("should err if tss not found", func(t *testing.T) { + k, ctx, _, _ := keepertest.CrosschainKeeperWithMocks(t, keepertest.CrosschainMockOptions{ + UseObserverMock: true, + }) + observerMock := keepertest.GetCrosschainObserverMock(t, k) + observerMock.On("VoteOnInboundBallot", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything). + Return(true, false, nil) + observerMock.On("GetTSS", mock.Anything).Return(observertypes.TSS{}, false) + msgServer := keeper.NewMsgServerImpl(*k) + to, from := int64(1337), int64(101) + + msg := sample.InboundVote(0, from, to) + res, err := msgServer.VoteOnObservedInboundTx( + ctx, + &msg, + ) + require.Error(t, err) + require.Nil(t, res) + }) } func TestStatus_ChangeStatus(t *testing.T) {