2020-02-18 04:42:53 -08:00
|
|
|
package keeper_test
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-06-29 18:10:15 -07:00
|
|
|
"github.com/stretchr/testify/require"
|
2020-07-14 10:41:30 -07:00
|
|
|
"github.com/stretchr/testify/suite"
|
2018-06-26 19:00:12 -07:00
|
|
|
|
2020-08-14 10:58:53 -07:00
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
2020-03-20 10:14:14 -07:00
|
|
|
|
2020-07-14 10:41:30 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
2020-02-18 04:42:53 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
2020-07-14 10:41:30 -07:00
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
2019-01-11 12:08:01 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
2018-06-26 19:00:12 -07:00
|
|
|
)
|
|
|
|
|
2020-07-14 10:41:30 -07:00
|
|
|
type KeeperTestSuite struct {
|
|
|
|
suite.Suite
|
|
|
|
|
|
|
|
app *simapp.SimApp
|
|
|
|
ctx sdk.Context
|
|
|
|
addrs []sdk.AccAddress
|
|
|
|
vals []types.Validator
|
|
|
|
queryClient types.QueryClient
|
|
|
|
}
|
|
|
|
|
|
|
|
func (suite *KeeperTestSuite) SetupTest() {
|
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-07-14 10:41:30 -07:00
|
|
|
|
|
|
|
querier := keeper.Querier{Keeper: app.StakingKeeper}
|
|
|
|
|
|
|
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
|
|
|
types.RegisterQueryServer(queryHelper, querier)
|
|
|
|
queryClient := types.NewQueryClient(queryHelper)
|
|
|
|
|
2020-10-23 05:07:52 -07:00
|
|
|
addrs, _, validators := createValidators(suite.T(), ctx, app, []int64{9, 8, 7})
|
2020-08-14 10:58:53 -07:00
|
|
|
header := tmproto.Header{
|
2020-07-14 10:41:30 -07:00
|
|
|
ChainID: "HelloChain",
|
|
|
|
Height: 5,
|
|
|
|
}
|
|
|
|
|
|
|
|
hi := types.NewHistoricalInfo(header, validators)
|
2020-10-23 05:07:52 -07:00
|
|
|
app.StakingKeeper.SetHistoricalInfo(ctx, 5, &hi)
|
2020-07-14 10:41:30 -07:00
|
|
|
|
|
|
|
suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators
|
|
|
|
}
|
2018-06-26 19:00:12 -07:00
|
|
|
func TestParams(t *testing.T) {
|
2020-02-18 04:42:53 -08:00
|
|
|
app := simapp.Setup(false)
|
2020-08-14 10:58:53 -07:00
|
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
2020-02-18 04:42:53 -08:00
|
|
|
|
2018-06-26 19:00:12 -07:00
|
|
|
expParams := types.DefaultParams()
|
|
|
|
|
|
|
|
//check that the empty keeper loads the default
|
2020-02-18 04:42:53 -08:00
|
|
|
resParams := app.StakingKeeper.GetParams(ctx)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, expParams.Equal(resParams))
|
2018-06-26 19:00:12 -07:00
|
|
|
|
|
|
|
//modify a params, save, and retrieve
|
|
|
|
expParams.MaxValidators = 777
|
2020-02-18 04:42:53 -08:00
|
|
|
app.StakingKeeper.SetParams(ctx, expParams)
|
|
|
|
resParams = app.StakingKeeper.GetParams(ctx)
|
2018-06-29 18:10:15 -07:00
|
|
|
require.True(t, expParams.Equal(resParams))
|
2018-06-26 19:00:12 -07:00
|
|
|
}
|
2020-07-14 10:41:30 -07:00
|
|
|
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
|
|
}
|