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

fix: add simulation tests for new param change #14728

Merged
merged 46 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9a41b1c
fix: add simulation tests for new param change
julienrbrt Jan 23, 2023
ec1137d
boilerplate
julienrbrt Jan 23, 2023
f771f69
Merge branch 'main' into julien/simulation
julienrbrt Jan 23, 2023
c2d854e
updates
julienrbrt Jan 23, 2023
7b6157f
updates
julienrbrt Jan 23, 2023
9796a31
updates
julienrbrt Jan 24, 2023
7b9f458
refactor: msgs
julienrbrt Jan 24, 2023
afaf035
renaming
julienrbrt Jan 24, 2023
5f1eb34
updates
julienrbrt Jan 24, 2023
3ce49dc
updates
julienrbrt Jan 24, 2023
9c0f111
updates
julienrbrt Jan 24, 2023
850eb8f
Merge branch 'main' into julien/refactor-msgs
julienrbrt Jan 24, 2023
de28032
add changelog
julienrbrt Jan 24, 2023
29300e8
revert
julienrbrt Jan 24, 2023
a7dee1e
updates
julienrbrt Jan 24, 2023
305ea9f
improvements
julienrbrt Jan 24, 2023
598d1c6
last fix
julienrbrt Jan 24, 2023
6310e92
Merge branch 'main' into julien/simulation
julienrbrt Jan 24, 2023
c386eb8
Merge branch 'julien/refactor-msgs' into julien/simulation
julienrbrt Jan 24, 2023
7575d4e
conflict fix
julienrbrt Jan 24, 2023
4651675
Merge branch 'main' into julien/simulation
julienrbrt Jan 24, 2023
9d59dfa
updates
julienrbrt Jan 24, 2023
34d97a8
Merge branch 'main' into julien/simulation
julienrbrt Jan 24, 2023
32499f5
Merge branch 'main' into julien/simulation
julienrbrt Jan 25, 2023
5158646
wip
julienrbrt Jan 25, 2023
776b2a3
updates
julienrbrt Jan 26, 2023
1c62f82
updates
julienrbrt Jan 26, 2023
ea4ef64
Merge branch 'main' into julien/simulation
julienrbrt Jan 26, 2023
ce74425
support legacy
julienrbrt Jan 26, 2023
4016ed5
updates
julienrbrt Jan 26, 2023
c7dc45a
updates
julienrbrt Jan 26, 2023
837bb8f
gosec
julienrbrt Jan 26, 2023
cbb711d
updates
julienrbrt Jan 26, 2023
8e4293c
updates
julienrbrt Jan 26, 2023
0226da2
Merge branch 'main' into julien/simulation
tac0turtle Jan 27, 2023
4f95e17
Merge branch 'main' into julien/simulation
julienrbrt Jan 27, 2023
500ae97
Merge branch 'main' into julien/simulation
julienrbrt Jan 27, 2023
7eb80c4
Merge branch 'main' into julien/simulation
tac0turtle Jan 27, 2023
3b57fd8
updates
julienrbrt Jan 27, 2023
cc31a56
Merge branch 'main' into julien/simulation
julienrbrt Jan 27, 2023
81c577d
updates
julienrbrt Jan 27, 2023
3b2d65d
updates
julienrbrt Jan 27, 2023
745dc78
fix typos
julienrbrt Jan 27, 2023
05021e5
updates
julienrbrt Jan 27, 2023
4d2001c
updates
julienrbrt Jan 27, 2023
be17432
Merge branch 'main' into julien/simulation
julienrbrt Jan 27, 2023
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
24 changes: 12 additions & 12 deletions types/module/simulation.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simu
// SimulationState is the input parameters used on each of the module's randomized
// GenesisState generator function
type SimulationState struct {
AppParams simulation.AppParams
Cdc codec.JSONCodec // application codec
Rand *rand.Rand // random number
GenState map[string]json.RawMessage // genesis state
Accounts []simulation.Account // simulation accounts
InitialStake sdkmath.Int // initial coins per account
NumBonded int64 // number of initially bonded accounts
BondDenom string // denom to be used as default
GenTimestamp time.Time // genesis timestamp
UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration
ParamChanges []simulation.ParamChange // simulated parameter changes from modules
Contents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key
AppParams simulation.AppParams
Cdc codec.JSONCodec // application codec
Rand *rand.Rand // random number
GenState map[string]json.RawMessage // genesis state
Accounts []simulation.Account // simulation accounts
InitialStake sdkmath.Int // initial coins per account
NumBonded int64 // number of initially bonded accounts
BondDenom string // denom to be used as default
GenTimestamp time.Time // genesis timestamp
UnbondTime time.Duration // staking unbond time stored to use it as the slashing maximum evidence duration
LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
Contents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key
}
2 changes: 1 addition & 1 deletion types/simulation/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Content interface {

type SimValFn func(r *rand.Rand) string

type ParamChange interface {
type LegacyParamChange interface {
Subspace() string
Key() string
SimValue() SimValFn
Expand Down
49 changes: 49 additions & 0 deletions x/auth/simulation/operations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package simulation

import (
"math/rand"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/auth/keeper"
"github.com/cosmos/cosmos-sdk/x/simulation"
)

// Simulation operation weights constants
//
//nolint:gosec // these are not hardcoded credentials.
const (
DefaultWeightMsgUpdateParams int = 100

OpWeightMsgUpdateParams = "op_weight_msg_update_params"
Fixed Show fixed Hide fixed
)

// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec, ak keeper.AccountKeeper,
) simulation.WeightedOperations {
var weightMsgUpdateParams int

appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil,
func(_ *rand.Rand) {
weightMsgUpdateParams = DefaultWeightMsgUpdateParams
},
)

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightMsgUpdateParams,
SimulateMsgUpdateParams(ak),
),
}
}

func SimulateMsgUpdateParams(ak keeper.AccountKeeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
return simtypes.OperationMsg{}, nil, nil
}
}
1 change: 1 addition & 0 deletions x/auth/simulation/operations_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package simulation_test
38 changes: 0 additions & 38 deletions x/auth/simulation/params.go

This file was deleted.

37 changes: 0 additions & 37 deletions x/auth/simulation/params_test.go

This file was deleted.

31 changes: 26 additions & 5 deletions x/bank/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ import (
//
//nolint:gosec // these are not hardcoded credentials.
const (
OpWeightMsgSend = "op_weight_msg_send"
OpWeightMsgMultiSend = "op_weight_msg_multisend"
DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend
DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend
OpWeightMsgSend = "op_weight_msg_send"
Fixed Show fixed Hide fixed
OpWeightMsgMultiSend = "op_weight_msg_multisend"
Fixed Show fixed Hide fixed
OpWeightMsgUpdateParams = "op_weight_msg_update_params"
Fixed Show fixed Hide fixed
DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend
DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend
DefaultWeightMsgUpdateParams = 100
)

// WeightedOperations returns all the operations from the module with their respective weights
func WeightedOperations(
appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk keeper.Keeper,
) simulation.WeightedOperations {
var weightMsgSend, weightMsgMultiSend int
var weightMsgSend, weightMsgMultiSend, weightMsgUpdateParams int

appParams.GetOrGenerate(cdc, OpWeightMsgSend, &weightMsgSend, nil,
func(_ *rand.Rand) {
weightMsgSend = DefaultWeightMsgSend
Expand All @@ -43,6 +46,12 @@ func WeightedOperations(
},
)

appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil,
func(_ *rand.Rand) {
weightMsgUpdateParams = DefaultWeightMsgUpdateParams
},
)

return simulation.WeightedOperations{
simulation.NewWeightedOperation(
weightMsgSend,
Expand All @@ -52,6 +61,10 @@ func WeightedOperations(
weightMsgMultiSend,
SimulateMsgMultiSend(ak, bk),
),
simulation.NewWeightedOperation(
weightMsgUpdateParams,
SimulateMsgUpdateParams(ak, bk),
),
}
}

Expand Down Expand Up @@ -319,6 +332,14 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe
}
}

func SimulateMsgUpdateParams(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
return simtypes.OperationMsg{}, nil, nil
}
}

// sendMsgMultiSend sends a transaction with a MsgMultiSend from a provided random
// account.
func sendMsgMultiSend(
Expand Down
23 changes: 0 additions & 23 deletions x/bank/simulation/params.go

This file was deleted.

35 changes: 0 additions & 35 deletions x/bank/simulation/params_test.go

This file was deleted.

21 changes: 21 additions & 0 deletions x/distribution/simulation/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ const (
OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward"
OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission"
OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool"
OpWeightMsgUpdateParams = "op_weight_msg_update_params"
Fixed Show fixed Hide fixed

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

// WeightedOperations returns all the operations from the module with their respective weights
Expand Down Expand Up @@ -62,6 +64,13 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty
},
)

var weightMsgUpdateParams int
appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil,
func(_ *rand.Rand) {
weightMsgUpdateParams = DefaultWeightMsgUpdateParams
},
)

interfaceRegistry := codectypes.NewInterfaceRegistry()
txConfig := tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), tx.DefaultSignModes)

Expand All @@ -82,6 +91,10 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty
weightMsgFundCommunityPool,
SimulateMsgFundCommunityPool(txConfig, ak, bk, k, sk),
),
simulation.NewWeightedOperation(
weightMsgUpdateParams,
SimulateMsgUpdateParams(ak, k),
),
}
}

Expand Down Expand Up @@ -254,3 +267,11 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep
return simulation.GenAndDeliverTx(txCtx, fees)
}
}

func SimulateMsgUpdateParams(ak types.AccountKeeper, k keeper.Keeper) simtypes.Operation {
return func(
r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string,
) (simtypes.OperationMsg, []simtypes.FutureOperation, error) {
return simtypes.OperationMsg{}, nil, nil
}
}
27 changes: 0 additions & 27 deletions x/distribution/simulation/params.go

This file was deleted.

Loading