cosmos-sdk/x/slashing/keeper/querier_test.go
Robert Zaremba 8eaf2ececc
Refactor x/staking Validation and Delegation tests based on MsgCreateValidator.Pubkey type change. (#7526)
* testing: refactore Validation and Delegation handling of x/staking

This Changeset introduces set of improvements for writing tests.

The idea is to create a testing subpackage which will provide functions
to make tests more dev-friendly and wrap higher level use-cases.
Here is a show-up of of creating a service for staking module
for tests.

This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string
to types.Any. This change motivated the other change to show the pattern I'm describing here.

* add validator checks

* type change fixes

* use deprecated

* adding test slashing

* new network comment update

* working on tests

* Fix TestMsgPkDecode test

* Add UnpackInterfaces to MsgCreateValidator

* Fix tests

* Convert bech32 pubkey to proto

* Fix test

* fix v039/migrate_test/TestMigrate

* fix tests

* testslashing: rename Service to Helper

* file rename

* update TestMsgDecode

Co-authored-by: blushi <marie.gauthier63@gmail.com>
Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
2020-10-19 13:04:55 +00:00

57 lines
1.5 KiB
Go

package keeper_test
import (
"testing"
"github.com/stretchr/testify/require"
abci "github.com/tendermint/tendermint/abci/types"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
"github.com/cosmos/cosmos-sdk/x/slashing/testslashing"
"github.com/cosmos/cosmos-sdk/x/slashing/types"
)
func TestNewQuerier(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino())
querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc.LegacyAmino)
query := abci.RequestQuery{
Path: "",
Data: []byte{},
}
_, err := querier(ctx, []string{types.QueryParameters}, query)
require.NoError(t, err)
}
func TestQueryParams(t *testing.T) {
cdc := codec.NewLegacyAmino()
legacyQuerierCdc := codec.NewAminoCodec(cdc)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
app.SlashingKeeper.SetParams(ctx, testslashing.TestParams())
querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc.LegacyAmino)
query := abci.RequestQuery{
Path: "",
Data: []byte{},
}
var params types.Params
res, err := querier(ctx, []string{types.QueryParameters}, query)
require.NoError(t, err)
err = cdc.UnmarshalJSON(res, &params)
require.NoError(t, err)
require.Equal(t, app.SlashingKeeper.GetParams(ctx), params)
}