Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Apr 2, 2024
1 parent 165eefe commit 807d644
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions x/crosschain/keeper/msg_server_vote_inbound_tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 807d644

Please sign in to comment.