cosmos-sdk/x/slashing/keeper/querier_test.go
Marie 7f59723d88
Make JSONMarshaler methods require proto.Message (#7054)
* Make JSONMarshaler require proto.Message

* Use &msg with MarshalJSON

* Use *LegacyAmino in queriers instead of JSONMarshaler

* Revert ABCIMessageLogs String() and coins tests

* Use LegacyAmino in client/debug and fix subspace tests

* Use LegacyAmino in all legacy queriers and adapt simulation

* Make AminoCodec implement Marshaler and some godoc fixes

* Test fixes

* Remove unrelevant comment

* Use TxConfig.TxJSONEncoder

* Use encoding/json in genutil cli migrate/validate genesis cmds

* Address simulation related comments

* Use JSONMarshaler in cli tests

* Use proto.Message as respType in cli tests

* Use tmjson for tm GenesisDoc

* Update types/module/simulation.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update types/module/module_test.go

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Add godoc comments

* Remove unused InsertKeyJSON

* Fix tests

Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
2020-08-26 09:39:38 +00:00

56 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/types"
)
func TestNewQuerier(t *testing.T) {
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
app.SlashingKeeper.SetParams(ctx, keeper.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.New()
legacyQuerierCdc := codec.NewAminoCodec(cdc)
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
app.SlashingKeeper.SetParams(ctx, keeper.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)
}