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 1, 2024
1 parent d477dba commit 33f7fc2
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 2 deletions.
20 changes: 20 additions & 0 deletions x/crosschain/keeper/foreign_coins_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/testutil/sample"
)

func TestKeeper_GetAllForeignCoins(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
fc := sample.ForeignCoins(t, sample.EthAddress().Hex())
fc.ForeignChainId = 101
k.GetFungibleKeeper().SetForeignCoins(ctx, fc)

res, err := k.GetAllForeignCoins(ctx)
require.NoError(t, err)
require.Equal(t, 1, len(res))
}
2 changes: 1 addition & 1 deletion x/crosschain/keeper/grpc_query_last_zeta_height_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestKeeper_LastZetaHeight(t *testing.T) {
t.Run("should error if height less than zero", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
ctx = ctx.WithBlockHeight(-1)
res, err := k.LastZetaHeight(ctx, nil)
res, err := k.LastZetaHeight(ctx, &types.QueryLastZetaHeightRequest{})
require.Error(t, err)
require.Nil(t, res)
})
Expand Down
10 changes: 10 additions & 0 deletions x/crosschain/keeper/grpc_query_out_tx_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ func TestKeeper_OutTxTracker(t *testing.T) {
require.Nil(t, res)
})

t.Run("should return if not found", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
res, err := k.OutTxTracker(ctx, &types.QueryGetOutTxTrackerRequest{
ChainID: 1,
Nonce: 1,
})
require.Error(t, err)
require.Nil(t, res)
})

t.Run("should return if req is not nil", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
k.SetOutTxTracker(ctx, types.OutTxTracker{
Expand Down
34 changes: 34 additions & 0 deletions x/crosschain/keeper/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package keeper_test

import (
"testing"

"github.com/stretchr/testify/require"
keepertest "github.com/zeta-chain/zetacore/testutil/keeper"
"github.com/zeta-chain/zetacore/x/crosschain/types"
)

func TestKeeper_GetParams(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
params := k.GetParams(ctx)
// TODO: there is no get params method?
k.SetParams(ctx, types.Params{Enabled: false})
require.Equal(t, types.NewParams(), params)
require.True(t, params.Enabled)
}

func TestKeeper_QueryParams(t *testing.T) {
t.Run("should error if req is nil", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
res, err := k.Params(ctx, nil)
require.Error(t, err)
require.Nil(t, res)
})

t.Run("should return params", func(t *testing.T) {
k, ctx, _, _ := keepertest.CrosschainKeeper(t)
res, err := k.Params(ctx, &types.QueryParamsRequest{})
require.NoError(t, err)
require.True(t, res.Params.Enabled)
})
}
Loading

0 comments on commit 33f7fc2

Please sign in to comment.