<!-- The default pull request template is for types feat, fix, or refactor. For other templates, add one of the following parameters to the url: - template=docs.md - template=other.md --> ## Description ref: #8961 <!-- Add a description of the changes that this PR introduces and the files that are the most critical to review. --> Following up on [#9697](https://github.com/cosmos/cosmos-sdk/pull/9697#pullrequestreview-727295733), this PR is the first step for the #8961. --- ### Author Checklist *All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues.* I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting)) - [x] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing) - [x] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [ ] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist *All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items.* I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed `!` in the type prefix if API or client breaking change - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable)
73 lines
2.1 KiB
Go
73 lines
2.1 KiB
Go
package keeper_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/baseapp"
|
|
"github.com/cosmos/cosmos-sdk/simapp"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
"github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
|
)
|
|
|
|
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(suite.T(), false)
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
querier := keeper.Querier{Keeper: app.StakingKeeper}
|
|
|
|
queryHelper := baseapp.NewQueryServerTestHelper(ctx, app.InterfaceRegistry())
|
|
types.RegisterQueryServer(queryHelper, querier)
|
|
queryClient := types.NewQueryClient(queryHelper)
|
|
|
|
addrs, _, validators := createValidators(suite.T(), ctx, app, []int64{9, 8, 7})
|
|
header := tmproto.Header{
|
|
ChainID: "HelloChain",
|
|
Height: 5,
|
|
}
|
|
|
|
// sort a copy of the validators, so that original validators does not
|
|
// have its order changed
|
|
sortedVals := make([]types.Validator, len(validators))
|
|
copy(sortedVals, validators)
|
|
hi := types.NewHistoricalInfo(header, sortedVals, app.StakingKeeper.PowerReduction(ctx))
|
|
app.StakingKeeper.SetHistoricalInfo(ctx, 5, &hi)
|
|
|
|
suite.app, suite.ctx, suite.queryClient, suite.addrs, suite.vals = app, ctx, queryClient, addrs, validators
|
|
}
|
|
func TestParams(t *testing.T) {
|
|
app := simapp.Setup(t, false)
|
|
ctx := app.BaseApp.NewContext(false, tmproto.Header{})
|
|
|
|
expParams := types.DefaultParams()
|
|
|
|
//check that the empty keeper loads the default
|
|
resParams := app.StakingKeeper.GetParams(ctx)
|
|
require.True(t, expParams.Equal(resParams))
|
|
|
|
//modify a params, save, and retrieve
|
|
expParams.MaxValidators = 777
|
|
app.StakingKeeper.SetParams(ctx, expParams)
|
|
resParams = app.StakingKeeper.GetParams(ctx)
|
|
require.True(t, expParams.Equal(resParams))
|
|
}
|
|
|
|
func TestKeeperTestSuite(t *testing.T) {
|
|
suite.Run(t, new(KeeperTestSuite))
|
|
}
|