2020-03-03 02:14:22 -08:00
|
|
|
package keeper_test
|
2018-12-14 11:09:39 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
2020-03-03 02:14:22 -08:00
|
|
|
|
2018-12-14 11:09:39 -08:00
|
|
|
abci "github.com/tendermint/tendermint/abci/types"
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2018-12-14 11:09:39 -08:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-03-03 02:14:22 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/keeper"
|
2020-02-19 16:04:13 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/slashing/types"
|
2018-12-14 11:09:39 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestNewQuerier(t *testing.T) {
|
2020-03-03 02:14:22 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-03 02:14:22 -08:00
|
|
|
app.SlashingKeeper.SetParams(ctx, keeper.TestParams())
|
2020-08-10 12:41:21 -07:00
|
|
|
legacyQuerierCdc := codec.NewAminoCodec(app.LegacyAmino())
|
2020-07-25 01:03:58 -07:00
|
|
|
querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc)
|
2018-12-14 11:09:39 -08:00
|
|
|
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: "",
|
|
|
|
Data: []byte{},
|
|
|
|
}
|
|
|
|
|
2020-03-03 02:14:22 -08:00
|
|
|
_, err := querier(ctx, []string{types.QueryParameters}, query)
|
2018-12-14 11:09:39 -08:00
|
|
|
require.NoError(t, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestQueryParams(t *testing.T) {
|
|
|
|
cdc := codec.New()
|
2020-07-25 01:03:58 -07:00
|
|
|
legacyQuerierCdc := codec.NewAminoCodec(cdc)
|
2020-03-03 02:14:22 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-03-03 02:14:22 -08:00
|
|
|
app.SlashingKeeper.SetParams(ctx, keeper.TestParams())
|
|
|
|
|
2020-07-25 01:03:58 -07:00
|
|
|
querier := keeper.NewQuerier(app.SlashingKeeper, legacyQuerierCdc)
|
2020-03-03 02:14:22 -08:00
|
|
|
|
|
|
|
query := abci.RequestQuery{
|
|
|
|
Path: "",
|
|
|
|
Data: []byte{},
|
|
|
|
}
|
2018-12-14 11:09:39 -08:00
|
|
|
|
2019-07-19 06:43:38 -07:00
|
|
|
var params types.Params
|
2018-12-14 11:09:39 -08:00
|
|
|
|
2020-03-03 02:14:22 -08:00
|
|
|
res, err := querier(ctx, []string{types.QueryParameters}, query)
|
|
|
|
require.NoError(t, err)
|
2018-12-14 11:09:39 -08:00
|
|
|
|
2020-03-03 02:14:22 -08:00
|
|
|
err = cdc.UnmarshalJSON(res, ¶ms)
|
2018-12-14 11:09:39 -08:00
|
|
|
require.NoError(t, err)
|
2020-03-03 02:14:22 -08:00
|
|
|
require.Equal(t, app.SlashingKeeper.GetParams(ctx), params)
|
2018-12-14 11:09:39 -08:00
|
|
|
}
|