Skip to content

Commit

Permalink
test: increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Aug 29, 2023
1 parent b921a2f commit 0ab9ebb
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 3 deletions.
5 changes: 4 additions & 1 deletion x/tokenfactory/keeper/before_send_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ func (s *KeeperTestSuite) TestBeforeSendHook() {
s.Require().NoError(err)

// set beforesend hook to the new denom
_, err = s.msgServer.SetBeforeSendHook(sdk.WrapSDKContext(s.Ctx), types.NewMsgSetBeforeSendHook(s.TestAccs[0].String(), denom, cosmwasmAddress.String()))
msg := types.NewMsgSetBeforeSendHook(s.TestAccs[0].String(), denom, cosmwasmAddress.String())
err = msg.ValidateBasic()
s.Require().NoError(err, "test: %v", tc.desc)
_, err = s.msgServer.SetBeforeSendHook(sdk.WrapSDKContext(s.Ctx), msg)
s.Require().NoError(err, "test: %v", tc.desc)

for _, sendTc := range tc.sendMsgs {
Expand Down
40 changes: 40 additions & 0 deletions x/tokenfactory/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package keeper_test

import "github.com/terra-money/core/v2/x/tokenfactory/types"

func (s *KeeperTestSuite) TestQueryParams() {
params, err := s.App.TokenFactoryKeeper.Params(s.Ctx, &types.QueryParamsRequest{})

s.Require().NoError(err)

expected := types.QueryParamsResponse{
Params: s.App.TokenFactoryKeeper.GetParams(s.Ctx),
}
s.Require().Equal(&expected, params)

}

func (s *KeeperTestSuite) TestQueryBeforeSendHookEmptyAddress() {
res, err := s.App.TokenFactoryKeeper.BeforeSendHookAddress(s.Ctx, &types.QueryBeforeSendHookAddressRequest{})

s.Require().NoError(err)

expected := types.QueryBeforeSendHookAddressResponse{
CosmwasmAddress: "",
}
s.Require().Equal(&expected, res)

}

func (s *KeeperTestSuite) TestQueryBeforeSendHookNonRegisteredAddress() {
res, err := s.App.TokenFactoryKeeper.BeforeSendHookAddress(s.Ctx, &types.QueryBeforeSendHookAddressRequest{
Denom: "bitcoin",
})
s.Require().NoError(err)

expected := types.QueryBeforeSendHookAddressResponse{
CosmwasmAddress: "",
}
s.Require().Equal(&expected, res)

}
8 changes: 6 additions & 2 deletions x/tokenfactory/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ func (s *KeeperTestSuite) TestForceTransferMsg() {
s.Run(fmt.Sprintf("Case %s", tc.desc), func() {
ctx := s.Ctx.WithEventManager(sdk.NewEventManager())
s.Require().Equal(0, len(ctx.EventManager().Events()))
// Test mint message
_, err := s.msgServer.ForceTransfer(ctx, types.NewMsgForceTransfer(tc.admin, sdk.NewInt64Coin(defaultDenom, tc.amount), tc.admin, tc.transferTo))
// Test force transfer message
msg := types.NewMsgForceTransfer(tc.admin, sdk.NewInt64Coin(defaultDenom, tc.amount), tc.admin, tc.transferTo)
err := msg.ValidateBasic()
s.Require().NoError(err)

_, err = s.msgServer.ForceTransfer(ctx, msg)
if tc.valid {
s.Require().NoError(err)
} else {
Expand Down
4 changes: 4 additions & 0 deletions x/tokenfactory/types/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import (

"github.com/stretchr/testify/require"

appparams "github.com/terra-money/core/v2/app/params"
"github.com/terra-money/core/v2/x/tokenfactory/types"
)

func TestGenesisState_Validate(t *testing.T) {
types.DefaultGenesis()
appparams.RegisterAddressesConfig()

for _, tc := range []struct {
desc string
genState *types.GenesisState
Expand Down
19 changes: 19 additions & 0 deletions x/tokenfactory/types/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package types_test

import (
"testing"

"github.com/stretchr/testify/require"

"github.com/terra-money/core/v2/x/tokenfactory/types"
)

func TestKeys(t *testing.T) {
denom_key := types.GetDenomPrefixStore("denom")
creator_key := types.GetCreatorPrefix("creator")
creator_prefix_key := types.GetCreatorsPrefix()

require.Equal(t, []byte("denoms|denom|"), denom_key)
require.Equal(t, []byte("creator|creator|"), creator_key)
require.Equal(t, []byte("creator|"), creator_prefix_key)
}
27 changes: 27 additions & 0 deletions x/tokenfactory/types/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package types_test

import (
"testing"

"cosmossdk.io/math"
"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/terra-money/core/v2/x/tokenfactory/types"
)

func TestCreateNewParms(t *testing.T) {
// Creaate new params
params := types.NewParams(sdk.NewCoins(sdk.NewCoin("uluna", math.NewInt(100000))), 10)
new_expected_params := types.Params{
DenomCreationFee: sdk.NewCoins(sdk.NewCoin("uluna", math.NewInt(100000))),
DenomCreationGasConsume: 10,
}
require.Equal(t, new_expected_params, params)

// Validate params set creation and validate they are different than the default
paramSetPairs := params.ParamSetPairs()
require.Equal(t, 2, len(paramSetPairs))
defaultKeyTable := types.ParamKeyTable()
require.NotEqual(t, defaultKeyTable, paramSetPairs)
}

0 comments on commit 0ab9ebb

Please sign in to comment.