Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove simapp from x/staking module #13101

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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