Skip to content

Commit

Permalink
refactor: remove simapp from x/staking module (cosmos#13101)
Browse files Browse the repository at this point in the history
## Description

Closes: cosmos#13099 



---

### 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...

- [ ] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules)
- [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing)
- [ ] 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)
  • Loading branch information
cool-develope authored and Wryhder committed Oct 26, 2022
1 parent decccc5 commit f21a2b4
Show file tree
Hide file tree
Showing 18 changed files with 349 additions and 453 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store
* [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price.
* [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the x/auth simulation decoder.
* [#13101](https://github.com/cosmos/cosmos-sdk/pull/13101) Remove weights from `simapp/params` and `testutil/sims`. They are now in their respective modules.
* (simapp) [#13107](https://github.com/cosmos/cosmos-sdk/pull/13107) Call `SetIAVLCacheSize` with the configured value in simapp.


### State Machine Breaking

* (x/distribution) [#12852](https://github.com/cosmos/cosmos-sdk/pull/12852) Deprecate `CommunityPoolSpendProposal`. Please execute a `MsgCommunityPoolSpend` message via the new v1 `x/gov` module instead. This message can be used to directly fund the `x/gov` module account.
Expand Down
13 changes: 0 additions & 13 deletions simapp/params/weights.go

This file was deleted.

26 changes: 0 additions & 26 deletions testutil/sims/weights.go

This file was deleted.

14 changes: 9 additions & 5 deletions x/distribution/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil"
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
Expand All @@ -26,35 +25,40 @@ const (
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward"
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission"
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool"

DefaultWeightMsgSetWithdrawAddress int = 50
DefaultWeightMsgWithdrawDelegationReward int = 50
DefaultWeightMsgWithdrawValidatorCommission int = 50
DefaultWeightMsgFundCommunityPool int = 50
)

// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper) simulation.WeightedOperations {
var weightMsgSetWithdrawAddress int
appParams.GetOrGenerate(cdc, OpWeightMsgSetWithdrawAddress, &weightMsgSetWithdrawAddress, nil,
func(_ *rand.Rand) {
weightMsgSetWithdrawAddress = simtestutil.DefaultWeightMsgSetWithdrawAddress
weightMsgSetWithdrawAddress = DefaultWeightMsgSetWithdrawAddress
},
)

var weightMsgWithdrawDelegationReward int
appParams.GetOrGenerate(cdc, OpWeightMsgWithdrawDelegationReward, &weightMsgWithdrawDelegationReward, nil,
func(_ *rand.Rand) {
weightMsgWithdrawDelegationReward = simtestutil.DefaultWeightMsgWithdrawDelegationReward
weightMsgWithdrawDelegationReward = DefaultWeightMsgWithdrawDelegationReward
},
)

var weightMsgWithdrawValidatorCommission int
appParams.GetOrGenerate(cdc, OpWeightMsgWithdrawValidatorCommission, &weightMsgWithdrawValidatorCommission, nil,
func(_ *rand.Rand) {
weightMsgWithdrawValidatorCommission = simtestutil.DefaultWeightMsgWithdrawValidatorCommission
weightMsgWithdrawValidatorCommission = DefaultWeightMsgWithdrawValidatorCommission
},
)

var weightMsgFundCommunityPool int
appParams.GetOrGenerate(cdc, OpWeightMsgFundCommunityPool, &weightMsgFundCommunityPool, nil,
func(_ *rand.Rand) {
weightMsgFundCommunityPool = simtestutil.DefaultWeightMsgFundCommunityPool
weightMsgFundCommunityPool = DefaultWeightMsgFundCommunityPool
},
)

Expand Down
1 change: 1 addition & 0 deletions x/gov/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
DefaultWeightMsgDeposit = 100
DefaultWeightMsgVote = 67
DefaultWeightMsgVoteWeighted = 33
DefaultWeightTextProposal = 5
)

// WeightedOperations returns all the operations from the module with their respective weights
Expand Down
3 changes: 1 addition & 2 deletions x/gov/simulation/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package simulation
import (
"math/rand"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand All @@ -18,7 +17,7 @@ func ProposalContents() []simtypes.WeightedProposalContent {
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightMsgDeposit,
simtestutil.DefaultWeightTextProposal,
DefaultWeightTextProposal,
SimulateTextProposalContent,
),
}
Expand Down
3 changes: 1 addition & 2 deletions x/gov/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/gov/simulation"
Expand All @@ -29,7 +28,7 @@ func TestProposalContents(t *testing.T) {

// tests w0 interface:
require.Equal(t, simulation.OpWeightMsgDeposit, w0.AppParamsKey())
require.Equal(t, simtestutil.DefaultWeightTextProposal, w0.DefaultWeight())
require.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight())

content := w0.ContentSimulatorFn()(r, ctx, accounts)

Expand Down
10 changes: 6 additions & 4 deletions x/params/simulation/proposals.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package simulation

import (
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)

// OpWeightSubmitParamChangeProposal app params key for param change proposal
const OpWeightSubmitParamChangeProposal = "op_weight_submit_param_change_proposal"
const (
// OpWeightSubmitParamChangeProposal app params key for param change proposal
OpWeightSubmitParamChangeProposal = "op_weight_submit_param_change_proposal"
DefaultWeightParamChangeProposal = 5
)

// ProposalContents defines the module weighted proposals' contents
func ProposalContents(paramChanges []simtypes.ParamChange) []simtypes.WeightedProposalContent {
return []simtypes.WeightedProposalContent{
simulation.NewWeightedProposalContent(
OpWeightSubmitParamChangeProposal,
simtestutil.DefaultWeightParamChangeProposal,
DefaultWeightParamChangeProposal,
SimulateParamChangeProposalContent(paramChanges),
),
}
Expand Down
3 changes: 1 addition & 2 deletions x/params/simulation/proposals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"

simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/params/simulation"
Expand All @@ -32,7 +31,7 @@ func TestProposalContents(t *testing.T) {

// tests w0 interface:
require.Equal(t, simulation.OpWeightSubmitParamChangeProposal, w0.AppParamsKey())
require.Equal(t, simtestutil.DefaultWeightParamChangeProposal, w0.DefaultWeight())
require.Equal(t, simulation.DefaultWeightParamChangeProposal, w0.DefaultWeight())

content := w0.ContentSimulatorFn()(r, ctx, accounts)

Expand Down
8 changes: 4 additions & 4 deletions x/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ func (suite *SimTestSuite) TestWeightedOperations() {
opMsgRoute string
opMsgName string
}{
{simtestutil.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, types.TypeMsgSetWithdrawAddress},
{simtestutil.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, types.TypeMsgWithdrawDelegatorReward},
{simtestutil.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, types.TypeMsgWithdrawValidatorCommission},
{simtestutil.DefaultWeightMsgFundCommunityPool, types.ModuleName, types.TypeMsgFundCommunityPool},
{simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, types.TypeMsgSetWithdrawAddress},
{simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, types.TypeMsgWithdrawDelegatorReward},
{simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, types.TypeMsgWithdrawValidatorCommission},
{simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, types.TypeMsgFundCommunityPool},
}

for i, w := range weightesOps {
Expand Down
5 changes: 3 additions & 2 deletions x/slashing/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
//
//nolint:gosec // these are not hardcoded credentials.
const (
OpWeightMsgUnjail = "op_weight_msg_unjail"
OpWeightMsgUnjail = "op_weight_msg_unjail"
DefaultWeightMsgUnjail = 100
)

// WeightedOperations returns all the operations from the module with their respective weights
Expand All @@ -33,7 +34,7 @@ func WeightedOperations(
var weightMsgUnjail int
appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil,
func(_ *rand.Rand) {
weightMsgUnjail = simtestutil.DefaultWeightMsgUnjail
weightMsgUnjail = DefaultWeightMsgUnjail
},
)

Expand Down
2 changes: 1 addition & 1 deletion x/slashing/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
weight int
opMsgRoute string
opMsgName string
}{{simtestutil.DefaultWeightMsgUnjail, types.ModuleName, types.TypeMsgUnjail}}
}{{simulation.DefaultWeightMsgUnjail, types.ModuleName, types.TypeMsgUnjail}}

weightesOps := simulation.WeightedOperations(appParams, suite.codec, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper)
for i, w := range weightesOps {
Expand Down
Loading

0 comments on commit f21a2b4

Please sign in to comment.