cosmos-sdk/x/slashing/keeper/querier_test.go

54 lines
1.2 KiB
Go
Raw Normal View History

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"
"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"
"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)
ctx := app.BaseApp.NewContext(false, abci.Header{})
app.SlashingKeeper.SetParams(ctx, keeper.TestParams())
querier := keeper.NewQuerier(app.SlashingKeeper)
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-03-03 02:14:22 -08:00
app := simapp.Setup(false)
ctx := app.BaseApp.NewContext(false, abci.Header{})
app.SlashingKeeper.SetParams(ctx, keeper.TestParams())
querier := keeper.NewQuerier(app.SlashingKeeper)
query := abci.RequestQuery{
Path: "",
Data: []byte{},
}
2018-12-14 11:09:39 -08: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, &params)
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
}