From 9a41b1c84e01640eb4d4bb2e5eb1feba3c5b905f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 23 Jan 2023 14:57:13 +0100 Subject: [PATCH 01/32] fix: add simulation tests for new param change --- types/module/simulation.go | 24 ++++----- types/simulation/types.go | 2 +- x/auth/simulation/params.go | 38 -------------- x/auth/simulation/params_test.go | 37 ------------- x/bank/simulation/params.go | 23 -------- x/bank/simulation/params_test.go | 35 ------------- x/distribution/simulation/params.go | 27 ---------- x/distribution/simulation/params_test.go | 35 ------------- x/gov/simulation/params.go | 67 ------------------------ x/gov/simulation/params_test.go | 37 ------------- x/mint/simulation/params.go | 45 ---------------- x/mint/simulation/params_test.go | 37 ------------- x/params/simulation/operations.go | 2 +- x/params/simulation/operations_test.go | 4 +- x/params/simulation/proposals.go | 2 +- x/params/simulation/proposals_test.go | 2 +- x/simulation/params.go | 28 +++++----- x/simulation/params_test.go | 4 +- x/slashing/simulation/params.go | 38 -------------- x/slashing/simulation/params_test.go | 37 ------------- x/staking/simulation/params.go | 32 ----------- x/staking/simulation/params_test.go | 37 ------------- 22 files changed, 34 insertions(+), 559 deletions(-) delete mode 100644 x/auth/simulation/params.go delete mode 100644 x/auth/simulation/params_test.go delete mode 100644 x/bank/simulation/params.go delete mode 100644 x/bank/simulation/params_test.go delete mode 100644 x/distribution/simulation/params.go delete mode 100644 x/distribution/simulation/params_test.go delete mode 100644 x/gov/simulation/params.go delete mode 100644 x/gov/simulation/params_test.go delete mode 100644 x/mint/simulation/params.go delete mode 100644 x/mint/simulation/params_test.go delete mode 100644 x/slashing/simulation/params.go delete mode 100644 x/slashing/simulation/params_test.go delete mode 100644 x/staking/simulation/params.go delete mode 100644 x/staking/simulation/params_test.go diff --git a/types/module/simulation.go b/types/module/simulation.go index d742a6639498..6c6c467cbe59 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -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 + Contents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key } diff --git a/types/simulation/types.go b/types/simulation/types.go index 702e6b2e49ca..2e491bb65e38 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -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 diff --git a/x/auth/simulation/params.go b/x/auth/simulation/params.go deleted file mode 100644 index 310e2a49ae16..000000000000 --- a/x/auth/simulation/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/auth/types" - "github.com/cosmos/cosmos-sdk/x/simulation" -) - -const ( - keyMaxMemoCharacters = "MaxMemoCharacters" - keyTxSigLimit = "TxSigLimit" - keyTxSizeCostPerByte = "TxSizeCostPerByte" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, keyMaxMemoCharacters, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", GenMaxMemoChars(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyTxSigLimit, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", GenTxSigLimit(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyTxSizeCostPerByte, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", GenTxSizeCostPerByte(r)) - }, - ), - } -} diff --git a/x/auth/simulation/params_test.go b/x/auth/simulation/params_test.go deleted file mode 100644 index b8fb384a80f6..000000000000 --- a/x/auth/simulation/params_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/auth/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"auth/MaxMemoCharacters", "MaxMemoCharacters", "\"181\"", "auth"}, - {"auth/TxSigLimit", "TxSigLimit", "\"7\"", "auth"}, - {"auth/TxSizeCostPerByte", "TxSizeCostPerByte", "\"12\"", "auth"}, - } - - paramChanges := simulation.ParamChanges(r) - - require.Len(t, paramChanges, 3) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/bank/simulation/params.go b/x/bank/simulation/params.go deleted file mode 100644 index ab83624c035b..000000000000 --- a/x/bank/simulation/params.go +++ /dev/null @@ -1,23 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - "github.com/cosmos/cosmos-sdk/x/simulation" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/bank/types" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, string(types.KeyDefaultSendEnabled), - func(r *rand.Rand) string { - return fmt.Sprintf("%v", RandomGenesisDefaultSendEnabledParam(r)) - }, - ), - } -} diff --git a/x/bank/simulation/params_test.go b/x/bank/simulation/params_test.go deleted file mode 100644 index df6604367a1d..000000000000 --- a/x/bank/simulation/params_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/bank/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"bank/DefaultSendEnabled", "DefaultSendEnabled", "true", "bank"}, - } - - paramChanges := simulation.ParamChanges(r) - - require.Len(t, paramChanges, len(expected)) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/distribution/simulation/params.go b/x/distribution/simulation/params.go deleted file mode 100644 index d4ca51822767..000000000000 --- a/x/distribution/simulation/params.go +++ /dev/null @@ -1,27 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - "github.com/cosmos/cosmos-sdk/x/simulation" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/distribution/types" -) - -const ( - keyCommunityTax = "communitytax" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, keyCommunityTax, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenCommunityTax(r)) - }, - ), - } -} diff --git a/x/distribution/simulation/params_test.go b/x/distribution/simulation/params_test.go deleted file mode 100644 index 0d1818a40510..000000000000 --- a/x/distribution/simulation/params_test.go +++ /dev/null @@ -1,35 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/distribution/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"distribution/communitytax", "communitytax", "\"0.120000000000000000\"", "distribution"}, - } - - paramChanges := simulation.ParamChanges(r) - - require.Len(t, paramChanges, 1) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/gov/simulation/params.go b/x/gov/simulation/params.go deleted file mode 100644 index 138ca15fb0bf..000000000000 --- a/x/gov/simulation/params.go +++ /dev/null @@ -1,67 +0,0 @@ -package simulation - -import ( - "encoding/json" - "fmt" - "math/rand" - - sdk "github.com/cosmos/cosmos-sdk/types" - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/simulation" -) - -const ( - keyVotingParams = "votingparams" - keyDepositParams = "depositparams" - keyTallyParams = "tallyparams" - subkeyQuorum = "quorum" - subkeyThreshold = "threshold" - subkeyVeto = "veto" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, keyVotingParams, - func(r *rand.Rand) string { - return fmt.Sprintf(`{"voting_period": "%d"}`, GenVotingParamsVotingPeriod(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyDepositParams, - func(r *rand.Rand) string { - return fmt.Sprintf(`{"max_deposit_period": "%d"}`, GenDepositParamsDepositPeriod(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyTallyParams, - func(r *rand.Rand) string { - changes := []struct { - key string - value sdk.Dec - }{ - {subkeyQuorum, GenTallyParamsQuorum(r)}, - {subkeyThreshold, GenTallyParamsThreshold(r)}, - {subkeyVeto, GenTallyParamsVeto(r)}, - } - - pc := make(map[string]string) - numChanges := simtypes.RandIntBetween(r, 1, len(changes)) - for i := 0; i < numChanges; i++ { - c := changes[r.Intn(len(changes))] - - _, ok := pc[c.key] - for ok { - c := changes[r.Intn(len(changes))] - _, ok = pc[c.key] - } - - pc[c.key] = c.value.String() - } - - bz, _ := json.Marshal(pc) - return string(bz) - }, - ), - } -} diff --git a/x/gov/simulation/params_test.go b/x/gov/simulation/params_test.go deleted file mode 100644 index de528d14d9d5..000000000000 --- a/x/gov/simulation/params_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/gov/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"gov/votingparams", "votingparams", "{\"voting_period\": \"82639000000000\"}", "gov"}, - {"gov/depositparams", "depositparams", "{\"max_deposit_period\": \"47332000000000\"}", "gov"}, - {"gov/tallyparams", "tallyparams", "{\"threshold\":\"0.509000000000000000\"}", "gov"}, - } - - paramChanges := simulation.ParamChanges(r) - require.Len(t, paramChanges, 3) - - for i, p := range paramChanges { - - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/mint/simulation/params.go b/x/mint/simulation/params.go deleted file mode 100644 index 34927567e185..000000000000 --- a/x/mint/simulation/params.go +++ /dev/null @@ -1,45 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - "github.com/cosmos/cosmos-sdk/x/simulation" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/mint/types" -) - -const ( - keyInflationRateChange = "InflationRateChange" - keyInflationMax = "InflationMax" - keyInflationMin = "InflationMin" - keyGoalBonded = "GoalBonded" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, keyInflationRateChange, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenInflationRateChange(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyInflationMax, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenInflationMax(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyInflationMin, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenInflationMin(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyGoalBonded, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenGoalBonded(r)) - }, - ), - } -} diff --git a/x/mint/simulation/params_test.go b/x/mint/simulation/params_test.go deleted file mode 100644 index 3334fbd51a97..000000000000 --- a/x/mint/simulation/params_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/mint/simulation" -) - -func TestParamChangest(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"mint/InflationRateChange", "InflationRateChange", "\"0.230000000000000000\"", "mint"}, - {"mint/InflationMax", "InflationMax", "\"0.200000000000000000\"", "mint"}, - {"mint/InflationMin", "InflationMin", "\"0.070000000000000000\"", "mint"}, - {"mint/GoalBonded", "GoalBonded", "\"0.670000000000000000\"", "mint"}, - } - - paramChanges := simulation.ParamChanges(r) - require.Len(t, paramChanges, 4) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/params/simulation/operations.go b/x/params/simulation/operations.go index 6e7619b7032b..037dff3ff0f2 100644 --- a/x/params/simulation/operations.go +++ b/x/params/simulation/operations.go @@ -19,7 +19,7 @@ func min(a int, b int) int { // SimulateParamChangeProposalContent returns random parameter change content. // It will generate a ParameterChangeProposal object with anywhere between 1 and // the total amount of defined parameters changes, all of which have random valid values. -func SimulateParamChangeProposalContent(paramChangePool []simulation.ParamChange) simulation.ContentSimulatorFn { +func SimulateParamChangeProposalContent(paramChangePool []simulation.LegacyParamChange) simulation.ContentSimulatorFn { numProposals := 0 // Bound the maximum number of simultaneous parameter changes maxSimultaneousParamChanges := min(len(paramChangePool), 1000) diff --git a/x/params/simulation/operations_test.go b/x/params/simulation/operations_test.go index 5ed1ba8a50fc..5e4f4e93e193 100644 --- a/x/params/simulation/operations_test.go +++ b/x/params/simulation/operations_test.go @@ -37,7 +37,7 @@ func (pc MockParamChange) SimValue() simtypes.SimValFn { } // make sure that the MockParamChange satisfied the ParamChange interface -var _ simtypes.ParamChange = MockParamChange{} +var _ simtypes.LegacyParamChange = MockParamChange{} func TestSimulateParamChangeProposalContent(t *testing.T) { s := rand.NewSource(1) @@ -45,7 +45,7 @@ func TestSimulateParamChangeProposalContent(t *testing.T) { ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) accounts := simtypes.RandomAccounts(r, 3) - paramChangePool := []simtypes.ParamChange{MockParamChange{1}, MockParamChange{2}, MockParamChange{3}} + paramChangePool := []simtypes.LegacyParamChange{MockParamChange{1}, MockParamChange{2}, MockParamChange{3}} // execute operation op := simulation.SimulateParamChangeProposalContent(paramChangePool) diff --git a/x/params/simulation/proposals.go b/x/params/simulation/proposals.go index 551f940754be..9f49b9102421 100644 --- a/x/params/simulation/proposals.go +++ b/x/params/simulation/proposals.go @@ -12,7 +12,7 @@ const ( ) // ProposalContents defines the module weighted proposals' contents -func ProposalContents(paramChanges []simtypes.ParamChange) []simtypes.WeightedProposalContent { +func ProposalContents(paramChanges []simtypes.LegacyParamChange) []simtypes.WeightedProposalContent { return []simtypes.WeightedProposalContent{ simulation.NewWeightedProposalContent( OpWeightSubmitParamChangeProposal, diff --git a/x/params/simulation/proposals_test.go b/x/params/simulation/proposals_test.go index 1ae2b413259d..e09202a6fe31 100644 --- a/x/params/simulation/proposals_test.go +++ b/x/params/simulation/proposals_test.go @@ -21,7 +21,7 @@ func TestProposalContents(t *testing.T) { ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) accounts := simtypes.RandomAccounts(r, 3) - paramChangePool := []simtypes.ParamChange{MockParamChange{1}, MockParamChange{2}, MockParamChange{3}} + paramChangePool := []simtypes.LegacyParamChange{MockParamChange{1}, MockParamChange{2}, MockParamChange{3}} // execute ProposalContents function weightedProposalContent := simulation.ProposalContents(paramChangePool) diff --git a/x/simulation/params.go b/x/simulation/params.go index acc7d9b6d8f7..00f58fb59e7b 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -86,41 +86,41 @@ func RandomParams(r *rand.Rand) Params { } } -// Param change proposals +// Legacy param change proposals -// ParamChange defines the object used for simulating parameter change proposals -type ParamChange struct { +// LegacyParamChange defines the object used for simulating parameter change proposals +type LegacyParamChange struct { subspace string key string simValue simulation.SimValFn } -func (spc ParamChange) Subspace() string { +func (spc LegacyParamChange) Subspace() string { return spc.subspace } -func (spc ParamChange) Key() string { +func (spc LegacyParamChange) Key() string { return spc.key } -func (spc ParamChange) SimValue() simulation.SimValFn { +func (spc LegacyParamChange) SimValue() simulation.SimValFn { return spc.simValue } -// NewSimParamChange creates a new ParamChange instance -func NewSimParamChange(subspace, key string, simVal simulation.SimValFn) simulation.ParamChange { - return ParamChange{ +// ComposedKey creates a new composed key for the legacy param change proposal +func (spc LegacyParamChange) ComposedKey() string { + return spc.Subspace() + "/" + spc.Key() +} + +// NewSimLegacyParamChange creates a new LegacyParamChange instance +func NewSimLegacyParamChange(subspace, key string, simVal simulation.SimValFn) simulation.LegacyParamChange { + return LegacyParamChange{ subspace: subspace, key: key, simValue: simVal, } } -// ComposedKey creates a new composed key for the param change proposal -func (spc ParamChange) ComposedKey() string { - return spc.Subspace() + "/" + spc.Key() -} - // Proposal Contents // WeightedProposalContent defines a common struct for proposal contents defined by diff --git a/x/simulation/params_test.go b/x/simulation/params_test.go index 90eb4f22a0a4..0edc1432e5ec 100644 --- a/x/simulation/params_test.go +++ b/x/simulation/params_test.go @@ -12,13 +12,13 @@ import ( simtypes "github.com/cosmos/cosmos-sdk/types/simulation" ) -func TestParamChange(t *testing.T) { +func TestLegacyParamChange(t *testing.T) { subspace, key := "theSubspace", "key" f := func(r *rand.Rand) string { return "theResult" } - pChange := NewSimParamChange(subspace, key, f) + pChange := NewSimLegacyParamChange(subspace, key, f) require.Equal(t, subspace, pChange.Subspace()) require.Equal(t, key, pChange.Key()) diff --git a/x/slashing/simulation/params.go b/x/slashing/simulation/params.go deleted file mode 100644 index 20d7f682589a..000000000000 --- a/x/slashing/simulation/params.go +++ /dev/null @@ -1,38 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/slashing/types" -) - -const ( - keySignedBlocksWindow = "SignedBlocksWindow" - keyMinSignedPerWindow = "MinSignedPerWindow" - keySlashFractionDowntime = "SlashFractionDowntime" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, keySignedBlocksWindow, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", GenSignedBlocksWindow(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keyMinSignedPerWindow, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenMinSignedPerWindow(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, keySlashFractionDowntime, - func(r *rand.Rand) string { - return fmt.Sprintf("\"%s\"", GenSlashFractionDowntime(r)) - }, - ), - } -} diff --git a/x/slashing/simulation/params_test.go b/x/slashing/simulation/params_test.go deleted file mode 100644 index 2f1933c60ad2..000000000000 --- a/x/slashing/simulation/params_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/slashing/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"slashing/SignedBlocksWindow", "SignedBlocksWindow", "\"231\"", "slashing"}, - {"slashing/MinSignedPerWindow", "MinSignedPerWindow", "\"0.700000000000000000\"", "slashing"}, - {"slashing/SlashFractionDowntime", "SlashFractionDowntime", "\"0.020833333333333333\"", "slashing"}, - } - - paramChanges := simulation.ParamChanges(r) - - require.Len(t, paramChanges, 3) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} diff --git a/x/staking/simulation/params.go b/x/staking/simulation/params.go deleted file mode 100644 index e969c7bd22ee..000000000000 --- a/x/staking/simulation/params.go +++ /dev/null @@ -1,32 +0,0 @@ -package simulation - -import ( - "fmt" - "math/rand" - - simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/simulation" - "github.com/cosmos/cosmos-sdk/x/staking/types" -) - -// ParamChanges defines the parameters that can be modified by param change proposals -// on the simulation -func ParamChanges(r *rand.Rand) []simtypes.ParamChange { - return []simtypes.ParamChange{ - simulation.NewSimParamChange(types.ModuleName, string(types.KeyMaxValidators), - func(r *rand.Rand) string { - return fmt.Sprintf("%d", genMaxValidators(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, string(types.KeyUnbondingTime), - func(r *rand.Rand) string { - return fmt.Sprintf("\"%d\"", genUnbondingTime(r)) - }, - ), - simulation.NewSimParamChange(types.ModuleName, string(types.KeyHistoricalEntries), - func(r *rand.Rand) string { - return fmt.Sprintf("%d", getHistEntries(r)) - }, - ), - } -} diff --git a/x/staking/simulation/params_test.go b/x/staking/simulation/params_test.go deleted file mode 100644 index 07da026645cf..000000000000 --- a/x/staking/simulation/params_test.go +++ /dev/null @@ -1,37 +0,0 @@ -package simulation_test - -import ( - "math/rand" - "testing" - - "github.com/stretchr/testify/require" - - "github.com/cosmos/cosmos-sdk/x/staking/simulation" -) - -func TestParamChanges(t *testing.T) { - s := rand.NewSource(1) - r := rand.New(s) - - expected := []struct { - composedKey string - key string - simValue string - subspace string - }{ - {"staking/MaxValidators", "MaxValidators", "82", "staking"}, - {"staking/UnbondingTime", "UnbondingTime", "\"275307000000000\"", "staking"}, - {"staking/HistoricalEntries", "HistoricalEntries", "9149", "staking"}, - } - - paramChanges := simulation.ParamChanges(r) - - require.Len(t, paramChanges, 3) - - for i, p := range paramChanges { - require.Equal(t, expected[i].composedKey, p.ComposedKey()) - require.Equal(t, expected[i].key, p.Key()) - require.Equal(t, expected[i].simValue, p.SimValue()(r)) - require.Equal(t, expected[i].subspace, p.Subspace()) - } -} From ec1137ddd23d519a5baf215b55ef32f3b86e71ae Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 23 Jan 2023 16:34:38 +0100 Subject: [PATCH 02/32] boilerplate --- x/auth/simulation/operations.go | 49 ++++++++++++++++++++++++ x/auth/simulation/operations_test.go | 1 + x/bank/simulation/operations.go | 31 ++++++++++++--- x/distribution/simulation/operations.go | 21 +++++++++++ x/gov/simulation/operations.go | 22 +++++++++++ x/mint/simulation/operations.go | 50 +++++++++++++++++++++++++ x/mint/simulation/operations_test.go | 1 + x/slashing/simulation/operations.go | 27 ++++++++++++- x/staking/simulation/operations.go | 19 ++++++++++ 9 files changed, 214 insertions(+), 7 deletions(-) create mode 100644 x/auth/simulation/operations.go create mode 100644 x/auth/simulation/operations_test.go create mode 100644 x/mint/simulation/operations.go create mode 100644 x/mint/simulation/operations_test.go diff --git a/x/auth/simulation/operations.go b/x/auth/simulation/operations.go new file mode 100644 index 000000000000..0028c3915831 --- /dev/null +++ b/x/auth/simulation/operations.go @@ -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" +) + +// 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 + } +} diff --git a/x/auth/simulation/operations_test.go b/x/auth/simulation/operations_test.go new file mode 100644 index 000000000000..5c6452f9a069 --- /dev/null +++ b/x/auth/simulation/operations_test.go @@ -0,0 +1 @@ +package simulation_test diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7818ebf1a2b6..c185c5c48609 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -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" + OpWeightMsgMultiSend = "op_weight_msg_multisend" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" + 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 @@ -43,6 +46,12 @@ func WeightedOperations( }, ) + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, + func(_ *rand.Rand) { + weightMsgUpdateParams = DefaultWeightMsgUpdateParams + }, + ) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgSend, @@ -52,6 +61,10 @@ func WeightedOperations( weightMsgMultiSend, SimulateMsgMultiSend(ak, bk), ), + simulation.NewWeightedOperation( + weightMsgUpdateParams, + SimulateMsgUpdateParams(ak, bk), + ), } } @@ -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( diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index d4c8caa61ebe..7cead85bb989 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -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" 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 @@ -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) @@ -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), + ), } } @@ -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 + } +} diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 47f81408c7aa..2536cb6c9d77 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -26,6 +26,7 @@ var ( TypeMsgVoteWeighted = sdk.MsgTypeURL(&v1.MsgVoteWeighted{}) TypeMsgSubmitProposal = sdk.MsgTypeURL(&v1.MsgSubmitProposal{}) TypeMsgCancelProposal = sdk.MsgTypeURL(&v1.MsgCancelProposal{}) + TypeMsgUpdateParams = sdk.MsgTypeURL(&v1.MsgUpdateParams{}) ) // Simulation operation weights constants @@ -36,12 +37,14 @@ const ( OpWeightMsgVote = "op_weight_msg_vote" OpWeightMsgVoteWeighted = "op_weight_msg_weighted_vote" OpWeightMsgCancelProposal = "op_weight_msg_cancel_proposal" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" DefaultWeightMsgDeposit = 100 DefaultWeightMsgVote = 67 DefaultWeightMsgVoteWeighted = 33 DefaultWeightTextProposal = 5 DefaultWeightMsgCancelProposal = 5 + DefaultWeightMsgUpdateParams = 5 ) // WeightedOperations returns all the operations from the module with their respective weights @@ -51,6 +54,7 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty weightMsgVote int weightMsgVoteWeighted int weightMsgCancelProposal int + weightMsgUpdateParams int ) appParams.GetOrGenerate(cdc, OpWeightMsgDeposit, &weightMsgDeposit, nil, @@ -77,6 +81,12 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty }, ) + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, + func(_ *rand.Rand) { + weightMsgUpdateParams = DefaultWeightMsgUpdateParams + }, + ) + // generate the weighted operations for the proposal contents var wProposalOps simulation.WeightedOperations @@ -112,11 +122,23 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty weightMsgCancelProposal, SimulateMsgCancelProposal(ak, bk, k), ), + simulation.NewWeightedOperation( + weightMsgUpdateParams, + SimulateMsgUpdateParams(ak, k), + ), } return append(wProposalOps, wGovOps...) } +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 + } +} + // SimulateMsgSubmitProposal simulates creating a msg Submit Proposal // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. diff --git a/x/mint/simulation/operations.go b/x/mint/simulation/operations.go new file mode 100644 index 000000000000..310a94f02f7f --- /dev/null +++ b/x/mint/simulation/operations.go @@ -0,0 +1,50 @@ +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/mint/keeper" + "github.com/cosmos/cosmos-sdk/x/mint/types" + "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" +) + +// WeightedOperations returns all the operations from the module with their respective weights +func WeightedOperations( + appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, k *keeper.Keeper, +) simulation.WeightedOperations { + var weightMsgUpdateParams int + + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, + func(_ *rand.Rand) { + weightMsgUpdateParams = DefaultWeightMsgUpdateParams + }, + ) + + return simulation.WeightedOperations{ + simulation.NewWeightedOperation( + weightMsgUpdateParams, + SimulateMsgUpdateParams(ak, k), + ), + } +} + +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 + } +} diff --git a/x/mint/simulation/operations_test.go b/x/mint/simulation/operations_test.go new file mode 100644 index 000000000000..5c6452f9a069 --- /dev/null +++ b/x/mint/simulation/operations_test.go @@ -0,0 +1 @@ +package simulation_test diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 939f28766fe5..c47c70e87c8e 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -21,8 +21,11 @@ import ( // //nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgUnjail = "op_weight_msg_unjail" - DefaultWeightMsgUnjail = 100 + OpWeightMsgUnjail = "op_weight_msg_unjail" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" + + DefaultWeightMsgUnjail = 100 + DefaultWeightMsgUpdateParams int = 100 ) // WeightedOperations returns all the operations from the module with their respective weights @@ -31,6 +34,7 @@ func WeightedOperations( bk types.BankKeeper, k keeper.Keeper, sk types.StakingKeeper, ) simulation.WeightedOperations { interfaceRegistry := codectypes.NewInterfaceRegistry() + var weightMsgUnjail int appParams.GetOrGenerate(cdc, OpWeightMsgUnjail, &weightMsgUnjail, nil, func(_ *rand.Rand) { @@ -38,11 +42,22 @@ func WeightedOperations( }, ) + var weightMsgUpdateParams int + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, + func(_ *rand.Rand) { + weightMsgUpdateParams = DefaultWeightMsgUpdateParams + }, + ) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgUnjail, SimulateMsgUnjail(codec.NewProtoCodec(interfaceRegistry), ak, bk, k, sk), ), + simulation.NewWeightedOperation( + weightMsgUpdateParams, + SimulateMsgUpdateParams(ak, k), + ), } } @@ -138,3 +153,11 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } + +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 + } +} diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index a675c4c9e634..b0d4777c9a92 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -26,6 +26,7 @@ const ( DefaultWeightMsgUndelegate int = 100 DefaultWeightMsgBeginRedelegate int = 100 DefaultWeightMsgCancelUnbondingDelegation int = 100 + DefaultWeightMsgUpdateParams int = 100 OpWeightMsgCreateValidator = "op_weight_msg_create_validator" OpWeightMsgEditValidator = "op_weight_msg_edit_validator" @@ -33,6 +34,7 @@ const ( OpWeightMsgUndelegate = "op_weight_msg_undelegate" OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate" OpWeightMsgCancelUnbondingDelegation = "op_weight_msg_cancel_unbonding_delegation" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" ) // WeightedOperations returns all the operations from the module with their respective weights @@ -47,6 +49,7 @@ func WeightedOperations( weightMsgUndelegate int weightMsgBeginRedelegate int weightMsgCancelUnbondingDelegation int + weightMsgUpdateParams int ) appParams.GetOrGenerate(cdc, OpWeightMsgCreateValidator, &weightMsgCreateValidator, nil, @@ -85,6 +88,10 @@ func WeightedOperations( }, ) + appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, func(r *rand.Rand) { + weightMsgUpdateParams = DefaultWeightMsgUpdateParams + }) + return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgCreateValidator, @@ -110,6 +117,10 @@ func WeightedOperations( weightMsgCancelUnbondingDelegation, SimulateMsgCancelUnbondingDelegate(ak, bk, k), ), + simulation.NewWeightedOperation( + weightMsgUpdateParams, + SimulateMsgUpdateParams(ak, k), + ), } } @@ -574,3 +585,11 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * return simulation.GenAndDeliverTxWithRandFees(txCtx) } } + +func SimulateMsgUpdateParams(ak types.AccountKeeper, sk *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 + } +} From c2d854e7cda815eded6b04271141e8db92a7a6e4 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 23 Jan 2023 22:23:01 +0100 Subject: [PATCH 03/32] updates --- x/staking/types/msg.go | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 588e54df52e5..22fac0e09e20 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -387,13 +387,6 @@ func (msg MsgCancelUnbondingDelegation) ValidateBasic() error { return nil } -// GetSignBytes returns the raw bytes for a MsgUpdateParams message that -// the expected signer needs to sign. -func (m *MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(m) - return sdk.MustSortJSON(bz) -} - // ValidateBasic executes sanity validation on the provided data func (m *MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { @@ -402,6 +395,19 @@ func (m *MsgUpdateParams) ValidateBasic() error { return m.Params.Validate() } +// Route implements the sdk.Msg interface. +func (msg MsgUpdateParams) Route() string { return RouterKey } + +// Type implements the sdk.Msg interface. +func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } + +// GetSignBytes returns the raw bytes for a MsgUpdateParams message that +// the expected signer needs to sign. +func (m *MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(m) + return sdk.MustSortJSON(bz) +} + // GetSigners returns the expected signers for a MsgUpdateParams message func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(m.Authority) From 7b6157f6fe66698385b007f4c43e326b13fcdecb Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 23 Jan 2023 22:28:44 +0100 Subject: [PATCH 04/32] updates --- x/auth/types/msgs.go | 4 ++-- x/slashing/types/msg.go | 4 ++-- x/staking/types/msg.go | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x/auth/types/msgs.go b/x/auth/types/msgs.go index c0f25ee1e023..a2bf307e0d34 100644 --- a/x/auth/types/msgs.go +++ b/x/auth/types/msgs.go @@ -13,13 +13,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 4f958ec1a456..e14a93bae279 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -57,13 +57,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 22fac0e09e20..25b5cce4c33c 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -388,11 +388,11 @@ func (msg MsgCancelUnbondingDelegation) ValidateBasic() error { } // ValidateBasic executes sanity validation on the provided data -func (m *MsgUpdateParams) ValidateBasic() error { - if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { +func (msg MsgUpdateParams) ValidateBasic() error { + if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } - return m.Params.Validate() + return msg.Params.Validate() } // Route implements the sdk.Msg interface. @@ -403,13 +403,13 @@ func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } // GetSignBytes returns the raw bytes for a MsgUpdateParams message that // the expected signer needs to sign. -func (m *MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(m) +func (msg MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&msg) return sdk.MustSortJSON(bz) } // GetSigners returns the expected signers for a MsgUpdateParams message -func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { - addr, _ := sdk.AccAddressFromBech32(m.Authority) +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { + addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } From 9796a317cbf8367189e4d78d342a3a168b161894 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 13:18:06 +0100 Subject: [PATCH 05/32] updates --- CHANGELOG.md | 1 + x/staking/types/msg.go | 6 ------ 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a274f41ec1..d187bed81727 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -164,6 +164,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` in simulation. * (x/nft) [#14725](https://github.com/cosmos/cosmos-sdk/pull/14725) Extract NFT in its own go.mod and rename the package to `cosmossdk.io/x/nft`. * (tx) [#14634](https://github.com/cosmos/cosmos-sdk/pull/14634) Move the `tx` go module to `x/tx`. * (snapshots) [#14597](https://github.com/cosmos/cosmos-sdk/pull/14597) Move `snapshots` to `store/snapshots`, rename and bump proto package to v1. diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 25b5cce4c33c..208f8cb340a2 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -395,12 +395,6 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.Validate() } -// Route implements the sdk.Msg interface. -func (msg MsgUpdateParams) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } - // GetSignBytes returns the raw bytes for a MsgUpdateParams message that // the expected signer needs to sign. func (msg MsgUpdateParams) GetSignBytes() []byte { From 7b9f45814ae5b1932737fbf0682245db22ccc939 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 14:07:44 +0100 Subject: [PATCH 06/32] refactor: msgs --- testutil/testdata/tx.go | 7 +- types/simulation/types.go | 9 +- types/tx_msg.go | 10 ++ types/tx_msg_test.go | 2 - x/auth/migrations/legacytx/stdsign.go | 4 +- x/auth/vesting/types/msgs.go | 41 ++---- x/authz/msgs.go | 43 +------ x/authz/msgs_test.go | 2 +- x/bank/types/msgs.go | 24 +--- x/consensus/types/msgs.go | 14 +- x/crisis/types/msgs.go | 22 +--- x/distribution/types/msg.go | 51 +------- x/evidence/types/genesis_test.go | 8 -- x/evidence/types/msgs.go | 12 +- x/feegrant/msgs.go | 30 +---- x/feegrant/msgs_test.go | 2 +- x/gov/types/v1/msgs.go | 43 +------ x/gov/types/v1beta1/msgs.go | 38 +----- x/group/msgs.go | 178 ++++++++------------------ x/slashing/types/msg.go | 13 +- x/staking/types/msg.go | 56 ++------ x/upgrade/types/msgs.go | 17 +-- 22 files changed, 141 insertions(+), 485 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 3d659e77d5c8..a1b2550b7ca5 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -76,10 +76,11 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } } -var _ sdk.Msg = (*TestMsg)(nil) +var ( + _ sdk.Msg = (*TestMsg)(nil) + _ sdk.HasAminoSigningCapability = (*TestMsg)(nil) +) -func (msg *TestMsg) Route() string { return "TestMsg" } -func (msg *TestMsg) Type() string { return "Test message" } func (msg *TestMsg) GetSignBytes() []byte { bz, err := json.Marshal(msg.Signers) if err != nil { diff --git a/types/simulation/types.go b/types/simulation/types.go index 702e6b2e49ca..af0c72768b72 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) type WeightedProposalContent interface { @@ -78,13 +77,11 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper // NewOperationMsg - create a new operation message from sdk.Msg func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg { - if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { - return NewOperationMsgBasic(legacyMsg.Route(), legacyMsg.Type(), comment, ok, legacyMsg.GetSignBytes()) + if legacyMsg, okType := msg.(sdk.HasAminoSigningCapability); okType { + return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) } - bz := cdc.MustMarshalJSON(msg) - - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, bz) + return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, cdc.MustMarshalJSON(msg)) } // NoOpMsg - create a no-operation message diff --git a/types/tx_msg.go b/types/tx_msg.go index 41c647e57de5..dc5991ac77a9 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -25,6 +25,16 @@ type ( GetSigners() []AccAddress } + // Extension interface for Msg that require Amino Signing + // Replaces legacytx.LegacyMsg. + // Deprecated: use Msg instead. + HasAminoSigningCapability interface { + Msg + + // Get the canonical byte representation of the Msg. + GetSignBytes() []byte + } + // Fee defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. Fee interface { diff --git a/types/tx_msg_test.go b/types/tx_msg_test.go index 0366d4fb14bc..7a9a5b945dae 100644 --- a/types/tx_msg_test.go +++ b/types/tx_msg_test.go @@ -25,8 +25,6 @@ func (s *testMsgSuite) TestMsg() { msg := testdata.NewTestMsg(accAddr) s.Require().NotNil(msg) s.Require().True(accAddr.Equals(msg.GetSigners()[0])) - s.Require().Equal("TestMsg", msg.Route()) - s.Require().Equal("Test message", msg.Type()) s.Require().Nil(msg.ValidateBasic()) s.Require().NotPanics(func() { msg.GetSignBytes() }) } diff --git a/x/auth/migrations/legacytx/stdsign.go b/x/auth/migrations/legacytx/stdsign.go index 9467ee8027c8..f54bc5186b4c 100644 --- a/x/auth/migrations/legacytx/stdsign.go +++ b/x/auth/migrations/legacytx/stdsign.go @@ -55,9 +55,9 @@ type StdSignDoc struct { func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string, tip *tx.Tip) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - legacyMsg, ok := msg.(LegacyMsg) + legacyMsg, ok := msg.(sdk.HasAminoSigningCapability) if !ok { - panic(fmt.Errorf("expected %T when using amino JSON", (*LegacyMsg)(nil))) + panic(fmt.Errorf("expected %T when using amino JSON", (*sdk.HasAminoSigningCapability)(nil))) } msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes())) diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index fbce860cede4..74bf0384974b 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -7,20 +7,15 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// TypeMsgCreateVestingAccount defines the type value for a MsgCreateVestingAccount. -const TypeMsgCreateVestingAccount = "msg_create_vesting_account" - -// TypeMsgCreatePermanentLockedAccount defines the type value for a MsgCreatePermanentLockedAccount. -const TypeMsgCreatePermanentLockedAccount = "msg_create_permanent_locked_account" - -// TypeMsgCreatePeriodicVestingAccount defines the type value for a MsgCreateVestingAccount. -const TypeMsgCreatePeriodicVestingAccount = "msg_create_periodic_vesting_account" - -var _ sdk.Msg = &MsgCreateVestingAccount{} - -var _ sdk.Msg = &MsgCreatePermanentLockedAccount{} - -var _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} +var ( + _ sdk.Msg = &MsgCreateVestingAccount{} + _ sdk.Msg = &MsgCreatePermanentLockedAccount{} + _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} + + _ sdk.HasAminoSigningCapability = &MsgCreateVestingAccount{} + _ sdk.HasAminoSigningCapability = &MsgCreatePermanentLockedAccount{} + _ sdk.HasAminoSigningCapability = &MsgCreatePeriodicVestingAccount{} +) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. // @@ -35,12 +30,6 @@ func NewMsgCreateVestingAccount(fromAddr, toAddr sdk.AccAddress, amount sdk.Coin } } -// Route returns the message route for a MsgCreateVestingAccount. -func (msg MsgCreateVestingAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreateVestingAccount. -func (msg MsgCreateVestingAccount) Type() string { return TypeMsgCreateVestingAccount } - // ValidateBasic Implements Msg. func (msg MsgCreateVestingAccount) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -88,12 +77,6 @@ func NewMsgCreatePermanentLockedAccount(fromAddr, toAddr sdk.AccAddress, amount } } -// Route returns the message route for a MsgCreatePermanentLockedAccount. -func (msg MsgCreatePermanentLockedAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreatePermanentLockedAccount. -func (msg MsgCreatePermanentLockedAccount) Type() string { return TypeMsgCreatePermanentLockedAccount } - // ValidateBasic Implements Msg. func (msg MsgCreatePermanentLockedAccount) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -138,12 +121,6 @@ func NewMsgCreatePeriodicVestingAccount(fromAddr, toAddr sdk.AccAddress, startTi } } -// Route returns the message route for a MsgCreatePeriodicVestingAccount. -func (msg MsgCreatePeriodicVestingAccount) Route() string { return RouterKey } - -// Type returns the message type for a MsgCreatePeriodicVestingAccount. -func (msg MsgCreatePeriodicVestingAccount) Type() string { return TypeMsgCreatePeriodicVestingAccount } - // GetSigners returns the expected signers for a MsgCreatePeriodicVestingAccount. func (msg MsgCreatePeriodicVestingAccount) GetSigners() []sdk.AccAddress { from, err := sdk.AccAddressFromBech32(msg.FromAddress) diff --git a/x/authz/msgs.go b/x/authz/msgs.go index d3c2afe28d8d..33e0bb63a585 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -10,7 +10,6 @@ import ( cdctypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( @@ -19,9 +18,9 @@ var ( _ sdk.Msg = &MsgExec{} // For amino support. - _ legacytx.LegacyMsg = &MsgGrant{} - _ legacytx.LegacyMsg = &MsgRevoke{} - _ legacytx.LegacyMsg = &MsgExec{} + _ sdk.HasAminoSigningCapability = &MsgGrant{} + _ sdk.HasAminoSigningCapability = &MsgRevoke{} + _ sdk.HasAminoSigningCapability = &MsgExec{} _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} @@ -66,17 +65,7 @@ func (msg MsgGrant) ValidateBasic() error { return msg.Grant.ValidateBasic() } -// Type implements the LegacyMsg.Type method. -func (msg MsgGrant) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgGrant) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// GetSignBytes implements the LegacyMsg.GetSignBytes method. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -157,17 +146,7 @@ func (msg MsgRevoke) ValidateBasic() error { return nil } -// Type implements the LegacyMsg.Type method. -func (msg MsgRevoke) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgRevoke) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// GetSignBytes implements the LegacyMsg.GetSignBytes method. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -235,17 +214,7 @@ func (msg MsgExec) ValidateBasic() error { return nil } -// Type implements the LegacyMsg.Type method. -func (msg MsgExec) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgExec) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// GetSignBytes implements the LegacyMsg.GetSignBytes method. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/authz/msgs_test.go b/x/authz/msgs_test.go index 5d7eb3c39fb9..7a7070916d3f 100644 --- a/x/authz/msgs_test.go +++ b/x/authz/msgs_test.go @@ -165,7 +165,7 @@ func TestMsgGrantGetAuthorization(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg legacytx.LegacyMsg + var msg sdk.HasAminoSigningCapability blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC) expiresAt := blockTime.Add(time.Hour) msgSend := banktypes.MsgSend{FromAddress: "cosmos1ghi", ToAddress: "cosmos1jkl"} diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 5f0ad3197f29..09c63d42ef59 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -5,18 +5,14 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// bank message types -const ( - TypeMsgSend = "send" - TypeMsgMultiSend = "multisend" - TypeMsgSetSendEnabled = "set_send_enabled" - TypeMsgUpdateParams = "update_params" -) - var ( _ sdk.Msg = &MsgSend{} _ sdk.Msg = &MsgMultiSend{} _ sdk.Msg = &MsgUpdateParams{} + + _ sdk.HasAminoSigningCapability = &MsgSend{} + _ sdk.HasAminoSigningCapability = &MsgMultiSend{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgSend - construct a msg to send coins from one account to another. @@ -26,12 +22,6 @@ func NewMsgSend(fromAddr, toAddr sdk.AccAddress, amount sdk.Coins) *MsgSend { return &MsgSend{FromAddress: fromAddr.String(), ToAddress: toAddr.String(), Amount: amount} } -// Route Implements Msg. -func (msg MsgSend) Route() string { return RouterKey } - -// Type Implements Msg. -func (msg MsgSend) Type() string { return TypeMsgSend } - // ValidateBasic Implements Msg. func (msg MsgSend) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.FromAddress); err != nil { @@ -69,12 +59,6 @@ func NewMsgMultiSend(in []Input, out []Output) *MsgMultiSend { return &MsgMultiSend{Inputs: in, Outputs: out} } -// Route Implements Msg -func (msg MsgMultiSend) Route() string { return RouterKey } - -// Type Implements Msg -func (msg MsgMultiSend) Type() string { return TypeMsgMultiSend } - // ValidateBasic Implements Msg. func (msg MsgMultiSend) ValidateBasic() error { // this just makes sure the input and all the outputs are properly formatted, diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 3d94883a7730..7671427c8b78 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -5,14 +5,16 @@ import ( tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) const ( TypeMsgUpdateParams = "update_params" ) -var _ legacytx.LegacyMsg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} +) // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. @@ -27,14 +29,6 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } -func (msg MsgUpdateParams) Route() string { - return sdk.MsgTypeURL(&msg) -} - -func (msg MsgUpdateParams) Type() string { - return sdk.MsgTypeURL(&msg) -} - // ValidateBasic performs basic MsgUpdateParams message validation. func (msg MsgUpdateParams) ValidateBasic() error { params := tmtypes.ConsensusParamsFromProto(msg.ToProtoConsensusParams()) diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index c2e2942ba13c..43b379409132 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -5,13 +5,11 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -const ( - TypeMsgVerifyInvariant = "verify_invariant" - TypeMsgUpdateParams = "update_params" -) - // ensure Msg interface compliance at compile time -var _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} +var ( + _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ sdk.HasAminoSigningCapability = &MsgVerifyInvariant{}, &MsgUpdateParams{} +) // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object // @@ -24,12 +22,6 @@ func NewMsgVerifyInvariant(sender sdk.AccAddress, invModeName, invRoute string) } } -// Route returns the MsgVerifyInvariant's route. -func (msg MsgVerifyInvariant) Route() string { return ModuleName } - -// Type returns the MsgVerifyInvariant's type. -func (msg MsgVerifyInvariant) Type() string { return TypeMsgVerifyInvariant } - // get the bytes for the message signer to sign on func (msg MsgVerifyInvariant) GetSigners() []sdk.AccAddress { sender, _ := sdk.AccAddressFromBech32(msg.Sender) @@ -55,12 +47,6 @@ func (msg MsgVerifyInvariant) FullInvariantRoute() string { return msg.InvariantModuleName + "/" + msg.InvariantRoute } -// Route returns the MsgUpdateParams's route. -func (msg MsgUpdateParams) Route() string { return ModuleName } - -// Type returns the MsgUpdateParams's type. -func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index e13d1bdc506e..c5da45de29a6 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -7,17 +7,6 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// distribution message types -const ( - TypeMsgSetWithdrawAddress = "set_withdraw_address" - TypeMsgWithdrawDelegatorReward = "withdraw_delegator_reward" - TypeMsgWithdrawValidatorCommission = "withdraw_validator_commission" - TypeMsgFundCommunityPool = "fund_community_pool" - TypeMsgUpdateParams = "update_params" - TypeMsgCommunityPoolSpend = "community_pool_spend" - TypeMsgDepositValidatorRewardsPool = "deposit_validator_rewards_pool" -) - // Verify interface at compile time var ( _ sdk.Msg = (*MsgSetWithdrawAddress)(nil) @@ -26,6 +15,13 @@ var ( _ sdk.Msg = (*MsgUpdateParams)(nil) _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) + + _ sdk.HasAminoSigningCapability = (*MsgSetWithdrawAddress)(nil) + _ sdk.HasAminoSigningCapability = (*MsgWithdrawDelegatorReward)(nil) + _ sdk.HasAminoSigningCapability = (*MsgWithdrawValidatorCommission)(nil) + _ sdk.HasAminoSigningCapability = (*MsgUpdateParams)(nil) + _ sdk.HasAminoSigningCapability = (*MsgCommunityPoolSpend)(nil) + _ sdk.HasAminoSigningCapability = (*MsgDepositValidatorRewardsPool)(nil) ) func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { @@ -35,9 +31,6 @@ func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithd } } -func (msg MsgSetWithdrawAddress) Route() string { return ModuleName } -func (msg MsgSetWithdrawAddress) Type() string { return TypeMsgSetWithdrawAddress } - // Return address that must sign over msg.GetSignBytes() func (msg MsgSetWithdrawAddress) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -69,9 +62,6 @@ func NewMsgWithdrawDelegatorReward(delAddr sdk.AccAddress, valAddr sdk.ValAddres } } -func (msg MsgWithdrawDelegatorReward) Route() string { return ModuleName } -func (msg MsgWithdrawDelegatorReward) Type() string { return TypeMsgWithdrawDelegatorReward } - // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawDelegatorReward) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -101,9 +91,6 @@ func NewMsgWithdrawValidatorCommission(valAddr sdk.ValAddress) *MsgWithdrawValid } } -func (msg MsgWithdrawValidatorCommission) Route() string { return ModuleName } -func (msg MsgWithdrawValidatorCommission) Type() string { return TypeMsgWithdrawValidatorCommission } - // Return address that must sign over msg.GetSignBytes() func (msg MsgWithdrawValidatorCommission) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) @@ -133,12 +120,6 @@ func NewMsgFundCommunityPool(amount sdk.Coins, depositor sdk.AccAddress) *MsgFun } } -// Route returns the MsgFundCommunityPool message route. -func (msg MsgFundCommunityPool) Route() string { return ModuleName } - -// Type returns the MsgFundCommunityPool message type. -func (msg MsgFundCommunityPool) Type() string { return TypeMsgFundCommunityPool } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgFundCommunityPool) GetSigners() []sdk.AccAddress { @@ -164,12 +145,6 @@ func (msg MsgFundCommunityPool) ValidateBasic() error { return nil } -// Route returns the MsgUpdateParams message route. -func (msg MsgUpdateParams) Route() string { return ModuleName } - -// Type returns the MsgUpdateParams message type. -func (msg MsgUpdateParams) Type() string { return TypeMsgUpdateParams } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes. func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { @@ -198,12 +173,6 @@ func (msg MsgUpdateParams) ValidateBasic() error { return msg.Params.ValidateBasic() } -// Route returns the MsgCommunityPoolSpend message route. -func (msg MsgCommunityPoolSpend) Route() string { return ModuleName } - -// Type returns the MsgCommunityPoolSpend message type. -func (msg MsgCommunityPoolSpend) Type() string { return TypeMsgCommunityPoolSpend } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes, which is the authority. func (msg MsgCommunityPoolSpend) GetSigners() []sdk.AccAddress { @@ -237,12 +206,6 @@ func NewMsgDepositValidatorRewardsPool(depositor sdk.AccAddress, valAddr sdk.Val } } -// Route returns the MsgDepositValidatorRewardsPool message route. -func (msg MsgDepositValidatorRewardsPool) Route() string { return ModuleName } - -// Type returns the MsgDepositValidatorRewardsPool message type. -func (msg MsgDepositValidatorRewardsPool) Type() string { return TypeMsgDepositValidatorRewardsPool } - // GetSigners returns the signer addresses that are expected to sign the result // of GetSignBytes, which is the authority. func (msg MsgDepositValidatorRewardsPool) GetSigners() []sdk.AccAddress { diff --git a/x/evidence/types/genesis_test.go b/x/evidence/types/genesis_test.go index e1738ef47ec0..79c57ef4c2d6 100644 --- a/x/evidence/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -160,14 +160,6 @@ type TestEvidence struct{} var _ exported.Evidence = &TestEvidence{} -func (*TestEvidence) Route() string { - return "test-route" -} - -func (*TestEvidence) Type() string { - return "test-type" -} - func (*TestEvidence) String() string { return "test-string" } diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index c12e140ee074..4b422f0a2766 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -11,13 +11,9 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// Message types for the evidence module -const ( - TypeMsgSubmitEvidence = "submit_evidence" -) - var ( _ sdk.Msg = &MsgSubmitEvidence{} + _ sdk.HasAminoSigningCapability = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) @@ -37,12 +33,6 @@ func NewMsgSubmitEvidence(s sdk.AccAddress, evi exported.Evidence) (*MsgSubmitEv return &MsgSubmitEvidence{Submitter: s.String(), Evidence: any}, nil } -// Route returns the MsgSubmitEvidence's route. -func (m MsgSubmitEvidence) Route() string { return RouterKey } - -// Type returns the MsgSubmitEvidence's type. -func (m MsgSubmitEvidence) Type() string { return TypeMsgSubmitEvidence } - // ValidateBasic performs basic (non-state-dependant) validation on a MsgSubmitEvidence. func (m MsgSubmitEvidence) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Submitter); err != nil { diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 4b4d1b3b3a37..24929ddcdda1 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -6,12 +6,12 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( - _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} - _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. + _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + // For amino support. + _, _ sdk.HasAminoSigningCapability = &MsgGrantAllowance{}, &MsgRevokeAllowance{} _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) @@ -61,17 +61,7 @@ func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// Type implements the LegacyMsg.Type method. -func (msg MsgGrantAllowance) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgGrantAllowance) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// GetSignBytes implements the LegacyMsg.GetSignBytes method. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -122,17 +112,7 @@ func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// Type implements the LegacyMsg.Type method. -func (msg MsgRevokeAllowance) Type() string { - return sdk.MsgTypeURL(&msg) -} - -// Route implements the LegacyMsg.Route method. -func (msg MsgRevokeAllowance) Route() string { - return sdk.MsgTypeURL(&msg) -} - -// GetSignBytes implements the LegacyMsg.GetSignBytes method. +// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index f33849557c97..383c08b771c6 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -136,7 +136,7 @@ func TestMsgRevokeAllowance(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg legacytx.LegacyMsg + var msg sdk.HasAminoSigningCapability allowanceAny, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100)))}) require.NoError(t, err) diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index 93d391644de2..8b07191e7031 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -16,6 +16,7 @@ import ( var ( _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} ) @@ -46,12 +47,6 @@ func (m *MsgSubmitProposal) GetMsgs() ([]sdk.Msg, error) { return sdktx.GetMsgs(m.Messages, "sdk.MsgProposal") } -// Route implements the sdk.Msg interface. -func (m MsgSubmitProposal) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } - // ValidateBasic implements the sdk.Msg interface. func (m MsgSubmitProposal) ValidateBasic() error { if m.Title == "" { @@ -118,12 +113,6 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins return &MsgDeposit{proposalID, depositor.String(), amount} } -// Route implements the sdk.Msg interface. -func (msg MsgDeposit) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDeposit) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgDeposit) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil { @@ -159,12 +148,6 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption, meta return &MsgVote{proposalID, voter.String(), option, metadata} } -// Route implements the sdk.Msg interface. -func (msg MsgVote) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVote) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVote) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -196,12 +179,6 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte return &MsgVoteWeighted{proposalID, voter.String(), options, metadata} } -// Route implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVoteWeighted) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -261,6 +238,12 @@ func NewMsgExecLegacyContent(content *codectypes.Any, authority string) *MsgExec } } +// GetSignBytes returns the message bytes to sign over. +func (c MsgExecLegacyContent) GetSignBytes() []byte { + bz := codec.ModuleCdc.MustMarshalJSON(&c) + return sdk.MustSortJSON(bz) +} + // GetSigners returns the expected signers for a MsgExecLegacyContent. func (c MsgExecLegacyContent) GetSigners() []sdk.AccAddress { authority, _ := sdk.AccAddressFromBech32(c.Authority) @@ -283,12 +266,6 @@ func (c MsgExecLegacyContent) UnpackInterfaces(unpacker codectypes.AnyUnpacker) return unpacker.UnpackAny(c.Content, &content) } -// Route implements the sdk.Msg interface. -func (msg MsgUpdateParams) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUpdateParams) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { @@ -320,12 +297,6 @@ func NewMsgCancelProposal(proposalID uint64, proposer string) *MsgCancelProposal } } -// Route implements Msg -func (msg MsgCancelProposal) Route() string { return types.RouterKey } - -// Type implements Msg -func (msg MsgCancelProposal) Type() string { return sdk.MsgTypeURL(&msg) } - // ValidateBasic implements Msg func (msg MsgCancelProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Proposer); err != nil { diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 248f46a30e2d..73a440795cab 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -13,17 +13,11 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) -// Governance message types and routes -const ( - TypeMsgDeposit = "deposit" - TypeMsgVote = "vote" - TypeMsgVoteWeighted = "weighted_vote" - TypeMsgSubmitProposal = "submit_proposal" -) - var ( - _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} - _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} + _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + + _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -83,12 +77,6 @@ func (m *MsgSubmitProposal) SetContent(content Content) error { return nil } -// Route implements the sdk.Msg interface. -func (m MsgSubmitProposal) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (m MsgSubmitProposal) Type() string { return TypeMsgSubmitProposal } - // ValidateBasic implements the sdk.Msg interface. func (m MsgSubmitProposal) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Proposer); err != nil { @@ -140,12 +128,6 @@ func NewMsgDeposit(depositor sdk.AccAddress, proposalID uint64, amount sdk.Coins return &MsgDeposit{proposalID, depositor.String(), amount} } -// Route implements the sdk.Msg interface. -func (msg MsgDeposit) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDeposit) Type() string { return TypeMsgDeposit } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgDeposit) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Depositor); err != nil { @@ -180,12 +162,6 @@ func NewMsgVote(voter sdk.AccAddress, proposalID uint64, option VoteOption) *Msg return &MsgVote{proposalID, voter.String(), option} } -// Route implements the sdk.Msg interface. -func (msg MsgVote) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVote) Type() string { return TypeMsgVote } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVote) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { @@ -217,12 +193,6 @@ func NewMsgVoteWeighted(voter sdk.AccAddress, proposalID uint64, options Weighte return &MsgVoteWeighted{proposalID, voter.String(), options} } -// Route implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Route() string { return types.RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgVoteWeighted) Type() string { return TypeMsgVoteWeighted } - // ValidateBasic implements the sdk.Msg interface. func (msg MsgVoteWeighted) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Voter); err != nil { diff --git a/x/group/msgs.go b/x/group/msgs.go index ced5c0e18460..624bbc603680 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -12,13 +12,10 @@ import ( "github.com/cosmos/cosmos-sdk/x/group/internal/math" ) -var _ sdk.Msg = &MsgCreateGroup{} - -// Route Implements Msg. -func (m MsgCreateGroup) Route() string { return sdk.MsgTypeURL(&m) } - -// Type Implements Msg. -func (m MsgCreateGroup) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgCreateGroup{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroup{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroup) GetSignBytes() []byte { @@ -60,15 +57,10 @@ func (m MemberRequest) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgUpdateGroupAdmin{} - -// Route Implements Msg. -func (m MsgUpdateGroupAdmin) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupAdmin) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupAdmin{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupAdmin) GetSignBytes() []byte { @@ -109,15 +101,10 @@ func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 { return m.GroupId } -var _ sdk.Msg = &MsgUpdateGroupMetadata{} - -// Route Implements Msg. -func (m MsgUpdateGroupMetadata) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupMetadata) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupMetadata{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMetadata) GetSignBytes() []byte { @@ -149,15 +136,10 @@ func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 { return m.GroupId } -var _ sdk.Msg = &MsgUpdateGroupMembers{} - -// Route Implements Msg. -func (m MsgUpdateGroupMembers) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupMembers) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupMembers{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMembers{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupMembers) GetSignBytes() []byte { @@ -200,6 +182,8 @@ func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { var ( _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupWithPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{} ) @@ -244,16 +228,6 @@ func (m MsgCreateGroupWithPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) e return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -// Route Implements Msg. -func (m MsgCreateGroupWithPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgCreateGroupWithPolicy) Type() string { - return sdk.MsgTypeURL(&m) -} - // GetSignBytes Implements Msg. func (m MsgCreateGroupWithPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -282,15 +256,10 @@ func (m MsgCreateGroupWithPolicy) ValidateBasic() error { return strictValidateMembers(m.Members) } -var _ sdk.Msg = &MsgCreateGroupPolicy{} - -// Route Implements Msg. -func (m MsgCreateGroupPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgCreateGroupPolicy) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} +) // GetSignBytes Implements Msg. func (m MsgCreateGroupPolicy) GetSignBytes() []byte { @@ -324,15 +293,10 @@ func (m MsgCreateGroupPolicy) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} - -// Route Implements Msg. -func (m MsgUpdateGroupPolicyAdmin) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyAdmin) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyAdmin{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyAdmin) GetSignBytes() []byte { @@ -371,6 +335,8 @@ func (m MsgUpdateGroupPolicyAdmin) ValidateBasic() error { var ( _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyDecisionPolicy{} + _ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{} ) @@ -401,16 +367,6 @@ func (m *MsgUpdateGroupPolicyDecisionPolicy) SetDecisionPolicy(decisionPolicy De return nil } -// Route Implements Msg. -func (m MsgUpdateGroupPolicyDecisionPolicy) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyDecisionPolicy) Type() string { - return sdk.MsgTypeURL(&m) -} - // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyDecisionPolicy) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -463,15 +419,10 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) UnpackInterfaces(unpacker types.AnyU return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -var _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} - -// Route Implements Msg. -func (m MsgUpdateGroupPolicyMetadata) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgUpdateGroupPolicyMetadata) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} + _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyMetadata{} +) // GetSignBytes Implements Msg. func (m MsgUpdateGroupPolicyMetadata) GetSignBytes() []byte { @@ -502,6 +453,8 @@ func (m MsgUpdateGroupPolicyMetadata) ValidateBasic() error { var ( _ sdk.Msg = &MsgCreateGroupPolicy{} + _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{} ) @@ -559,7 +512,10 @@ func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error return unpacker.UnpackAny(m.DecisionPolicy, &decisionPolicy) } -var _ sdk.Msg = &MsgSubmitProposal{} +var ( + _ sdk.Msg = &MsgSubmitProposal{} + _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{} +) // NewMsgSubmitProposal creates a new MsgSubmitProposal. func NewMsgSubmitProposal(address string, proposers []string, msgs []sdk.Msg, metadata string, exec Exec, title, summary string) (*MsgSubmitProposal, error) { @@ -578,14 +534,6 @@ func NewMsgSubmitProposal(address string, proposers []string, msgs []sdk.Msg, me return m, nil } -// Route Implements Msg. -func (m MsgSubmitProposal) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgSubmitProposal) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes Implements Msg. func (m MsgSubmitProposal) GetSignBytes() []byte { return sdk.MustSortJSON(codec.ModuleCdc.MustMarshalJSON(&m)) @@ -678,13 +626,10 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error { return tx.UnpackInterfaces(unpacker, m.Messages) } -var _ sdk.Msg = &MsgWithdrawProposal{} - -// Route Implements Msg. -func (m MsgWithdrawProposal) Route() string { return sdk.MsgTypeURL(&m) } - -// Type Implements Msg. -func (m MsgWithdrawProposal) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgWithdrawProposal{} + _ sdk.HasAminoSigningCapability = &MsgWithdrawProposal{} +) // GetSignBytes Implements Msg. func (m MsgWithdrawProposal) GetSignBytes() []byte { @@ -712,15 +657,10 @@ func (m MsgWithdrawProposal) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgVote{} - -// Route Implements Msg. -func (m MsgVote) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgVote) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgVote{} + _ sdk.HasAminoSigningCapability = &MsgVote{} +) // GetSignBytes Implements Msg. func (m MsgVote) GetSignBytes() []byte { @@ -752,15 +692,10 @@ func (m MsgVote) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgExec{} - -// Route Implements Msg. -func (m MsgExec) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg. -func (m MsgExec) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgExec{} + _ sdk.HasAminoSigningCapability = &MsgExec{} +) // GetSignBytes Implements Msg. func (m MsgExec) GetSignBytes() []byte { @@ -786,15 +721,10 @@ func (m MsgExec) ValidateBasic() error { return nil } -var _ sdk.Msg = &MsgLeaveGroup{} - -// Route Implements Msg -func (m MsgLeaveGroup) Route() string { - return sdk.MsgTypeURL(&m) -} - -// Type Implements Msg -func (m MsgLeaveGroup) Type() string { return sdk.MsgTypeURL(&m) } +var ( + _ sdk.Msg = &MsgLeaveGroup{} + _ sdk.HasAminoSigningCapability = &MsgLeaveGroup{} +) // GetSignBytes Implements Msg func (m MsgLeaveGroup) GetSignBytes() []byte { diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 4f958ec1a456..8dafa411530d 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -14,6 +14,9 @@ const ( var ( _ sdk.Msg = &MsgUnjail{} _ sdk.Msg = &MsgUpdateParams{} + + _ sdk.HasAminoSigningCapability = &MsgUnjail{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgUnjail creates a new MsgUnjail instance @@ -25,12 +28,6 @@ func NewMsgUnjail(validatorAddr sdk.ValAddress) *MsgUnjail { } } -// Route implements the sdk.Msg interface. -func (msg MsgUnjail) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUnjail) Type() string { return TypeMsgUnjail } - // GetSigners returns the expected signers for MsgUnjail. func (msg MsgUnjail) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddr) @@ -57,13 +54,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 588e54df52e5..ea18e1d8284f 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -8,27 +8,23 @@ import ( sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) -// staking message types -const ( - TypeMsgUndelegate = "begin_unbonding" - TypeMsgCancelUnbondingDelegation = "cancel_unbond" - TypeMsgEditValidator = "edit_validator" - TypeMsgCreateValidator = "create_validator" - TypeMsgDelegate = "delegate" - TypeMsgBeginRedelegate = "begin_redelegate" - TypeMsgUpdateParams = "update_params" -) - var ( _ sdk.Msg = &MsgCreateValidator{} _ codectypes.UnpackInterfacesMessage = (*MsgCreateValidator)(nil) - _ sdk.Msg = &MsgCreateValidator{} _ sdk.Msg = &MsgEditValidator{} _ sdk.Msg = &MsgDelegate{} _ sdk.Msg = &MsgUndelegate{} _ sdk.Msg = &MsgBeginRedelegate{} _ sdk.Msg = &MsgCancelUnbondingDelegation{} _ sdk.Msg = &MsgUpdateParams{} + + _ sdk.HasAminoSigningCapability = &MsgCreateValidator{} + _ sdk.HasAminoSigningCapability = &MsgEditValidator{} + _ sdk.HasAminoSigningCapability = &MsgDelegate{} + _ sdk.HasAminoSigningCapability = &MsgUndelegate{} + _ sdk.HasAminoSigningCapability = &MsgBeginRedelegate{} + _ sdk.HasAminoSigningCapability = &MsgCancelUnbondingDelegation{} + _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} ) // NewMsgCreateValidator creates a new MsgCreateValidator instance. @@ -54,12 +50,6 @@ func NewMsgCreateValidator( }, nil } -// Route implements the sdk.Msg interface. -func (msg MsgCreateValidator) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgCreateValidator) Type() string { return TypeMsgCreateValidator } - // GetSigners implements the sdk.Msg interface. It returns the address(es) that // must sign over msg.GetSignBytes(). // If the validator address is not same as delegator's, then the validator must @@ -138,12 +128,6 @@ func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRat } } -// Route implements the sdk.Msg interface. -func (msg MsgEditValidator) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgEditValidator) Type() string { return TypeMsgEditValidator } - // GetSigners implements the sdk.Msg interface. func (msg MsgEditValidator) GetSigners() []sdk.AccAddress { valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress) @@ -193,12 +177,6 @@ func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.C } } -// Route implements the sdk.Msg interface. -func (msg MsgDelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgDelegate) Type() string { return TypeMsgDelegate } - // GetSigners implements the sdk.Msg interface. func (msg MsgDelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -244,12 +222,6 @@ func NewMsgBeginRedelegate( } } -// Route implements the sdk.Msg interface. -func (msg MsgBeginRedelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface -func (msg MsgBeginRedelegate) Type() string { return TypeMsgBeginRedelegate } - // GetSigners implements the sdk.Msg interface func (msg MsgBeginRedelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -295,12 +267,6 @@ func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk } } -// Route implements the sdk.Msg interface. -func (msg MsgUndelegate) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgUndelegate) Type() string { return TypeMsgUndelegate } - // GetSigners implements the sdk.Msg interface. func (msg MsgUndelegate) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) @@ -344,12 +310,6 @@ func NewMsgCancelUnbondingDelegation(delAddr sdk.AccAddress, valAddr sdk.ValAddr } } -// Route implements the sdk.Msg interface. -func (msg MsgCancelUnbondingDelegation) Route() string { return RouterKey } - -// Type implements the sdk.Msg interface. -func (msg MsgCancelUnbondingDelegation) Type() string { return TypeMsgCancelUnbondingDelegation } - // GetSigners implements the sdk.Msg interface. func (msg MsgCancelUnbondingDelegation) GetSigners() []sdk.AccAddress { delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress) diff --git a/x/upgrade/types/msgs.go b/x/upgrade/types/msgs.go index 86dc6a1338b2..85f036c3173a 100644 --- a/x/upgrade/types/msgs.go +++ b/x/upgrade/types/msgs.go @@ -3,20 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( - _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} - _, _ legacytx.LegacyMsg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.HasAminoSigningCapability = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} ) -// Route implements the LegacyMsg interface. -func (m MsgSoftwareUpgrade) Route() string { return sdk.MsgTypeURL(&m) } - -// Type implements the LegacyMsg interface. -func (m MsgSoftwareUpgrade) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes implements the LegacyMsg interface. func (m MsgSoftwareUpgrade) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) @@ -41,12 +34,6 @@ func (m *MsgSoftwareUpgrade) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{addr} } -// Route implements the LegacyMsg interface. -func (m MsgCancelUpgrade) Route() string { return sdk.MsgTypeURL(&m) } - -// Type implements the LegacyMsg interface. -func (m MsgCancelUpgrade) Type() string { return sdk.MsgTypeURL(&m) } - // GetSignBytes implements the LegacyMsg interface. func (m MsgCancelUpgrade) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&m)) From afaf035f284a0c115e730e1ca23867f72d58dda3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 14:40:36 +0100 Subject: [PATCH 07/32] renaming --- testutil/testdata/tx.go | 5 +- types/simulation/types.go | 3 +- types/tx_msg.go | 10 -- x/auth/migrations/legacytx/stdsign.go | 16 +--- x/auth/types/msgs.go | 10 +- x/auth/vesting/types/msgs.go | 7 +- x/authz/msgs.go | 7 +- x/authz/msgs_test.go | 2 +- x/bank/simulation/operations.go | 31 ++++--- x/bank/simulation/operations_test.go | 16 ++-- x/bank/types/msgs.go | 7 +- x/bank/types/msgs_test.go | 25 ----- x/consensus/types/msgs.go | 9 +- x/crisis/types/msgs.go | 5 +- x/distribution/simulation/operations.go | 22 ++--- x/distribution/simulation/operations_test.go | 8 +- x/distribution/types/msg.go | 13 +-- x/evidence/types/msgs.go | 3 +- x/feegrant/msgs.go | 3 +- x/feegrant/msgs_test.go | 2 +- x/feegrant/simulation/operations.go | 2 - x/gov/simulation/operations.go | 16 ++-- x/gov/simulation/operations_test.go | 10 +- x/gov/types/v1/msgs.go | 3 +- x/gov/types/v1beta1/msgs.go | 5 +- x/group/msgs.go | 61 ++++++------ x/group/msgs_test.go | 28 +++--- x/group/simulation/operations.go | 90 +++++++++--------- x/mint/types/msgs.go | 10 +- x/simulation/util.go | 9 +- x/slashing/simulation/operations.go | 20 ++-- x/slashing/simulation/operations_test.go | 3 +- x/slashing/types/msg.go | 10 +- x/staking/keeper/msg_server.go | 6 +- x/staking/simulation/operations.go | 97 ++++++++++---------- x/staking/simulation/operations_test.go | 12 +-- x/staking/types/msg.go | 23 ++--- x/upgrade/types/msgs.go | 5 +- x/upgrade/types/msgs_test.go | 2 - 39 files changed, 292 insertions(+), 324 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index a1b2550b7ca5..6053a903319e 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -13,6 +13,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // AddressGenerator creates and returns a random address generator using rapid. @@ -77,8 +78,8 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } var ( - _ sdk.Msg = (*TestMsg)(nil) - _ sdk.HasAminoSigningCapability = (*TestMsg)(nil) + _ sdk.Msg = (*TestMsg)(nil) + _ legacytx.LegacyMsg = (*TestMsg)(nil) ) func (msg *TestMsg) GetSignBytes() []byte { diff --git a/types/simulation/types.go b/types/simulation/types.go index af0c72768b72..4d6560e22970 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -9,6 +9,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/kv" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) type WeightedProposalContent interface { @@ -77,7 +78,7 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper // NewOperationMsg - create a new operation message from sdk.Msg func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg { - if legacyMsg, okType := msg.(sdk.HasAminoSigningCapability); okType { + if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) } diff --git a/types/tx_msg.go b/types/tx_msg.go index dc5991ac77a9..41c647e57de5 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -25,16 +25,6 @@ type ( GetSigners() []AccAddress } - // Extension interface for Msg that require Amino Signing - // Replaces legacytx.LegacyMsg. - // Deprecated: use Msg instead. - HasAminoSigningCapability interface { - Msg - - // Get the canonical byte representation of the Msg. - GetSignBytes() []byte - } - // Fee defines an interface for an application application-defined concrete // transaction type to be able to set and return the transaction fee. Fee interface { diff --git a/x/auth/migrations/legacytx/stdsign.go b/x/auth/migrations/legacytx/stdsign.go index f54bc5186b4c..634a5ef27dcb 100644 --- a/x/auth/migrations/legacytx/stdsign.go +++ b/x/auth/migrations/legacytx/stdsign.go @@ -17,22 +17,14 @@ import ( "github.com/cosmos/cosmos-sdk/types/tx/signing" ) -// LegacyMsg defines the old interface a message must fulfill, containing -// Amino signing method and legacy router info. +// LegacyMsg defines the old interface a message must fulfill, +// containing Amino signing method. // Deprecated: Please use `Msg` instead. type LegacyMsg interface { sdk.Msg // Get the canonical byte representation of the Msg. GetSignBytes() []byte - - // Return the message type. - // Must be alphanumeric or empty. - Route() string - - // Returns a human-readable string for the message, intended for utilization - // within tags - Type() string } // StdSignDoc is replay-prevention structure. @@ -55,9 +47,9 @@ type StdSignDoc struct { func StdSignBytes(chainID string, accnum, sequence, timeout uint64, fee StdFee, msgs []sdk.Msg, memo string, tip *tx.Tip) []byte { msgsBytes := make([]json.RawMessage, 0, len(msgs)) for _, msg := range msgs { - legacyMsg, ok := msg.(sdk.HasAminoSigningCapability) + legacyMsg, ok := msg.(LegacyMsg) if !ok { - panic(fmt.Errorf("expected %T when using amino JSON", (*sdk.HasAminoSigningCapability)(nil))) + panic(fmt.Errorf("expected %T when using amino JSON", (*LegacyMsg)(nil))) } msgsBytes = append(msgsBytes, json.RawMessage(legacyMsg.GetSignBytes())) diff --git a/x/auth/types/msgs.go b/x/auth/types/msgs.go index c0f25ee1e023..4220cfee5761 100644 --- a/x/auth/types/msgs.go +++ b/x/auth/types/msgs.go @@ -3,9 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -var _ sdk.Msg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} +) // GetSignBytes implements the LegacyMsg interface. func (msg MsgUpdateParams) GetSignBytes() []byte { @@ -13,13 +17,13 @@ func (msg MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (msg *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (msg MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(msg.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (msg *MsgUpdateParams) ValidateBasic() error { +func (msg MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(msg.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/auth/vesting/types/msgs.go b/x/auth/vesting/types/msgs.go index 74bf0384974b..f21fe53d1dff 100644 --- a/x/auth/vesting/types/msgs.go +++ b/x/auth/vesting/types/msgs.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( @@ -12,9 +13,9 @@ var ( _ sdk.Msg = &MsgCreatePermanentLockedAccount{} _ sdk.Msg = &MsgCreatePeriodicVestingAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreateVestingAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreatePermanentLockedAccount{} - _ sdk.HasAminoSigningCapability = &MsgCreatePeriodicVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreateVestingAccount{} + _ legacytx.LegacyMsg = &MsgCreatePermanentLockedAccount{} + _ legacytx.LegacyMsg = &MsgCreatePeriodicVestingAccount{} ) // NewMsgCreateVestingAccount returns a reference to a new MsgCreateVestingAccount. diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 33e0bb63a585..6957c91dcc3a 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -3,6 +3,7 @@ package authz import ( "time" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" authzcodec "github.com/cosmos/cosmos-sdk/x/authz/codec" "github.com/cosmos/gogoproto/proto" @@ -18,9 +19,9 @@ var ( _ sdk.Msg = &MsgExec{} // For amino support. - _ sdk.HasAminoSigningCapability = &MsgGrant{} - _ sdk.HasAminoSigningCapability = &MsgRevoke{} - _ sdk.HasAminoSigningCapability = &MsgExec{} + _ legacytx.LegacyMsg = &MsgGrant{} + _ legacytx.LegacyMsg = &MsgRevoke{} + _ legacytx.LegacyMsg = &MsgExec{} _ cdctypes.UnpackInterfacesMessage = &MsgGrant{} _ cdctypes.UnpackInterfacesMessage = &MsgExec{} diff --git a/x/authz/msgs_test.go b/x/authz/msgs_test.go index 7a7070916d3f..5d7eb3c39fb9 100644 --- a/x/authz/msgs_test.go +++ b/x/authz/msgs_test.go @@ -165,7 +165,7 @@ func TestMsgGrantGetAuthorization(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg sdk.HasAminoSigningCapability + var msg legacytx.LegacyMsg blockTime := time.Date(1, 1, 1, 1, 1, 1, 1, time.UTC) expiresAt := blockTime.Add(time.Hour) msgSend := banktypes.MsgSend{FromAddress: "cosmos1ghi", ToAddress: "cosmos1jkl"} diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 7818ebf1a2b6..68932910784f 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -62,27 +62,29 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + + msgType := sdk.MsgTypeURL(&types.MsgSend{}) from, to, coins, skip := randomSendFields(r, ctx, accs, bk, ak) // if coins slice is empty, we can not create valid types.MsgSend if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "empty coins slice"), nil, nil } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "skip all transfers"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "skip all transfers"), nil, nil } msg := types.NewMsgSend(from.Address, to.Address, coins) err := sendMsgSend(r, app, bk, ak, msg, ctx, chainID, []cryptotypes.PrivKey{from.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -96,27 +98,27 @@ func SimulateMsgSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keeper, mo r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgSend{}) from := accs[0] - to := getModuleAccounts(ak, ctx, moduleAccCount)[0] spendable := bk.SpendableCoins(ctx, from.Address) coins := simtypes.RandSubsetCoins(r, spendable) // if coins slice is empty, we can not create valid types.MsgSend if len(coins) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, "empty coins slice"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "empty coins slice"), nil, nil } // Check send_enabled status of each coin denom if err := bk.IsSendEnabledCoins(ctx, coins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } msg := types.NewMsgSend(from.Address, to.Address, coins) err := sendMsgSend(r, app, bk, ak, msg, ctx, chainID, []cryptotypes.PrivKey{from.PrivKey}) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -179,6 +181,8 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgMultiSend{}) + // random number of inputs/outputs between [1, 3] inputs := make([]types.Input, r.Intn(1)+1) //nolint:staticcheck // SA4030: (*math/rand.Rand).Intn(n) generates a random value 0 <= x < n; that is, the generated values don't include n; r.Intn(1) therefore always returns 0 outputs := make([]types.Output, r.Intn(3)+1) @@ -200,7 +204,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope } if skip { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, "skip all transfers"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "skip all transfers"), nil, nil } // set input address in used address map @@ -216,7 +220,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope // Check send_enabled status of each sent coin denom if err := bk.IsSendEnabledCoins(ctx, totalSentCoins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } for o := range outputs { @@ -254,7 +258,7 @@ func SimulateMsgMultiSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Ope } err := sendMsgMultiSend(r, app, bk, ak, msg, ctx, chainID, privs) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -267,6 +271,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgMultiSend{}) inputs := make([]types.Input, 2) outputs := make([]types.Output, moduleAccCount) // collect signer privKeys @@ -281,7 +286,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe totalSentCoins = totalSentCoins.Add(coins...) } if err := bk.IsSendEnabledCoins(ctx, totalSentCoins...); err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgMultiSend, err.Error()), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, err.Error()), nil, nil } moduleAccounts := getModuleAccounts(ak, ctx, moduleAccCount) for i := range outputs { @@ -313,7 +318,7 @@ func SimulateMsgMultiSendToModuleAccount(ak types.AccountKeeper, bk keeper.Keepe } err := sendMsgMultiSend(r, app, bk, ak, msg, ctx, chainID, privs) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "invalid transfers"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "invalid transfers"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 97128ebfa8a2..760281b92809 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -72,8 +72,8 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {100, types.ModuleName, types.TypeMsgSend}, - {10, types.ModuleName, types.TypeMsgMultiSend}, + {100, types.ModuleName, sdk.MsgTypeURL(&types.MsgSend{})}, + {10, types.ModuleName, sdk.MsgTypeURL(&types.MsgMultiSend{})}, } for i, w := range weightesOps { @@ -112,8 +112,7 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(types.TypeMsgSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -144,8 +143,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require.Len(msg.Outputs, 2) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Outputs[1].Address) require.Equal("107287087stake", msg.Outputs[1].Coins.String()) - require.Equal(types.TypeMsgMultiSend, msg.Type()) - require.Equal(types.ModuleName, msg.Route()) + require.Equal(types.TypeMsgMultiSend, sdk.MsgTypeURL(msg)) require.Len(futureOperations, 0) } @@ -176,8 +174,7 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -205,8 +202,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgMultiSend, msg.Type()) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(types.TypeMsgMultiSend, sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/bank/types/msgs.go b/x/bank/types/msgs.go index 09c63d42ef59..8bb09b461adb 100644 --- a/x/bank/types/msgs.go +++ b/x/bank/types/msgs.go @@ -3,6 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( @@ -10,9 +11,9 @@ var ( _ sdk.Msg = &MsgMultiSend{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgSend{} - _ sdk.HasAminoSigningCapability = &MsgMultiSend{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgSend{} + _ legacytx.LegacyMsg = &MsgMultiSend{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgSend - construct a msg to send coins from one account to another. diff --git a/x/bank/types/msgs_test.go b/x/bank/types/msgs_test.go index f2fc353521f0..7ce8399be3e1 100644 --- a/x/bank/types/msgs_test.go +++ b/x/bank/types/msgs_test.go @@ -11,16 +11,6 @@ import ( govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" ) -func TestMsgSendRoute(t *testing.T) { - addr1 := sdk.AccAddress([]byte("from")) - addr2 := sdk.AccAddress([]byte("to")) - coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - msg := NewMsgSend(addr1, addr2, coins) - - require.Equal(t, msg.Route(), RouterKey) - require.Equal(t, msg.Type(), "send") -} - func TestMsgSendValidation(t *testing.T) { addr1 := sdk.AccAddress([]byte("from________________")) addr2 := sdk.AccAddress([]byte("to__________________")) @@ -67,21 +57,6 @@ func TestMsgSendGetSignBytes(t *testing.T) { require.Equal(t, expected, string(res)) } -func TestMsgMultiSendRoute(t *testing.T) { - // Construct a MsgSend - addr1 := sdk.AccAddress([]byte("input")) - addr2 := sdk.AccAddress([]byte("output")) - coins := sdk.NewCoins(sdk.NewInt64Coin("atom", 10)) - msg := MsgMultiSend{ - Inputs: []Input{NewInput(addr1, coins)}, - Outputs: []Output{NewOutput(addr2, coins)}, - } - - // TODO some failures for bad result - require.Equal(t, msg.Route(), RouterKey) - require.Equal(t, msg.Type(), "multisend") -} - func TestInputValidation(t *testing.T) { addr1 := sdk.AccAddress([]byte("_______alice________")) addr2 := sdk.AccAddress([]byte("________bob_________")) diff --git a/x/consensus/types/msgs.go b/x/consensus/types/msgs.go index 7671427c8b78..10efaf60d83f 100644 --- a/x/consensus/types/msgs.go +++ b/x/consensus/types/msgs.go @@ -5,15 +5,12 @@ import ( tmtypes "github.com/tendermint/tendermint/types" sdk "github.com/cosmos/cosmos-sdk/types" -) - -const ( - TypeMsgUpdateParams = "update_params" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( - _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // GetSigners returns the signer addresses that are expected to sign the result diff --git a/x/crisis/types/msgs.go b/x/crisis/types/msgs.go index 43b379409132..665183b98a5f 100644 --- a/x/crisis/types/msgs.go +++ b/x/crisis/types/msgs.go @@ -3,12 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // ensure Msg interface compliance at compile time var ( - _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} - _, _ sdk.HasAminoSigningCapability = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ sdk.Msg = &MsgVerifyInvariant{}, &MsgUpdateParams{} + _, _ legacytx.LegacyMsg = &MsgVerifyInvariant{}, &MsgUpdateParams{} ) // NewMsgVerifyInvariant creates a new MsgVerifyInvariant object diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index d4c8caa61ebe..7f9e61d1d03d 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -91,7 +91,7 @@ func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKee r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { if !k.GetWithdrawAddrEnabled(ctx) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgSetWithdrawAddress, "withdrawal is not enabled"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), "withdrawal is not enabled"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) @@ -108,7 +108,6 @@ func SimulateMsgSetWithdrawAddress(txConfig client.TxConfig, ak types.AccountKee TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -129,14 +128,14 @@ func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.Accou simAccount, _ := simtypes.RandomAcc(r, accs) delegations := sk.GetAllDelegatorDelegations(ctx, simAccount.Address) if len(delegations) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawDelegatorReward, "number of delegators equal 0"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "number of delegators equal 0"), nil, nil } delegation := delegations[r.Intn(len(delegations))] validator := sk.Validator(ctx, delegation.GetValidatorAddr()) if validator == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawDelegatorReward, "validator is nil"), nil, fmt.Errorf("validator %s not found", delegation.GetValidatorAddr()) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), "validator is nil"), nil, fmt.Errorf("validator %s not found", delegation.GetValidatorAddr()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -150,7 +149,6 @@ func SimulateMsgWithdrawDelegatorReward(txConfig client.TxConfig, ak types.Accou TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -168,19 +166,21 @@ func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.A return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}) + validator, ok := testutil.RandSliceElem(r, sk.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "random validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "random validator is not ok"), nil, nil } commission := k.GetValidatorAccumulatedCommission(ctx, validator.GetOperator()) if commission.Commission.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "validator commission is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator commission is zero"), nil, nil } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(validator.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgWithdrawValidatorCommission, "could not find account"), nil, fmt.Errorf("validator %s not found", validator.GetOperator()) + return simtypes.NoOpMsg(types.ModuleName, msgType, "could not find account"), nil, fmt.Errorf("validator %s not found", validator.GetOperator()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -194,7 +194,6 @@ func SimulateMsgWithdrawValidatorCommission(txConfig client.TxConfig, ak types.A TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -220,7 +219,7 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep fundAmount := simtypes.RandSubsetCoins(r, spendable) if fundAmount.Empty() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgFundCommunityPool, "fund amount is empty"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "fund amount is empty"), nil, nil } var ( @@ -232,7 +231,7 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgFundCommunityPool, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), "unable to generate fees"), nil, err } } @@ -244,7 +243,6 @@ func SimulateMsgFundCommunityPool(txConfig client.TxConfig, ak types.AccountKeep TxGen: txConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: funder, AccountKeeper: ak, diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 66c43c5cb84e..3e7cf34a8cf6 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -84,7 +84,7 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(types.TypeMsgSetWithdrawAddress, msg.Type()) + suite.Require().Equal(types.TypeMsgSetWithdrawAddress, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -125,7 +125,7 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, msg.Type()) + suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -185,7 +185,7 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, msg.Type()) + suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } @@ -213,7 +213,7 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(types.TypeMsgFundCommunityPool, msg.Type()) + suite.Require().Equal(types.TypeMsgFundCommunityPool, sdk.MsgTypeURL(msg)) suite.Require().Equal(types.ModuleName, msg.Route()) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/types/msg.go b/x/distribution/types/msg.go index c5da45de29a6..1bd3edcdcc63 100644 --- a/x/distribution/types/msg.go +++ b/x/distribution/types/msg.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // Verify interface at compile time @@ -16,12 +17,12 @@ var ( _ sdk.Msg = (*MsgCommunityPoolSpend)(nil) _ sdk.Msg = (*MsgDepositValidatorRewardsPool)(nil) - _ sdk.HasAminoSigningCapability = (*MsgSetWithdrawAddress)(nil) - _ sdk.HasAminoSigningCapability = (*MsgWithdrawDelegatorReward)(nil) - _ sdk.HasAminoSigningCapability = (*MsgWithdrawValidatorCommission)(nil) - _ sdk.HasAminoSigningCapability = (*MsgUpdateParams)(nil) - _ sdk.HasAminoSigningCapability = (*MsgCommunityPoolSpend)(nil) - _ sdk.HasAminoSigningCapability = (*MsgDepositValidatorRewardsPool)(nil) + _ legacytx.LegacyMsg = (*MsgSetWithdrawAddress)(nil) + _ legacytx.LegacyMsg = (*MsgWithdrawDelegatorReward)(nil) + _ legacytx.LegacyMsg = (*MsgWithdrawValidatorCommission)(nil) + _ legacytx.LegacyMsg = (*MsgUpdateParams)(nil) + _ legacytx.LegacyMsg = (*MsgCommunityPoolSpend)(nil) + _ legacytx.LegacyMsg = (*MsgDepositValidatorRewardsPool)(nil) ) func NewMsgSetWithdrawAddress(delAddr, withdrawAddr sdk.AccAddress) *MsgSetWithdrawAddress { diff --git a/x/evidence/types/msgs.go b/x/evidence/types/msgs.go index 4b422f0a2766..25a99e6e0575 100644 --- a/x/evidence/types/msgs.go +++ b/x/evidence/types/msgs.go @@ -9,11 +9,12 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _ sdk.Msg = &MsgSubmitEvidence{} - _ sdk.HasAminoSigningCapability = &MsgSubmitEvidence{} + _ legacytx.LegacyMsg = &MsgSubmitEvidence{} _ types.UnpackInterfacesMessage = MsgSubmitEvidence{} _ exported.MsgSubmitEvidenceI = &MsgSubmitEvidence{} ) diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 24929ddcdda1..33af976e41ac 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -6,12 +6,13 @@ import ( "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( _, _ sdk.Msg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} // For amino support. - _, _ sdk.HasAminoSigningCapability = &MsgGrantAllowance{}, &MsgRevokeAllowance{} + _, _ legacytx.LegacyMsg = &MsgGrantAllowance{}, &MsgRevokeAllowance{} _ types.UnpackInterfacesMessage = &MsgGrantAllowance{} ) diff --git a/x/feegrant/msgs_test.go b/x/feegrant/msgs_test.go index 383c08b771c6..f33849557c97 100644 --- a/x/feegrant/msgs_test.go +++ b/x/feegrant/msgs_test.go @@ -136,7 +136,7 @@ func TestMsgRevokeAllowance(t *testing.T) { func TestAminoJSON(t *testing.T) { tx := legacytx.StdTx{} - var msg sdk.HasAminoSigningCapability + var msg legacytx.LegacyMsg allowanceAny, err := codectypes.NewAnyWithValue(&feegrant.BasicAllowance{SpendLimit: sdk.NewCoins(sdk.NewCoin("foo", sdk.NewInt(100)))}) require.NoError(t, err) diff --git a/x/feegrant/simulation/operations.go b/x/feegrant/simulation/operations.go index 4079a90ef9d4..023d2076e9e4 100644 --- a/x/feegrant/simulation/operations.go +++ b/x/feegrant/simulation/operations.go @@ -103,7 +103,6 @@ func SimulateMsgGrantAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper, TxGen: tx.NewTxConfig(cdc, tx.DefaultSignModes), Cdc: nil, Msg: msg, - MsgType: TypeMsgGrantAllowance, Context: ctx, SimAccount: granter, AccountKeeper: ak, @@ -153,7 +152,6 @@ func SimulateMsgRevokeAllowance(cdc *codec.ProtoCodec, ak feegrant.AccountKeeper TxGen: tx.NewTxConfig(cdc, tx.DefaultSignModes), Cdc: nil, Msg: &msg, - MsgType: TypeMsgRevokeAllowance, Context: ctx, SimAccount: granter, AccountKeeper: ak, diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 47f81408c7aa..7fb0059bb168 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -169,7 +169,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k msg, err := v1.NewMsgSubmitProposal([]sdk.Msg{contentMsg}, deposit, simAccount.Address.String(), "", "Title of proposal", "Short description of proposal") if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate a submit proposal msg"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err } account := ak.GetAccount(ctx, simAccount.Address) @@ -180,7 +180,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err } } @@ -197,12 +197,12 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } opMsg := simtypes.NewOperationMsg(msg, true, "", nil) @@ -210,7 +210,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k // get the submitted proposal ID proposalID, err := k.GetProposalID(ctx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate proposalID"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate proposalID"), nil, err } // 2) Schedule operations for votes @@ -268,7 +268,7 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.K if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err } } @@ -278,7 +278,6 @@ func SimulateMsgDeposit(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.K TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -328,7 +327,6 @@ func operationSimulateMsgVote(ak types.AccountKeeper, bk types.BankKeeper, k *ke TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -380,7 +378,6 @@ func operationSimulateMsgVoteWeighted(ak types.AccountKeeper, bk types.BankKeepe TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -420,7 +417,6 @@ func SimulateMsgCancelProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 4506314c9aa6..622293938d03 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -143,7 +143,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgSubmitProposal, msg.Type()) + require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(msg)) } // TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. @@ -188,7 +188,7 @@ func TestSimulateMsgCancelProposal(t *testing.T) { require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, proposer.String(), msg.Proposer) require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgCancelProposal, msg.Type()) + require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(msg)) } // TestSimulateMsgDeposit tests the normal scenario of a valid message of type TypeMsgDeposit. @@ -235,7 +235,7 @@ func TestSimulateMsgDeposit(t *testing.T) { require.NotEqual(t, len(msg.Amount), 0) require.Equal(t, "560969stake", msg.Amount[0].String()) require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgDeposit, msg.Type()) + require.Equal(t, simulation.TypeMsgDeposit, sdk.MsgTypeURL(msg)) } // TestSimulateMsgVote tests the normal scenario of a valid message of type TypeMsgVote. @@ -280,7 +280,7 @@ func TestSimulateMsgVote(t *testing.T) { require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.Equal(t, v1.OptionYes, msg.Option) require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgVote, msg.Type()) + require.Equal(t, simulation.TypeMsgVote, sdk.MsgTypeURL(msg)) } // TestSimulateMsgVoteWeighted tests the normal scenario of a valid message of type TypeMsgVoteWeighted. @@ -324,7 +324,7 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.True(t, len(msg.Options) >= 1) require.Equal(t, "gov", msg.Route()) - require.Equal(t, simulation.TypeMsgVoteWeighted, msg.Type()) + require.Equal(t, simulation.TypeMsgVoteWeighted, sdk.MsgTypeURL(msg)) } type suite struct { diff --git a/x/gov/types/v1/msgs.go b/x/gov/types/v1/msgs.go index 8b07191e7031..a40df3a7b8fd 100644 --- a/x/gov/types/v1/msgs.go +++ b/x/gov/types/v1/msgs.go @@ -9,6 +9,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" sdktx "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" @@ -16,7 +17,7 @@ import ( var ( _, _, _, _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} - _, _, _, _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} + _, _, _, _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{}, &MsgExecLegacyContent{}, &MsgUpdateParams{}, &MsgCancelProposal{} _, _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{}, &MsgExecLegacyContent{} ) diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 73a440795cab..6fb219deea96 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -9,13 +9,14 @@ import ( codectypes "github.com/cosmos/cosmos-sdk/codec/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov/codec" "github.com/cosmos/cosmos-sdk/x/gov/types" ) var ( - _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} - _, _, _, _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} + _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} _ codectypes.UnpackInterfacesMessage = &MsgSubmitProposal{} ) diff --git a/x/group/msgs.go b/x/group/msgs.go index 624bbc603680..71d1e7482aee 100644 --- a/x/group/msgs.go +++ b/x/group/msgs.go @@ -7,14 +7,15 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/group/codec" errors "github.com/cosmos/cosmos-sdk/x/group/errors" "github.com/cosmos/cosmos-sdk/x/group/internal/math" ) var ( - _ sdk.Msg = &MsgCreateGroup{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroup{} + _ sdk.Msg = &MsgCreateGroup{} + _ legacytx.LegacyMsg = &MsgCreateGroup{} ) // GetSignBytes Implements Msg. @@ -58,8 +59,8 @@ func (m MemberRequest) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupAdmin{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupAdmin{} + _ sdk.Msg = &MsgUpdateGroupAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupAdmin{} ) // GetSignBytes Implements Msg. @@ -102,8 +103,8 @@ func (m *MsgUpdateGroupAdmin) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgUpdateGroupMetadata{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMetadata{} + _ sdk.Msg = &MsgUpdateGroupMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMetadata{} ) // GetSignBytes Implements Msg. @@ -137,8 +138,8 @@ func (m *MsgUpdateGroupMetadata) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgUpdateGroupMembers{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupMembers{} + _ sdk.Msg = &MsgUpdateGroupMembers{} + _ legacytx.LegacyMsg = &MsgUpdateGroupMembers{} ) // GetSignBytes Implements Msg. @@ -181,8 +182,8 @@ func (m *MsgUpdateGroupMembers) GetGroupID() uint64 { } var ( - _ sdk.Msg = &MsgCreateGroupWithPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupWithPolicy{} + _ sdk.Msg = &MsgCreateGroupWithPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupWithPolicy{} _ types.UnpackInterfacesMessage = MsgCreateGroupWithPolicy{} ) @@ -257,8 +258,8 @@ func (m MsgCreateGroupWithPolicy) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgCreateGroupPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} ) // GetSignBytes Implements Msg. @@ -294,8 +295,8 @@ func (m MsgCreateGroupPolicy) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyAdmin{} + _ sdk.Msg = &MsgUpdateGroupPolicyAdmin{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyAdmin{} ) // GetSignBytes Implements Msg. @@ -334,8 +335,8 @@ func (m MsgUpdateGroupPolicyAdmin) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyDecisionPolicy{} + _ sdk.Msg = &MsgUpdateGroupPolicyDecisionPolicy{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyDecisionPolicy{} _ types.UnpackInterfacesMessage = MsgUpdateGroupPolicyDecisionPolicy{} ) @@ -420,8 +421,8 @@ func (m MsgUpdateGroupPolicyDecisionPolicy) UnpackInterfaces(unpacker types.AnyU } var ( - _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} - _ sdk.HasAminoSigningCapability = &MsgUpdateGroupPolicyMetadata{} + _ sdk.Msg = &MsgUpdateGroupPolicyMetadata{} + _ legacytx.LegacyMsg = &MsgUpdateGroupPolicyMetadata{} ) // GetSignBytes Implements Msg. @@ -452,8 +453,8 @@ func (m MsgUpdateGroupPolicyMetadata) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgCreateGroupPolicy{} - _ sdk.HasAminoSigningCapability = &MsgCreateGroupPolicy{} + _ sdk.Msg = &MsgCreateGroupPolicy{} + _ legacytx.LegacyMsg = &MsgCreateGroupPolicy{} _ types.UnpackInterfacesMessage = MsgCreateGroupPolicy{} ) @@ -513,8 +514,8 @@ func (m MsgCreateGroupPolicy) UnpackInterfaces(unpacker types.AnyUnpacker) error } var ( - _ sdk.Msg = &MsgSubmitProposal{} - _ sdk.HasAminoSigningCapability = &MsgSubmitProposal{} + _ sdk.Msg = &MsgSubmitProposal{} + _ legacytx.LegacyMsg = &MsgSubmitProposal{} ) // NewMsgSubmitProposal creates a new MsgSubmitProposal. @@ -627,8 +628,8 @@ func (m MsgSubmitProposal) UnpackInterfaces(unpacker types.AnyUnpacker) error { } var ( - _ sdk.Msg = &MsgWithdrawProposal{} - _ sdk.HasAminoSigningCapability = &MsgWithdrawProposal{} + _ sdk.Msg = &MsgWithdrawProposal{} + _ legacytx.LegacyMsg = &MsgWithdrawProposal{} ) // GetSignBytes Implements Msg. @@ -658,8 +659,8 @@ func (m MsgWithdrawProposal) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgVote{} - _ sdk.HasAminoSigningCapability = &MsgVote{} + _ sdk.Msg = &MsgVote{} + _ legacytx.LegacyMsg = &MsgVote{} ) // GetSignBytes Implements Msg. @@ -693,8 +694,8 @@ func (m MsgVote) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgExec{} - _ sdk.HasAminoSigningCapability = &MsgExec{} + _ sdk.Msg = &MsgExec{} + _ legacytx.LegacyMsg = &MsgExec{} ) // GetSignBytes Implements Msg. @@ -722,8 +723,8 @@ func (m MsgExec) ValidateBasic() error { } var ( - _ sdk.Msg = &MsgLeaveGroup{} - _ sdk.HasAminoSigningCapability = &MsgLeaveGroup{} + _ sdk.Msg = &MsgLeaveGroup{} + _ legacytx.LegacyMsg = &MsgLeaveGroup{} ) // GetSignBytes Implements Msg diff --git a/x/group/msgs_test.go b/x/group/msgs_test.go index f5ff82913931..acfdeb5b6f9f 100644 --- a/x/group/msgs_test.go +++ b/x/group/msgs_test.go @@ -153,7 +153,7 @@ func TestMsgCreateGroup(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroup{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgCreateGroup{})) } }) } @@ -224,7 +224,7 @@ func TestMsgUpdateGroupAdmin(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupAdmin{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupAdmin{})) } }) } @@ -274,7 +274,7 @@ func TestMsgUpdateGroupMetadata(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupMetadata{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupMetadata{})) } }) } @@ -354,7 +354,7 @@ func TestMsgUpdateGroupMembers(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupMembers{})) + require.Equal(t, sdk.MsgTypeURL(tc.msg), sdk.MsgTypeURL(&group.MsgUpdateGroupMembers{})) } }) } @@ -533,7 +533,7 @@ func TestMsgCreateGroupWithPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroupWithPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgCreateGroupWithPolicy{})) } }) } @@ -688,7 +688,7 @@ func TestMsgCreateGroupPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgCreateGroupPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgCreateGroupPolicy{})) } }) } @@ -788,7 +788,7 @@ func TestMsgUpdateGroupPolicyDecisionPolicy(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyDecisionPolicy{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyDecisionPolicy{})) } }) } @@ -860,7 +860,7 @@ func TestMsgUpdateGroupPolicyAdmin(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyAdmin{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyAdmin{})) } }) } @@ -911,7 +911,7 @@ func TestMsgUpdateGroupPolicyMetadata(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyMetadata{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgUpdateGroupPolicyMetadata{})) } }) } @@ -984,7 +984,7 @@ func TestMsgSubmitProposal(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgSubmitProposal{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgSubmitProposal{})) } }) } @@ -1069,7 +1069,7 @@ func TestMsgVote(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgVote{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgVote{})) } }) } @@ -1118,7 +1118,7 @@ func TestMsgWithdrawProposal(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgWithdrawProposal{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgWithdrawProposal{})) } }) } @@ -1166,7 +1166,7 @@ func TestMsgExec(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgExec{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgExec{})) } }) } @@ -1214,7 +1214,7 @@ func TestMsgLeaveGroup(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, msg.Type(), sdk.MsgTypeURL(&group.MsgLeaveGroup{})) + require.Equal(t, sdk.MsgTypeURL(msg), sdk.MsgTypeURL(&group.MsgLeaveGroup{})) } }) } diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index 1966833a8aab..f150cdab2395 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -279,7 +279,7 @@ func SimulateMsgCreateGroup(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk gr _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err @@ -318,7 +318,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKee } msg.SetDecisionPolicy(decisionPolicy) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to set decision policy"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to set decision policy"), nil, err } txGen := tx.NewTxConfig(cdc, tx.DefaultSignModes) @@ -339,7 +339,7 @@ func SimulateMsgCreateGroupWithPolicy(cdc *codec.ProtoCodec, ak group.AccountKee _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil @@ -400,7 +400,7 @@ func SimulateMsgCreateGroupPolicy(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { fmt.Printf("ERR DELIVER %v\n", err) - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err @@ -450,7 +450,7 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk return simtypes.NoOpMsg(group.ModuleName, TypeMsgSubmitProposal, "fee error"), nil, err } - msg := group.MsgSubmitProposal{ + msg := &group.MsgSubmitProposal{ GroupPolicyAddress: groupPolicyAddr, Proposers: []string{acc.Address.String()}, Metadata: simtypes.RandStringOfLength(r, 10), @@ -462,7 +462,7 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -476,10 +476,10 @@ func SimulateMsgSubmitProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, bk _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -512,7 +512,7 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, newAdmin, _ = simtypes.RandomAcc(r, accounts) } - msg := group.MsgUpdateGroupAdmin{ + msg := &group.MsgUpdateGroupAdmin{ GroupId: groupID, Admin: account.GetAddress().String(), NewAdmin: newAdmin.Address.String(), @@ -522,7 +522,7 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -536,10 +536,10 @@ func SimulateMsgUpdateGroupAdmin(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -563,7 +563,7 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupMetadata, "fee error"), nil, err } - msg := group.MsgUpdateGroupMetadata{ + msg := &group.MsgUpdateGroupMetadata{ GroupId: groupID, Admin: account.GetAddress().String(), Metadata: simtypes.RandStringOfLength(r, 10), @@ -573,7 +573,7 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -587,10 +587,10 @@ func SimulateMsgUpdateGroupMetadata(cdc *codec.ProtoCodec, ak group.AccountKeepe _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -643,7 +643,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper } } - msg := group.MsgUpdateGroupMembers{ + msg := &group.MsgUpdateGroupMembers{ GroupId: groupID, Admin: acc.Address.String(), MemberUpdates: members, @@ -653,7 +653,7 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -667,10 +667,10 @@ func SimulateMsgUpdateGroupMembers(cdc *codec.ProtoCodec, ak group.AccountKeeper _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -703,7 +703,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe newAdmin, _ = simtypes.RandomAcc(r, accounts) } - msg := group.MsgUpdateGroupPolicyAdmin{ + msg := &group.MsgUpdateGroupPolicyAdmin{ Admin: acc.Address.String(), GroupPolicyAddress: groupPolicyAddr, NewAdmin: newAdmin.Address.String(), @@ -713,7 +713,7 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -727,10 +727,10 @@ func SimulateMsgUpdateGroupPolicyAdmin(cdc *codec.ProtoCodec, ak group.AccountKe _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -789,7 +789,7 @@ func SimulateMsgUpdateGroupPolicyDecisionPolicy(cdc *codec.ProtoCodec, ak group. _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } @@ -817,7 +817,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun return simtypes.NoOpMsg(group.ModuleName, TypeMsgUpdateGroupPolicyMetadata, "fee error"), nil, err } - msg := group.MsgUpdateGroupPolicyMetadata{ + msg := &group.MsgUpdateGroupPolicyMetadata{ Admin: acc.Address.String(), GroupPolicyAddress: groupPolicyAddr, Metadata: simtypes.RandStringOfLength(r, 10), @@ -827,7 +827,7 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -841,10 +841,10 @@ func SimulateMsgUpdateGroupPolicyMetadata(cdc *codec.ProtoCodec, ak group.Accoun _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -919,7 +919,7 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(group.ModuleName, TypeMsgWithdrawProposal, "fee error"), nil, err } - msg := group.MsgWithdrawProposal{ + msg := &group.MsgWithdrawProposal{ ProposalId: uint64(proposalID), Address: proposer.Address.String(), } @@ -928,7 +928,7 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -944,12 +944,12 @@ func SimulateMsgWithdrawProposal(cdc *codec.ProtoCodec, ak group.AccountKeeper, if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1023,7 +1023,7 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(group.ModuleName, TypeMsgVote, "member has already voted"), nil, nil } - msg := group.MsgVote{ + msg := &group.MsgVote{ ProposalId: uint64(proposalID), Voter: acc.Address.String(), Option: group.VOTE_OPTION_YES, @@ -1033,7 +1033,7 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -1049,12 +1049,12 @@ func SimulateMsgVote(cdc *codec.ProtoCodec, ak group.AccountKeeper, if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1103,7 +1103,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil } - msg := group.MsgExec{ + msg := &group.MsgExec{ ProposalId: uint64(proposalID), Executor: acc.Address.String(), } @@ -1111,7 +1111,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{&msg}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -1126,12 +1126,12 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { if strings.Contains(err.Error(), "group was modified") || strings.Contains(err.Error(), "group policy was modified") { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "no-op:group/group-policy was modified"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "no-op:group/group-policy was modified"), nil, nil } - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - return simtypes.NewOperationMsg(&msg, true, "", nil), nil, err + return simtypes.NewOperationMsg(msg, true, "", nil), nil, err } } @@ -1187,7 +1187,7 @@ func SimulateMsgLeaveGroup(cdc *codec.ProtoCodec, k keeper.Keeper, ak group.Acco _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(group.ModuleName, msg.Type(), err.Error()), nil, err + return simtypes.NoOpMsg(group.ModuleName, sdk.MsgTypeURL(msg), err.Error()), nil, err } return simtypes.NewOperationMsg(msg, true, "", nil), nil, err diff --git a/x/mint/types/msgs.go b/x/mint/types/msgs.go index a08186ef312c..366a0a02a4c7 100644 --- a/x/mint/types/msgs.go +++ b/x/mint/types/msgs.go @@ -3,9 +3,13 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -var _ sdk.Msg = &MsgUpdateParams{} +var ( + _ sdk.Msg = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} +) // GetSignBytes implements the LegacyMsg interface. func (m MsgUpdateParams) GetSignBytes() []byte { @@ -13,13 +17,13 @@ func (m MsgUpdateParams) GetSignBytes() []byte { } // GetSigners returns the expected signers for a MsgUpdateParams message. -func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (m MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(m.Authority) return []sdk.AccAddress{addr} } // ValidateBasic does a sanity check on the provided data. -func (m *MsgUpdateParams) ValidateBasic() error { +func (m MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } diff --git a/x/simulation/util.go b/x/simulation/util.go index f65a3f035b2d..13e90bb29ef3 100644 --- a/x/simulation/util.go +++ b/x/simulation/util.go @@ -68,7 +68,6 @@ type OperationInput struct { TxGen client.TxConfig Cdc *codec.ProtoCodec Msg sdk.Msg - MsgType string CoinsSpentInMsg sdk.Coins Context sdk.Context SimAccount simtypes.Account @@ -87,12 +86,12 @@ func GenAndDeliverTxWithRandFees(txCtx OperationInput) (simtypes.OperationMsg, [ coins, hasNeg := spendable.SafeSub(txCtx.CoinsSpentInMsg...) if hasNeg { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "message doesn't leave room for fees"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "message doesn't leave room for fees"), nil, err } fees, err = simtypes.RandomFees(txCtx.R, txCtx.Context, coins) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to generate fees"), nil, err } return GenAndDeliverTx(txCtx, fees) } @@ -112,12 +111,12 @@ func GenAndDeliverTx(txCtx OperationInput, fees sdk.Coins) (simtypes.OperationMs txCtx.SimAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to generate mock tx"), nil, err } _, _, err = txCtx.App.SimDeliver(txCtx.TxGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(txCtx.ModuleName, txCtx.MsgType, "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(txCtx.ModuleName, sdk.MsgTypeURL(txCtx.Msg), "unable to deliver tx"), nil, err } return simtypes.NewOperationMsg(txCtx.Msg, true, "", txCtx.Cdc), nil, nil diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 939f28766fe5..3abf711d82cf 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -52,33 +52,35 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgUnjail{}) + validator, ok := testutil.RandSliceElem(r, sk.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not ok"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil // skip } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(validator.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find account"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find account"), nil, nil // skip } if !validator.IsJailed() { // TODO: due to this condition this message is almost, if not always, skipped ! - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "validator is not jailed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not jailed"), nil, nil } consAddr, err := validator.GetConsAddr() if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to get validator consensus key"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to get validator consensus key"), nil, err } info, found := k.GetValidatorSigningInfo(ctx, consAddr) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to find validator signing info"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find validator signing info"), nil, nil // skip } selfDel := sk.Delegation(ctx, simAccount.Address, validator.GetOperator()) if selfDel == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "self delegation is nil"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "self delegation is nil"), nil, nil // skip } account := ak.GetAccount(ctx, sdk.AccAddress(validator.GetOperator())) @@ -86,7 +88,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B fees, err := simtypes.RandomFees(r, ctx, spendable) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUnjail, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } msg := types.NewMsgUnjail(validator.GetOperator()) @@ -104,7 +106,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } _, res, err := app.SimDeliver(txGen.TxEncoder(), tx) @@ -132,7 +134,7 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B } if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to deliver tx"), nil, errors.New(res.Log) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, errors.New(res.Log) } return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 3651ed3e67cd..9f30d44b736f 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -123,7 +123,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { weight int opMsgRoute string opMsgName string - }{{simulation.DefaultWeightMsgUnjail, types.ModuleName, types.TypeMsgUnjail}} + }{{simulation.DefaultWeightMsgUnjail, types.ModuleName, sdk.MsgTypeURL(&types.MsgUnjail{})}} weightesOps := simulation.WeightedOperations(appParams, suite.codec, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper) for i, w := range weightesOps { @@ -181,7 +181,6 @@ func (suite *SimTestSuite) TestSimulateMsgUnjail() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) - suite.Require().Equal(types.TypeMsgUnjail, msg.Type()) suite.Require().Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddr) suite.Require().Len(futureOperations, 0) } diff --git a/x/slashing/types/msg.go b/x/slashing/types/msg.go index 8dafa411530d..df9178fd3d6f 100644 --- a/x/slashing/types/msg.go +++ b/x/slashing/types/msg.go @@ -3,11 +3,7 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" -) - -// slashing message types -const ( - TypeMsgUnjail = "unjail" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // verify interface at compile time @@ -15,8 +11,8 @@ var ( _ sdk.Msg = &MsgUnjail{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgUnjail{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgUnjail{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgUnjail creates a new MsgUnjail instance diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 35464a8c1815..21cd788d45b4 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -225,7 +225,7 @@ func (k msgServer) Delegate(goCtx context.Context, msg *types.MsgDelegate) (*typ defer func() { telemetry.IncrCounter(1, types.ModuleName, "delegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) @@ -285,7 +285,7 @@ func (k msgServer) BeginRedelegate(goCtx context.Context, msg *types.MsgBeginRed defer func() { telemetry.IncrCounter(1, types.ModuleName, "redelegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) @@ -344,7 +344,7 @@ func (k msgServer) Undelegate(goCtx context.Context, msg *types.MsgUndelegate) ( defer func() { telemetry.IncrCounter(1, types.ModuleName, "undelegate") telemetry.SetGaugeWithLabels( - []string{"tx", "msg", msg.Type()}, + []string{"tx", "msg", sdk.MsgTypeURL(msg)}, float32(msg.Amount.Amount.Int64()), []metrics.Label{telemetry.NewLabel("denom", msg.Amount.Denom)}, ) diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index a675c4c9e634..18794553b037 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -118,25 +118,27 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgCreateValidator{}) + simAccount, _ := simtypes.RandomAcc(r, accs) address := sdk.ValAddress(simAccount.Address) // ensure the validator doesn't exist already _, found := k.GetValidator(ctx, address) if found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "validator already exists"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator already exists"), nil, nil } denom := k.GetParams(ctx).BondDenom balance := bk.GetBalance(ctx, simAccount.Address, denom).Amount if !balance.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "balance is negative"), nil, nil } amount, err := simtypes.RandPositiveInt(r, balance) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } selfDelegation := sdk.NewCoin(denom, amount) @@ -150,7 +152,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCreateValidator, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } } @@ -171,7 +173,7 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * msg, err := types.NewMsgCreateValidator(address, simAccount.ConsKey.PubKey(), selfDelegation, description, commission, math.OneInt()) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "unable to create CreateValidator message"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to create CreateValidator message"), nil, err } txCtx := simulation.OperationInput{ @@ -180,7 +182,6 @@ func SimulateMsgCreateValidator(ak types.AccountKeeper, bk types.BankKeeper, k * TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -196,13 +197,15 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgEditValidator{}) + if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "unable to pick a validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick a validator"), nil, nil } address := val.GetOperator() @@ -210,12 +213,12 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke if err := val.Commission.ValidateNewRate(newCommissionRate, ctx.BlockHeader().Time); err != nil { // skip as the commission is invalid - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "invalid commission rate"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid commission rate"), nil, nil } simAccount, found := simtypes.FindAccount(accs, sdk.AccAddress(val.GetOperator())) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgEditValidator, "unable to find account"), nil, fmt.Errorf("validator %s not found", val.GetOperator()) + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to find account"), nil, fmt.Errorf("validator %s not found", val.GetOperator()) } account := ak.GetAccount(ctx, simAccount.Address) @@ -237,7 +240,6 @@ func SimulateMsgEditValidator(ak types.AccountKeeper, bk types.BankKeeper, k *ke TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -255,30 +257,31 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgDelegate{}) denom := k.GetParams(ctx).BondDenom if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to pick a validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick a validator"), nil, nil } if val.InvalidExRate() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "validator's invalid echange rate"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator's invalid echange rate"), nil, nil } amount := bk.GetBalance(ctx, simAccount.Address, denom).Amount if !amount.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "balance is negative"), nil, nil } amount, err := simtypes.RandPositiveInt(r, amount) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } bondAmt := sdk.NewCoin(denom, amount) @@ -292,7 +295,7 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate fees"), nil, err } } @@ -304,7 +307,6 @@ func SimulateMsgDelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keeper. TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -320,15 +322,17 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgUndelegate{}) + val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil } valAddr := val.GetOperator() delegations := k.GetValidatorDelegations(ctx, val.GetOperator()) if delegations == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "keeper does have any delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have any delegation entries"), nil, nil } // get random delegator from validator @@ -336,21 +340,21 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe delAddr := delegation.GetDelegatorAddr() if k.HasMaxUnbondingDelegationEntries(ctx, delAddr, valAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "keeper does have a max unbonding delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have a max unbonding delegation entries"), nil, nil } totalBond := val.TokensFromShares(delegation.GetShares()).TruncateInt() if !totalBond.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "total bond is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "total bond is negative"), nil, nil } unbondAmt, err := simtypes.RandPositiveInt(r, totalBond) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "invalid unbond amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid unbond amount"), nil, err } if unbondAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgUndelegate, "unbond amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unbond amount is zero"), nil, nil } msg := types.NewMsgUndelegate( @@ -368,7 +372,7 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe } // if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error if simAccount.PrivKey == nil { - return simtypes.NoOpMsg(types.ModuleName, msg.Type(), "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) } account := ak.GetAccount(ctx, delAddr) @@ -380,7 +384,6 @@ func SimulateMsgUndelegate(ak types.AccountKeeper, bk types.BankKeeper, k *keepe TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -398,23 +401,25 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}) + if len(k.GetAllValidators(ctx)) == 0 { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgDelegate, "number of validators equal zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "number of validators equal zero"), nil, nil } simAccount, _ := simtypes.RandomAcc(r, accs) val, ok := testutil.RandSliceElem(r, k.GetAllValidators(ctx)) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "validator is not ok"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is not ok"), nil, nil } if val.IsJailed() || val.InvalidExRate() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "validator is jailed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "validator is jailed"), nil, nil } valAddr := val.GetOperator() unbondingDelegation, found := k.GetUnbondingDelegation(ctx, simAccount.Address, valAddr) if !found { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "account does have any unbonding delegation"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "account does have any unbonding delegation"), nil, nil } // This is a temporary fix to make staking simulation pass. We should fetch @@ -435,17 +440,17 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee } if unbondingDelegationEntry.CompletionTime.Before(ctx.BlockTime()) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "unbonding delegation is already processed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unbonding delegation is already processed"), nil, nil } if !unbondingDelegationEntry.Balance.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "delegator receiving balance is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "delegator receiving balance is negative"), nil, nil } cancelBondAmt := simtypes.RandomAmount(r, unbondingDelegationEntry.Balance) if cancelBondAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgCancelUnbondingDelegation, "cancelBondAmt amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "cancelBondAmt amount is zero"), nil, nil } msg := types.NewMsgCancelUnbondingDelegation( @@ -460,7 +465,6 @@ func SimulateMsgCancelUnbondingDelegate(ak types.AccountKeeper, bk types.BankKee TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, @@ -478,16 +482,18 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msgType := sdk.MsgTypeURL(&types.MsgBeginRedelegate{}) + allVals := k.GetAllValidators(ctx) srcVal, ok := testutil.RandSliceElem(r, allVals) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to pick validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick validator"), nil, nil } srcAddr := srcVal.GetOperator() delegations := k.GetValidatorDelegations(ctx, srcAddr) if delegations == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "keeper does have any delegation entries"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "keeper does have any delegation entries"), nil, nil } // get random delegator from src validator @@ -495,42 +501,42 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * delAddr := delegation.GetDelegatorAddr() if k.HasReceivingRedelegation(ctx, delAddr, srcAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "receveing redelegation is not allowed"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "receveing redelegation is not allowed"), nil, nil // skip } // get random destination validator destVal, ok := testutil.RandSliceElem(r, allVals) if !ok { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to pick validator"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to pick validator"), nil, nil } destAddr := destVal.GetOperator() if srcAddr.Equals(destAddr) || destVal.InvalidExRate() || k.HasMaxRedelegationEntries(ctx, delAddr, srcAddr, destAddr) { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "checks failed"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "checks failed"), nil, nil } totalBond := srcVal.TokensFromShares(delegation.GetShares()).TruncateInt() if !totalBond.IsPositive() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "total bond is negative"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "total bond is negative"), nil, nil } redAmt, err := simtypes.RandPositiveInt(r, totalBond) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "unable to generate positive amount"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "unable to generate positive amount"), nil, err } if redAmt.IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "amount is zero"), nil, nil + return simtypes.NoOpMsg(types.ModuleName, msgType, "amount is zero"), nil, nil } // check if the shares truncate to zero shares, err := srcVal.SharesFromTokens(redAmt) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "invalid shares"), nil, err + return simtypes.NoOpMsg(types.ModuleName, msgType, "invalid shares"), nil, err } if srcVal.TokensFromShares(shares).TruncateInt().IsZero() { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "shares truncate to zero"), nil, nil // skip + return simtypes.NoOpMsg(types.ModuleName, msgType, "shares truncate to zero"), nil, nil // skip } // need to retrieve the simulation account associated with delegation to retrieve PrivKey @@ -545,7 +551,7 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * // if simaccount.PrivKey == nil, delegation address does not exist in accs. Return error if simAccount.PrivKey == nil { - return simtypes.NoOpMsg(types.ModuleName, types.TypeMsgBeginRedelegate, "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) + return simtypes.NoOpMsg(types.ModuleName, msgType, "account private key is nil"), nil, fmt.Errorf("delegation addr: %s does not exist in simulation accounts", delAddr) } account := ak.GetAccount(ctx, delAddr) @@ -562,7 +568,6 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * TxGen: moduletestutil.MakeTestEncodingConfig().TxConfig, Cdc: nil, Msg: msg, - MsgType: msg.Type(), Context: ctx, SimAccount: simAccount, AccountKeeper: ak, diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index bc21d49200ba..f0ea235e8dab 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -168,7 +168,7 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCreateValidator, msg.Type()) + require.Equal(types.TypeMsgCreateValidator, sdk.MsgTypeURL(msg)) valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) require.NoError(err) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) @@ -214,7 +214,7 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCancelUnbondingDelegation, msg.Type()) + require.Equal(types.TypeMsgCancelUnbondingDelegation, sdk.MsgTypeURL(msg)) require.Equal(delegator.Address.String(), msg.DelegatorAddress) require.Equal(validator0.GetOperator().String(), msg.ValidatorAddress) require.Len(futureOperations, 0) @@ -242,7 +242,7 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgEditValidator, msg.Type()) + require.Equal(types.TypeMsgEditValidator, sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -265,7 +265,7 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgDelegate, msg.Type()) + require.Equal(types.TypeMsgDelegate, sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -305,7 +305,7 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgUndelegate, msg.Type()) + require.Equal(types.TypeMsgUndelegate, sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -348,7 +348,7 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgBeginRedelegate, msg.Type()) + require.Equal(types.TypeMsgBeginRedelegate, sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index ea18e1d8284f..4542f3b821d0 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -6,6 +6,7 @@ import ( cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( @@ -18,13 +19,13 @@ var ( _ sdk.Msg = &MsgCancelUnbondingDelegation{} _ sdk.Msg = &MsgUpdateParams{} - _ sdk.HasAminoSigningCapability = &MsgCreateValidator{} - _ sdk.HasAminoSigningCapability = &MsgEditValidator{} - _ sdk.HasAminoSigningCapability = &MsgDelegate{} - _ sdk.HasAminoSigningCapability = &MsgUndelegate{} - _ sdk.HasAminoSigningCapability = &MsgBeginRedelegate{} - _ sdk.HasAminoSigningCapability = &MsgCancelUnbondingDelegation{} - _ sdk.HasAminoSigningCapability = &MsgUpdateParams{} + _ legacytx.LegacyMsg = &MsgCreateValidator{} + _ legacytx.LegacyMsg = &MsgEditValidator{} + _ legacytx.LegacyMsg = &MsgDelegate{} + _ legacytx.LegacyMsg = &MsgUndelegate{} + _ legacytx.LegacyMsg = &MsgBeginRedelegate{} + _ legacytx.LegacyMsg = &MsgCancelUnbondingDelegation{} + _ legacytx.LegacyMsg = &MsgUpdateParams{} ) // NewMsgCreateValidator creates a new MsgCreateValidator instance. @@ -349,13 +350,13 @@ func (msg MsgCancelUnbondingDelegation) ValidateBasic() error { // GetSignBytes returns the raw bytes for a MsgUpdateParams message that // the expected signer needs to sign. -func (m *MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(m) +func (m MsgUpdateParams) GetSignBytes() []byte { + bz := ModuleCdc.MustMarshalJSON(&m) return sdk.MustSortJSON(bz) } // ValidateBasic executes sanity validation on the provided data -func (m *MsgUpdateParams) ValidateBasic() error { +func (m MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } @@ -363,7 +364,7 @@ func (m *MsgUpdateParams) ValidateBasic() error { } // GetSigners returns the expected signers for a MsgUpdateParams message -func (m *MsgUpdateParams) GetSigners() []sdk.AccAddress { +func (m MsgUpdateParams) GetSigners() []sdk.AccAddress { addr, _ := sdk.AccAddressFromBech32(m.Authority) return []sdk.AccAddress{addr} } diff --git a/x/upgrade/types/msgs.go b/x/upgrade/types/msgs.go index 85f036c3173a..b14255433878 100644 --- a/x/upgrade/types/msgs.go +++ b/x/upgrade/types/msgs.go @@ -3,11 +3,12 @@ package types import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) var ( - _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} - _, _ sdk.HasAminoSigningCapability = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ sdk.Msg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} + _, _ legacytx.LegacyMsg = &MsgSoftwareUpgrade{}, &MsgCancelUpgrade{} ) // GetSignBytes implements the LegacyMsg interface. diff --git a/x/upgrade/types/msgs_test.go b/x/upgrade/types/msgs_test.go index feb648be97bd..70981f9e389b 100644 --- a/x/upgrade/types/msgs_test.go +++ b/x/upgrade/types/msgs_test.go @@ -63,7 +63,6 @@ func TestMsgSoftwareUpgrade(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&types.MsgSoftwareUpgrade{})) } }) } @@ -102,7 +101,6 @@ func TestMsgCancelUpgrade(t *testing.T) { require.Contains(t, err.Error(), tc.errMsg) } else { require.NoError(t, err) - require.Equal(t, tc.msg.Type(), sdk.MsgTypeURL(&types.MsgCancelUpgrade{})) } }) } From 5f1eb344082daefeb706bb985c2cd4318fbf7b4c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 15:54:39 +0100 Subject: [PATCH 08/32] updates --- baseapp/baseapp.go | 7 +-- types/simulation/types.go | 20 +++++--- types/tx_msg.go | 13 ++++++ x/authz/msgs.go | 6 +-- x/bank/simulation/operations_test.go | 24 +++++----- x/distribution/simulation/operations_test.go | 36 +++++++------- x/feegrant/msgs.go | 4 +- x/feegrant/simulation/operations_test.go | 8 ++-- x/gov/simulation/operations_test.go | 25 ++++------ x/group/simulation/operations_test.go | 30 ++++++------ x/simulation/event_stats.go | 12 ++--- x/slashing/simulation/operations_test.go | 4 +- x/staking/simulation/operations_test.go | 49 ++++++++++---------- 13 files changed, 123 insertions(+), 115 deletions(-) diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index 8a987156cb79..be1837c7d78d 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -835,11 +835,8 @@ func createEvents(events sdk.Events, msg sdk.Msg) sdk.Events { // verify that events have no module attribute set if _, found := events.GetAttributes(sdk.AttributeKeyModule); !found { - // here we assume that routes module name is the second element of the route - // e.g. "cosmos.bank.v1beta1.MsgSend" => "bank" - moduleName := strings.Split(eventMsgName, ".") - if len(moduleName) > 1 { - msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName[1])) + if moduleName := sdk.GetModuleNameFromTypeURL(eventMsgName); moduleName != "" { + msgEvent = msgEvent.AppendAttributes(sdk.NewAttribute(sdk.AttributeKeyModule, moduleName)) } } diff --git a/types/simulation/types.go b/types/simulation/types.go index 4d6560e22970..eeb9c15553f0 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -66,10 +66,10 @@ type OperationMsg struct { } // NewOperationMsgBasic creates a new operation message from raw input. -func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) OperationMsg { +func NewOperationMsgBasic(moduleName, msgType, comment string, ok bool, msg []byte) OperationMsg { return OperationMsg{ - Route: route, - Name: name, + Route: moduleName, + Name: msgType, Comment: comment, OK: ok, Msg: msg, @@ -78,16 +78,22 @@ func NewOperationMsgBasic(route, name, comment string, ok bool, msg []byte) Oper // NewOperationMsg - create a new operation message from sdk.Msg func NewOperationMsg(msg sdk.Msg, ok bool, comment string, cdc *codec.ProtoCodec) OperationMsg { + msgType := sdk.MsgTypeURL(msg) + moduleName := sdk.GetModuleNameFromTypeURL(msgType) + if moduleName == "" { + moduleName = msgType + } + if legacyMsg, okType := msg.(legacytx.LegacyMsg); okType { - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, legacyMsg.GetSignBytes()) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, legacyMsg.GetSignBytes()) } - return NewOperationMsgBasic(sdk.MsgTypeURL(msg), sdk.MsgTypeURL(msg), comment, ok, cdc.MustMarshalJSON(msg)) + return NewOperationMsgBasic(moduleName, msgType, comment, ok, cdc.MustMarshalJSON(msg)) } // NoOpMsg - create a no-operation message -func NoOpMsg(route, msgType, comment string) OperationMsg { - return NewOperationMsgBasic(route, msgType, comment, false, nil) +func NoOpMsg(moduleName, msgType, comment string) OperationMsg { + return NewOperationMsgBasic(moduleName, msgType, comment, false, nil) } // log entry text for this operation msg diff --git a/types/tx_msg.go b/types/tx_msg.go index 41c647e57de5..d0127a7b5b67 100644 --- a/types/tx_msg.go +++ b/types/tx_msg.go @@ -3,6 +3,7 @@ package types import ( "encoding/json" fmt "fmt" + strings "strings" "github.com/cosmos/gogoproto/proto" @@ -102,3 +103,15 @@ func GetMsgFromTypeURL(cdc codec.Codec, input string) (Msg, error) { return msg, nil } + +// GetModuleNameFromTypeURL assumes that module name is the second element of the msg type URL +// e.g. "cosmos.bank.v1beta1.MsgSend" => "bank" +// It returns an empty string if the input is not a valid type URL +func GetModuleNameFromTypeURL(input string) string { + moduleName := strings.Split(input, ".") + if len(moduleName) > 1 { + return moduleName[1] + } + + return "" +} diff --git a/x/authz/msgs.go b/x/authz/msgs.go index 6957c91dcc3a..792120d6de71 100644 --- a/x/authz/msgs.go +++ b/x/authz/msgs.go @@ -66,7 +66,7 @@ func (msg MsgGrant) ValidateBasic() error { return msg.Grant.ValidateBasic() } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrant) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -147,7 +147,7 @@ func (msg MsgRevoke) ValidateBasic() error { return nil } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevoke) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } @@ -215,7 +215,7 @@ func (msg MsgExec) ValidateBasic() error { return nil } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgExec) GetSignBytes() []byte { return sdk.MustSortJSON(authzcodec.ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 760281b92809..f88e037a2812 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -105,14 +105,14 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -133,8 +133,8 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require := suite.Require() require.NoError(err) - var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Len(msg.Inputs, 1) @@ -143,7 +143,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require.Len(msg.Outputs, 2) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Outputs[1].Address) require.Equal("107287087stake", msg.Outputs[1].Coins.String()) - require.Equal(types.TypeMsgMultiSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) require.Len(futureOperations, 0) } @@ -169,12 +169,12 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -197,12 +197,12 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(types.TypeMsgMultiSend, sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3e7cf34a8cf6..3211dc43d287 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -43,10 +43,10 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, types.TypeMsgSetWithdrawAddress}, - {simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, types.TypeMsgWithdrawDelegatorReward}, - {simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, types.TypeMsgWithdrawValidatorCommission}, - {simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, types.TypeMsgFundCommunityPool}, + {simulation.DefaultWeightMsgSetWithdrawAddress, types.ModuleName, sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{})}, + {simulation.DefaultWeightMsgWithdrawDelegationReward, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{})}, + {simulation.DefaultWeightMsgWithdrawValidatorCommission, types.ModuleName, sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{})}, + {simulation.DefaultWeightMsgFundCommunityPool, types.ModuleName, sdk.MsgTypeURL(&types.MsgFundCommunityPool{})}, } for i, w := range weightesOps { @@ -78,14 +78,13 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgSetWithdrawAddress - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgSetWithdrawAddress + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(types.TypeMsgSetWithdrawAddress, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -119,14 +118,13 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgWithdrawDelegatorReward - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgWithdrawDelegatorReward + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawDelegatorReward, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } @@ -180,13 +178,12 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName } else { suite.Require().NoError(err) - var msg types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgWithdrawValidatorCommission + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(types.TypeMsgWithdrawValidatorCommission, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } } @@ -207,14 +204,13 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg types.MsgFundCommunityPool - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgFundCommunityPool + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(types.TypeMsgFundCommunityPool, sdk.MsgTypeURL(msg)) - suite.Require().Equal(types.ModuleName, msg.Route()) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/feegrant/msgs.go b/x/feegrant/msgs.go index 33af976e41ac..13f9a09ccd09 100644 --- a/x/feegrant/msgs.go +++ b/x/feegrant/msgs.go @@ -62,7 +62,7 @@ func (msg MsgGrantAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgGrantAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } @@ -113,7 +113,7 @@ func (msg MsgRevokeAllowance) GetSigners() []sdk.AccAddress { return []sdk.AccAddress{granter} } -// GetSignBytes implements the HasAminoSigningCapability.GetSignBytes method. +// GetSignBytes implements the LegacyMsg.GetSignBytes method. func (msg MsgRevokeAllowance) GetSignBytes() []byte { return sdk.MustSortJSON(ModuleCdc.MustMarshalJSON(&msg)) } diff --git a/x/feegrant/simulation/operations_test.go b/x/feegrant/simulation/operations_test.go index 2ca0dd3d0c10..8ffb29981ddc 100644 --- a/x/feegrant/simulation/operations_test.go +++ b/x/feegrant/simulation/operations_test.go @@ -89,13 +89,13 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ { simulation.DefaultWeightGrantAllowance, - feegrant.MsgGrantAllowance{}.Route(), - simulation.TypeMsgGrantAllowance, + feegrant.ModuleName, + sdk.MsgTypeURL(&feegrant.MsgGrantAllowance{}), }, { simulation.DefaultWeightRevokeAllowance, - feegrant.MsgRevokeAllowance{}.Route(), - simulation.TypeMsgRevokeAllowance, + feegrant.ModuleName, + sdk.MsgTypeURL(&feegrant.MsgRevokeAllowance{}), }, } diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 622293938d03..29c97a8ece08 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -132,8 +132,8 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgSubmitProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgSubmitProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -142,7 +142,6 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.Equal(t, "2686011stake", msg.InitialDeposit[0].String()) require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(msg)) } @@ -180,14 +179,13 @@ func TestSimulateMsgCancelProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgCancelProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgCancelProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, proposer.String(), msg.Proposer) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgCancelProposal, sdk.MsgTypeURL(msg)) } @@ -225,8 +223,8 @@ func TestSimulateMsgDeposit(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgDeposit - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgDeposit + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -234,7 +232,6 @@ func TestSimulateMsgDeposit(t *testing.T) { require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) require.NotEqual(t, len(msg.Amount), 0) require.Equal(t, "560969stake", msg.Amount[0].String()) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgDeposit, sdk.MsgTypeURL(msg)) } @@ -272,14 +269,13 @@ func TestSimulateMsgVote(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgVote - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgVote + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.Equal(t, v1.OptionYes, msg.Option) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgVote, sdk.MsgTypeURL(msg)) } @@ -316,14 +312,13 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg v1.MsgVoteWeighted - govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *v1.MsgVoteWeighted + govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(t, operationMsg.OK) require.Equal(t, uint64(1), msg.ProposalId) require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Voter) require.True(t, len(msg.Options) >= 1) - require.Equal(t, "gov", msg.Route()) require.Equal(t, simulation.TypeMsgVoteWeighted, sdk.MsgTypeURL(msg)) } diff --git a/x/group/simulation/operations_test.go b/x/group/simulation/operations_test.go index 25ffcdcb303b..1a7718543b36 100644 --- a/x/group/simulation/operations_test.go +++ b/x/group/simulation/operations_test.go @@ -70,21 +70,21 @@ func (suite *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.WeightMsgCreateGroup, group.MsgCreateGroup{}.Route(), simulation.TypeMsgCreateGroup}, - {simulation.WeightMsgCreateGroupPolicy, group.MsgCreateGroupPolicy{}.Route(), simulation.TypeMsgCreateGroupPolicy}, - {simulation.WeightMsgCreateGroupWithPolicy, group.MsgCreateGroupWithPolicy{}.Route(), simulation.TypeMsgCreateGroupWithPolicy}, - {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, - {simulation.WeightMsgSubmitProposal, group.MsgSubmitProposal{}.Route(), simulation.TypeMsgSubmitProposal}, - {simulation.WeightMsgWithdrawProposal, group.MsgWithdrawProposal{}.Route(), simulation.TypeMsgWithdrawProposal}, - {simulation.WeightMsgVote, group.MsgVote{}.Route(), simulation.TypeMsgVote}, - {simulation.WeightMsgExec, group.MsgExec{}.Route(), simulation.TypeMsgExec}, - {simulation.WeightMsgUpdateGroupMetadata, group.MsgUpdateGroupMetadata{}.Route(), simulation.TypeMsgUpdateGroupMetadata}, - {simulation.WeightMsgUpdateGroupAdmin, group.MsgUpdateGroupAdmin{}.Route(), simulation.TypeMsgUpdateGroupAdmin}, - {simulation.WeightMsgUpdateGroupMembers, group.MsgUpdateGroupMembers{}.Route(), simulation.TypeMsgUpdateGroupMembers}, - {simulation.WeightMsgUpdateGroupPolicyAdmin, group.MsgUpdateGroupPolicyAdmin{}.Route(), simulation.TypeMsgUpdateGroupPolicyAdmin}, - {simulation.WeightMsgUpdateGroupPolicyDecisionPolicy, group.MsgUpdateGroupPolicyDecisionPolicy{}.Route(), simulation.TypeMsgUpdateGroupPolicyDecisionPolicy}, - {simulation.WeightMsgUpdateGroupPolicyMetadata, group.MsgUpdateGroupPolicyMetadata{}.Route(), simulation.TypeMsgUpdateGroupPolicyMetadata}, - {simulation.WeightMsgLeaveGroup, group.MsgLeaveGroup{}.Route(), simulation.TypeMsgLeaveGroup}, + {simulation.WeightMsgCreateGroup, group.ModuleName, simulation.TypeMsgCreateGroup}, + {simulation.WeightMsgCreateGroupPolicy, group.ModuleName, simulation.TypeMsgCreateGroupPolicy}, + {simulation.WeightMsgCreateGroupWithPolicy, group.ModuleName, simulation.TypeMsgCreateGroupWithPolicy}, + {simulation.WeightMsgSubmitProposal, group.ModuleName, simulation.TypeMsgSubmitProposal}, + {simulation.WeightMsgSubmitProposal, group.ModuleName, simulation.TypeMsgSubmitProposal}, + {simulation.WeightMsgWithdrawProposal, group.ModuleName, simulation.TypeMsgWithdrawProposal}, + {simulation.WeightMsgVote, group.ModuleName, simulation.TypeMsgVote}, + {simulation.WeightMsgExec, group.ModuleName, simulation.TypeMsgExec}, + {simulation.WeightMsgUpdateGroupMetadata, group.ModuleName, simulation.TypeMsgUpdateGroupMetadata}, + {simulation.WeightMsgUpdateGroupAdmin, group.ModuleName, simulation.TypeMsgUpdateGroupAdmin}, + {simulation.WeightMsgUpdateGroupMembers, group.ModuleName, simulation.TypeMsgUpdateGroupMembers}, + {simulation.WeightMsgUpdateGroupPolicyAdmin, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyAdmin}, + {simulation.WeightMsgUpdateGroupPolicyDecisionPolicy, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyDecisionPolicy}, + {simulation.WeightMsgUpdateGroupPolicyMetadata, group.ModuleName, simulation.TypeMsgUpdateGroupPolicyMetadata}, + {simulation.WeightMsgLeaveGroup, group.ModuleName, simulation.TypeMsgLeaveGroup}, } for i, w := range weightedOps { diff --git a/x/simulation/event_stats.go b/x/simulation/event_stats.go index 675380e8215a..d34b716e561e 100644 --- a/x/simulation/event_stats.go +++ b/x/simulation/event_stats.go @@ -17,18 +17,18 @@ func NewEventStats() EventStats { } // Tally increases the count of a simulation event. -func (es EventStats) Tally(route, op, evResult string) { - _, ok := es[route] +func (es EventStats) Tally(moduleName, op, evResult string) { + _, ok := es[moduleName] if !ok { - es[route] = make(map[string]map[string]int) + es[moduleName] = make(map[string]map[string]int) } - _, ok = es[route][op] + _, ok = es[moduleName][op] if !ok { - es[route][op] = make(map[string]int) + es[moduleName][op] = make(map[string]int) } - es[route][op][evResult]++ + es[moduleName][op][evResult]++ } // Print the event stats in JSON format. diff --git a/x/slashing/simulation/operations_test.go b/x/slashing/simulation/operations_test.go index 9f30d44b736f..95574cbbca2b 100644 --- a/x/slashing/simulation/operations_test.go +++ b/x/slashing/simulation/operations_test.go @@ -123,7 +123,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { weight int opMsgRoute string opMsgName string - }{{simulation.DefaultWeightMsgUnjail, types.ModuleName, sdk.MsgTypeURL(&types.MsgUnjail{})}} + }{ + {simulation.DefaultWeightMsgUnjail, types.ModuleName, sdk.MsgTypeURL(&types.MsgUnjail{})}, + } weightesOps := simulation.WeightedOperations(appParams, suite.codec, suite.accountKeeper, suite.bankKeeper, suite.slashingKeeper, suite.stakingKeeper) for i, w := range weightesOps { diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index f0ea235e8dab..ff52bd293106 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -131,12 +131,12 @@ func (s *SimTestSuite) TestWeightedOperations() { opMsgRoute string opMsgName string }{ - {simulation.DefaultWeightMsgCreateValidator, types.ModuleName, types.TypeMsgCreateValidator}, - {simulation.DefaultWeightMsgEditValidator, types.ModuleName, types.TypeMsgEditValidator}, - {simulation.DefaultWeightMsgDelegate, types.ModuleName, types.TypeMsgDelegate}, - {simulation.DefaultWeightMsgUndelegate, types.ModuleName, types.TypeMsgUndelegate}, - {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, types.TypeMsgBeginRedelegate}, - {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, types.TypeMsgCancelUnbondingDelegation}, + {simulation.DefaultWeightMsgCreateValidator, types.ModuleName, sdk.MsgTypeURL(&types.MsgCreateValidator{})}, + {simulation.DefaultWeightMsgEditValidator, types.ModuleName, sdk.MsgTypeURL(&types.MsgEditValidator{})}, + {simulation.DefaultWeightMsgDelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgDelegate{})}, + {simulation.DefaultWeightMsgUndelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgUndelegate{})}, + {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgBeginRedelegate{})}, + {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{})}, } for i, w := range weightesOps { @@ -147,7 +147,6 @@ func (s *SimTestSuite) TestWeightedOperations() { // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail require.Equal(expected[i].weight, w.Weight(), "weight should be the same") - require.Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") require.Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") } } @@ -164,11 +163,11 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, s.ctx, s.accounts[1:], "") require.NoError(err) - var msg types.MsgCreateValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgCreateValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCreateValidator, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msg)) valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) require.NoError(err) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) @@ -210,11 +209,11 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg types.MsgCancelUnbondingDelegation - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgCancelUnbondingDelegation + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgCancelUnbondingDelegation, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}), sdk.MsgTypeURL(msg)) require.Equal(delegator.Address.String(), msg.DelegatorAddress) require.Equal(validator0.GetOperator().String(), msg.ValidatorAddress) require.Len(futureOperations, 0) @@ -238,11 +237,11 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg types.MsgEditValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgEditValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) - require.Equal(types.TypeMsgEditValidator, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -259,13 +258,13 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts[1:], "") require.NoError(err) - var msg types.MsgDelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgDelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgDelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -298,14 +297,14 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg types.MsgUndelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgUndelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgUndelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -342,13 +341,13 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { s.T().Logf("operation message: %v", operationMsg) require.NoError(err) - var msg types.MsgBeginRedelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + var msg *types.MsgBeginRedelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(types.TypeMsgBeginRedelegate, sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) From 3ce49dc13d39823edaad08bf8d9b5cbc6412ffd7 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:18:48 +0100 Subject: [PATCH 09/32] updates --- docs/docs/building-modules/02-messages-and-queries.md | 2 -- docs/docs/core/08-events.md | 1 - x/gov/client/utils/query_test.go | 3 +-- x/gov/types/v1beta1/msgs.go | 8 ++++++++ 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/docs/docs/building-modules/02-messages-and-queries.md b/docs/docs/building-modules/02-messages-and-queries.md index 2021c7e967be..749f7547ece9 100644 --- a/docs/docs/building-modules/02-messages-and-queries.md +++ b/docs/docs/building-modules/02-messages-and-queries.md @@ -63,8 +63,6 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.47.0-rc1/types/tx_msg.go#L14-L26 It extends `proto.Message` and contains the following methods: -* `Route() string`: Name of the route for this message. Typically all `message`s in a module have the same route, which is most often the module's name. -* `Type() string`: Type of the message, used primarily in [events](../core/08-events.md). This should return a message-specific `string`, typically the denomination of the message itself. * [`ValidateBasic() error`](../basics/01-tx-lifecycle.md#ValidateBasic). * `GetSignBytes() []byte`: Return the canonical byte representation of the message. Used to generate a signature. * `GetSigners() []AccAddress`: Return the list of signers. The Cosmos SDK will make sure that each `message` contained in a transaction is signed by all the signers listed in the list returned by this method. diff --git a/docs/docs/core/08-events.md b/docs/docs/core/08-events.md index 15535e5776e2..ba860d3d3203 100644 --- a/docs/docs/core/08-events.md +++ b/docs/docs/core/08-events.md @@ -57,7 +57,6 @@ The following examples show how to query Events using the Cosmos SDK. | ------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------- | | `tx.height=23` | Query all transactions at height 23 | | `message.action='/cosmos.bank.v1beta1.Msg/Send'` | Query all transactions containing a x/bank `Send` [Service `Msg`](../building-modules/03-msg-services.md). Note the `'`s around the value. | -| `message.action='send'` | Query all transactions containing a x/bank `Send` [legacy `Msg`](../building-modules/03-msg-services.md#legacy-amino-msgs). Note the `'`s around the value. | | `message.module='bank'` | Query all transactions containing messages from the x/bank module. Note the `'`s around the value. | | `create_validator.validator='cosmosval1...'` | x/staking-specific Event, see [x/staking SPEC](../modules/staking/README.md). | diff --git a/x/gov/client/utils/query_test.go b/x/gov/client/utils/query_test.go index 02f8ea611348..2479e832c59f 100644 --- a/x/gov/client/utils/query_test.go +++ b/x/gov/client/utils/query_test.go @@ -13,7 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/client" sdk "github.com/cosmos/cosmos-sdk/types" moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" "github.com/cosmos/cosmos-sdk/x/gov" "github.com/cosmos/cosmos-sdk/x/gov/client/utils" v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -46,7 +45,7 @@ func (mock TxSearchMock) TxSearch(ctx context.Context, query string, prove bool, return nil, err } for _, msg := range sdkTx.GetMsgs() { - if msg.(legacytx.LegacyMsg).Type() == msgType { + if sdk.MsgTypeURL(msg) == msgType { matchingTxs = append(matchingTxs, tx) break } diff --git a/x/gov/types/v1beta1/msgs.go b/x/gov/types/v1beta1/msgs.go index 6fb219deea96..3bff5eff98db 100644 --- a/x/gov/types/v1beta1/msgs.go +++ b/x/gov/types/v1beta1/msgs.go @@ -14,6 +14,14 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/types" ) +// Governance message types and routes +const ( + TypeMsgDeposit = "deposit" + TypeMsgVote = "vote" + TypeMsgVoteWeighted = "weighted_vote" + TypeMsgSubmitProposal = "submit_proposal" +) + var ( _, _, _, _ sdk.Msg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} _, _, _, _ legacytx.LegacyMsg = &MsgSubmitProposal{}, &MsgDeposit{}, &MsgVote{}, &MsgVoteWeighted{} From 9c0f1113908aa1c65c10e6b0db11c2df21fa4e85 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:22:28 +0100 Subject: [PATCH 10/32] updates --- testutil/testdata/tx.go | 6 +----- x/staking/simulation/operations_test.go | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/testutil/testdata/tx.go b/testutil/testdata/tx.go index 6053a903319e..9b4e081253ff 100644 --- a/testutil/testdata/tx.go +++ b/testutil/testdata/tx.go @@ -13,7 +13,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/query" - "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) // AddressGenerator creates and returns a random address generator using rapid. @@ -77,10 +76,7 @@ func NewTestMsg(addrs ...sdk.AccAddress) *TestMsg { } } -var ( - _ sdk.Msg = (*TestMsg)(nil) - _ legacytx.LegacyMsg = (*TestMsg)(nil) -) +var _ sdk.Msg = (*TestMsg)(nil) func (msg *TestMsg) GetSignBytes() []byte { bz, err := json.Marshal(msg.Signers) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index ff52bd293106..362751278551 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -147,6 +147,7 @@ func (s *SimTestSuite) TestWeightedOperations() { // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail require.Equal(expected[i].weight, w.Weight(), "weight should be the same") + require.Equal(expected[i].opMsgRoute, operationMsg.Route, "route should be the same") require.Equal(expected[i].opMsgName, operationMsg.Name, "operation Msg name should be the same") } } From de280320ecce8f8a658dbddf9566d454f1470436 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:25:12 +0100 Subject: [PATCH 11/32] add changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74ed0ac82b78..c9f4c8b5699a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (x/auth/tx) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove `.Type()` and `Route()` methods from all msgs and `legacytx.LegacyMsg` interface. * [#14691](https://github.com/cosmos/cosmos-sdk/pull/14691) Change behavior of `sdk.StringifyEvents` to not flatten events attributes by events type. * This change only affects ABCI message logs, and not the actual events. * [#14692](https://github.com/cosmos/cosmos-sdk/pull/14692) Improve RPC queries error message when app is at height 0. @@ -165,6 +166,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/simulation) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove the `MsgType` field from `simulation.OperationInput` struct. * (crypto/keyring) [#13734](https://github.com/cosmos/cosmos-sdk/pull/13834) The keyring's `Sign` method now takes a new `signMode` argument. It is only used if the signing key is a Ledger hardware device. You can set it to 0 in all other cases. * (x/evidence) [14724](https://github.com/cosmos/cosmos-sdk/pull/14724) Extract Evidence in its own go.mod and rename the package to `cosmossdk.io/x/evidence`. * (x/nft) [#14725](https://github.com/cosmos/cosmos-sdk/pull/14725) Extract NFT in its own go.mod and rename the package to `cosmossdk.io/x/nft`. From 29300e8a7962089f87b6856b77128563f51b3893 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:32:54 +0100 Subject: [PATCH 12/32] revert --- x/evidence/types/genesis_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/x/evidence/types/genesis_test.go b/x/evidence/types/genesis_test.go index 79c57ef4c2d6..425aceb8b909 100644 --- a/x/evidence/types/genesis_test.go +++ b/x/evidence/types/genesis_test.go @@ -164,6 +164,14 @@ func (*TestEvidence) String() string { return "test-string" } +func (*TestEvidence) Route() string { + return "test-route" +} + +func (*TestEvidence) Type() string { + return "test-type" +} + func (*TestEvidence) ProtoMessage() {} func (*TestEvidence) Reset() {} From a7dee1e3054adf6b8fd9d352152cd81e2db2ba49 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:42:05 +0100 Subject: [PATCH 13/32] updates --- x/bank/simulation/operations.go | 1 - x/bank/simulation/operations_test.go | 24 ++++++------- x/distribution/simulation/operations_test.go | 24 ++++++------- x/staking/simulation/operations_test.go | 36 ++++++++++---------- 4 files changed, 42 insertions(+), 43 deletions(-) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 68932910784f..25aa67759269 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -62,7 +62,6 @@ func SimulateMsgSend(ak types.AccountKeeper, bk keeper.Keeper) simtypes.Operatio r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - msgType := sdk.MsgTypeURL(&types.MsgSend{}) from, to, coins, skip := randomSendFields(r, ctx, accs, bk, ak) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index f88e037a2812..0988c8d1c42b 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -105,14 +105,14 @@ func (suite *SimTestSuite) TestSimulateMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("65337742stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.FromAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.ToAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -133,8 +133,8 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require := suite.Require() require.NoError(err) - var msg *types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Len(msg.Inputs, 1) @@ -143,7 +143,7 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSend() { require.Len(msg.Outputs, 2) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Outputs[1].Address) require.Equal("107287087stake", msg.Outputs[1].Coins.String()) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) require.Len(futureOperations, 0) } @@ -169,12 +169,12 @@ func (suite *SimTestSuite) TestSimulateModuleAccountMsgSend() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg *types.MsgSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -197,12 +197,12 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().Error(err) - var msg *types.MsgMultiSend - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgMultiSend + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().False(operationMsg.OK) // sending tokens to a module account should fail suite.Require().Equal(operationMsg.Comment, "invalid transfers") - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgMultiSend{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/distribution/simulation/operations_test.go b/x/distribution/simulation/operations_test.go index 3211dc43d287..717b105cbd9f 100644 --- a/x/distribution/simulation/operations_test.go +++ b/x/distribution/simulation/operations_test.go @@ -78,13 +78,13 @@ func (suite *SimTestSuite) TestSimulateMsgSetWithdrawAddress() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgSetWithdrawAddress - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgSetWithdrawAddress + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) suite.Require().Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.WithdrawAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgSetWithdrawAddress{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -118,13 +118,13 @@ func (suite *SimTestSuite) TestSimulateMsgWithdrawDelegatorReward() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgWithdrawDelegatorReward - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgWithdrawDelegatorReward + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1l4s054098kk9hmr5753c6k3m2kw65h686d3mhr", msg.ValidatorAddress) suite.Require().Equal("cosmos1d6u7zhjwmsucs678d7qn95uqajd4ucl9jcjt26", msg.DelegatorAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawDelegatorReward{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } @@ -178,12 +178,12 @@ func (suite *SimTestSuite) testSimulateMsgWithdrawValidatorCommission(tokenName } else { suite.Require().NoError(err) - var msg *types.MsgWithdrawValidatorCommission - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgWithdrawValidatorCommission + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgWithdrawValidatorCommission{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } } @@ -204,13 +204,13 @@ func (suite *SimTestSuite) TestSimulateMsgFundCommunityPool() { operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") suite.Require().NoError(err) - var msg *types.MsgFundCommunityPool - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgFundCommunityPool + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) suite.Require().True(operationMsg.OK) suite.Require().Equal("4896096stake", msg.Amount.String()) suite.Require().Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Depositor) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(msg)) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgFundCommunityPool{}), sdk.MsgTypeURL(&msg)) suite.Require().Len(futureOperations, 0) } diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 362751278551..d3f11642eae1 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -164,11 +164,11 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, s.ctx, s.accounts[1:], "") require.NoError(err) - var msg *types.MsgCreateValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgCreateValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgCreateValidator{}), sdk.MsgTypeURL(&msg)) valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress) require.NoError(err) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String()) @@ -210,11 +210,11 @@ func (s *SimTestSuite) TestSimulateMsgCancelUnbondingDelegation() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, accounts, "") require.NoError(err) - var msg *types.MsgCancelUnbondingDelegation - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgCancelUnbondingDelegation + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{}), sdk.MsgTypeURL(&msg)) require.Equal(delegator.Address.String(), msg.DelegatorAddress) require.Equal(validator0.GetOperator().String(), msg.ValidatorAddress) require.Len(futureOperations, 0) @@ -238,11 +238,11 @@ func (s *SimTestSuite) TestSimulateMsgEditValidator() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg *types.MsgEditValidator - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgEditValidator + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) - require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgEditValidator{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -259,13 +259,13 @@ func (s *SimTestSuite) TestSimulateMsgDelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts[1:], "") require.NoError(err) - var msg *types.MsgDelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgDelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgDelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1tnh2q55v8wyygtt9srz5safamzdengsn9dsd7z", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -298,14 +298,14 @@ func (s *SimTestSuite) TestSimulateMsgUndelegate() { operationMsg, futureOperations, err := op(s.r, s.app.BaseApp, ctx, s.accounts, "") require.NoError(err) - var msg *types.MsgUndelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgUndelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.DelegatorAddress) require.Equal("1646627814093010272", msg.Amount.Amount.String()) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgUndelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress) require.Len(futureOperations, 0) } @@ -342,13 +342,13 @@ func (s *SimTestSuite) TestSimulateMsgBeginRedelegate() { s.T().Logf("operation message: %v", operationMsg) require.NoError(err) - var msg *types.MsgBeginRedelegate - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg types.MsgBeginRedelegate + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.True(operationMsg.OK) require.Equal("cosmos1ua0fwyws7vzjrry3pqkklvf8mny93l9s9zg0h4", msg.DelegatorAddress) require.Equal("stake", msg.Amount.Denom) - require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(msg)) + require.Equal(sdk.MsgTypeURL(&types.MsgBeginRedelegate{}), sdk.MsgTypeURL(&msg)) require.Equal("cosmosvaloper1ghekyjucln7y67ntx7cf27m9dpuxxemnsvnaes", msg.ValidatorDstAddress) require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorSrcAddress) require.Len(futureOperations, 0) From 305ea9fee121108def1ed26cae780b099679fcc3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 16:58:03 +0100 Subject: [PATCH 14/32] improvements --- x/authz/simulation/operations_test.go | 16 +++++++--------- x/group/simulation/operations.go | 12 ++++++------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/x/authz/simulation/operations_test.go b/x/authz/simulation/operations_test.go index 481fec1a828b..0a2b7ffb17a6 100644 --- a/x/authz/simulation/operations_test.go +++ b/x/authz/simulation/operations_test.go @@ -69,10 +69,11 @@ func (suite *SimTestSuite) TestWeightedOperations() { expected := []struct { weight int opMsgRoute string + opMsgName string }{ - {simulation.WeightGrant, simulation.TypeMsgGrant}, - {simulation.WeightExec, simulation.TypeMsgExec}, - {simulation.WeightRevoke, simulation.TypeMsgRevoke}, + {simulation.WeightGrant, authz.ModuleName, simulation.TypeMsgGrant}, + {simulation.WeightExec, authz.ModuleName, simulation.TypeMsgExec}, + {simulation.WeightRevoke, authz.ModuleName, simulation.TypeMsgRevoke}, } require := suite.Require() @@ -83,12 +84,9 @@ func (suite *SimTestSuite) TestWeightedOperations() { // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests // will fail - require.Equal(expected[i].weight, w.Weight(), - "weight should be the same. %v", op.Comment) - require.Equal(expected[i].opMsgRoute, op.Route, - "route should be the same. %v", op.Comment) - require.Equal(expected[i].opMsgRoute, op.Name, - "operation Msg name should be the same %v", op.Comment) + require.Equal(expected[i].weight, w.Weight(), "weight should be the same. %v", op.Comment) + require.Equal(expected[i].opMsgRoute, op.Route, "route should be the same. %v", op.Comment) + require.Equal(expected[i].opMsgName, op.Name, "operation Msg name should be the same %v", op.Comment) } } diff --git a/x/group/simulation/operations.go b/x/group/simulation/operations.go index f150cdab2395..9b19fd692f46 100644 --- a/x/group/simulation/operations.go +++ b/x/group/simulation/operations.go @@ -1067,26 +1067,26 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { _, groupPolicy, acc, account, err := randomGroupPolicy(r, k, ak, sdkCtx, accounts) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, ""), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, ""), nil, err } if groupPolicy == nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no group policy found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no group policy found"), nil, nil } groupPolicyAddr := groupPolicy.Address spendableCoins := bk.SpendableCoins(sdkCtx, account.GetAddress()) fees, err := simtypes.RandomFees(r, sdkCtx, spendableCoins) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fee error"), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "fee error"), nil, err } proposalsResult, err := k.ProposalsByGroupPolicy(sdkCtx, &group.QueryProposalsByGroupPolicyRequest{Address: groupPolicyAddr}) if err != nil { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "fail to query group info"), nil, err + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "fail to query group info"), nil, err } proposals := proposalsResult.GetProposals() if len(proposals) == 0 { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no proposals found"), nil, nil } proposalID := -1 @@ -1100,7 +1100,7 @@ func SimulateMsgExec(cdc *codec.ProtoCodec, ak group.AccountKeeper, // return no-op if no proposal found if proposalID == -1 { - return simtypes.NoOpMsg(TypeMsgExec, TypeMsgExec, "no proposals found"), nil, nil + return simtypes.NoOpMsg(group.ModuleName, TypeMsgExec, "no proposals found"), nil, nil } msg := &group.MsgExec{ From 598d1c632262bae1927c090a2f78393d5327cf3a Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 17:05:40 +0100 Subject: [PATCH 15/32] last fix --- x/gov/simulation/operations_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 29c97a8ece08..d652e672b448 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -132,8 +132,8 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) - var msg *v1.MsgSubmitProposal - err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, msg) + var msg v1.MsgSubmitProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) require.NoError(t, err) require.True(t, operationMsg.OK) @@ -142,7 +142,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.Equal(t, "2686011stake", msg.InitialDeposit[0].String()) require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) - require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(msg)) + require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) } // TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. From 7575d4e757e5232fc1bac36f117256acdd267968 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 17:10:48 +0100 Subject: [PATCH 16/32] conflict fix --- x/staking/types/msg.go | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 168a6e7af5b1..4542f3b821d0 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -360,14 +360,7 @@ func (m MsgUpdateParams) ValidateBasic() error { if _, err := sdk.AccAddressFromBech32(m.Authority); err != nil { return sdkerrors.Wrap(err, "invalid authority address") } - return msg.Params.Validate() -} - -// GetSignBytes returns the raw bytes for a MsgUpdateParams message that -// the expected signer needs to sign. -func (msg MsgUpdateParams) GetSignBytes() []byte { - bz := ModuleCdc.MustMarshalJSON(&msg) - return sdk.MustSortJSON(bz) + return m.Params.Validate() } // GetSigners returns the expected signers for a MsgUpdateParams message From 9d59dfa0c2481682b67365efc20128b4277ecff3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Tue, 24 Jan 2023 20:52:01 +0100 Subject: [PATCH 17/32] updates --- x/staking/simulation/operations_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index d3f11642eae1..55f9391809ea 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -137,6 +137,7 @@ func (s *SimTestSuite) TestWeightedOperations() { {simulation.DefaultWeightMsgUndelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgUndelegate{})}, {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgBeginRedelegate{})}, {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{})}, + {simulation.DefaultWeightMsgUpdateParams, types.ModuleName, sdk.MsgTypeURL(&types.MsgUpdateParams{})}, } for i, w := range weightesOps { From 515864658b185c97af94bd5f624094200649733d Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Wed, 25 Jan 2023 15:36:28 +0100 Subject: [PATCH 18/32] wip --- x/bank/simulation/operations.go | 33 ++++++++++++++++++++++++++-- x/bank/simulation/operations_test.go | 23 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index d91b70c5a205..f42174631ed9 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -25,7 +25,7 @@ const ( OpWeightMsgUpdateParams = "op_weight_msg_update_params" DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend - DefaultWeightMsgUpdateParams = 100 + DefaultWeightMsgUpdateParams = 5 ) // WeightedOperations returns all the operations from the module with their respective weights @@ -340,7 +340,36 @@ func SimulateMsgUpdateParams(ak types.AccountKeeper, bk keeper.Keeper) simtypes. 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 + simAccount, _ := simtypes.RandomAcc(r, accs) + account := ak.GetAccount(ctx, simAccount.Address) + spendable := bk.SpendableCoins(ctx, account.GetAddress()) + + authority := ak.GetModuleAccount(ctx, "gov") + msg := &types.MsgUpdateParams{ + Authority: authority.String(), + Params: randomParams(), + } + + txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig + txCtx := simulation.OperationInput{ + R: r, + App: app, + TxGen: txConfig, + Cdc: nil, + Msg: msg, + Context: ctx, + SimAccount: simAccount, + AccountKeeper: ak, + ModuleName: types.ModuleName, + } + + return simulation.GenAndDeliverTx(txCtx, spendable) + } +} + +func randomParams() types.Params { + return types.Params{ + DefaultSendEnabled: false, } } diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 0988c8d1c42b..a3250f7fd43b 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -74,6 +74,7 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ {100, types.ModuleName, sdk.MsgTypeURL(&types.MsgSend{})}, {10, types.ModuleName, sdk.MsgTypeURL(&types.MsgMultiSend{})}, + {5, types.ModuleName, sdk.MsgTypeURL(&types.MsgUpdateParams{})}, } for i, w := range weightesOps { @@ -206,6 +207,28 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { suite.Require().Len(futureOperations, 0) } +func (suite *SimTestSuite) TestSimulateMsgUpdateParams() { + s := rand.NewSource(1) + r := rand.New(s) + accounts := suite.getTestingAccounts(r, 2) + + // begin a new block + suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}}) + + // execute operation + op := simulation.SimulateMsgUpdateParams(suite.accountKeeper, suite.bankKeeper) + + operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") + suite.Require().Error(err) + + var msg types.MsgUpdateParams + types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + + suite.Require().False(operationMsg.OK) + suite.Require().Equal(sdk.MsgTypeURL(&types.MsgUpdateParams{}), sdk.MsgTypeURL(&msg)) + suite.Require().Len(futureOperations, 0) +} + func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { accounts := simtypes.RandomAccounts(r, n) From 776b2a3fee8f6572caa857ac5beee9544dd24c85 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 15:18:39 +0100 Subject: [PATCH 19/32] updates --- UPGRADING.md | 2 + testutil/sims/simulation_helpers.go | 2 +- types/module/simulation.go | 34 +++++------ types/simulation/types.go | 39 +++++++----- x/auth/module.go | 6 +- x/auth/simulation/operations.go | 49 --------------- x/auth/simulation/operations_test.go | 1 - x/auth/simulation/proposals.go | 49 +++++++++++++++ x/auth/simulation/proposals_test.go | 45 ++++++++++++++ x/authz/module/module.go | 5 +- x/bank/module.go | 6 +- x/bank/simulation/operations.go | 59 ++---------------- x/bank/simulation/operations_test.go | 22 ------- x/bank/simulation/proposals.go | 56 +++++++++++++++++ x/bank/simulation/proposals_test.go | 44 ++++++++++++++ x/capability/module.go | 4 +- x/distribution/module.go | 7 +-- x/distribution/simulation/operations.go | 21 ------- x/distribution/simulation/proposals.go | 46 ++++++++++++++ x/distribution/simulation/proposals_test.go | 42 +++++++++++++ x/evidence/module.go | 5 +- x/feegrant/module/module.go | 5 +- x/gov/module.go | 9 ++- x/gov/simulation/operations.go | 67 ++++++++------------- x/gov/simulation/operations_test.go | 43 ++++++------- x/gov/simulation/proposals.go | 23 +++---- x/gov/simulation/proposals_test.go | 20 +++--- x/group/module/module.go | 5 +- x/mint/module.go | 6 +- x/mint/simulation/operations.go | 50 --------------- x/mint/simulation/operations_test.go | 1 - x/mint/simulation/proposals.go | 50 +++++++++++++++ x/mint/simulation/proposals_test.go | 46 ++++++++++++++ x/params/module.go | 5 +- x/simulation/params.go | 27 ++++----- x/slashing/module.go | 6 +- x/slashing/simulation/operations.go | 25 +------- x/slashing/simulation/proposals.go | 50 +++++++++++++++ x/slashing/simulation/proposals_test.go | 46 ++++++++++++++ x/staking/module.go | 6 +- x/staking/simulation/operations.go | 19 ------ x/staking/simulation/proposals.go | 51 ++++++++++++++++ x/staking/simulation/proposals_test.go | 47 +++++++++++++++ 43 files changed, 731 insertions(+), 420 deletions(-) delete mode 100644 x/auth/simulation/operations.go delete mode 100644 x/auth/simulation/operations_test.go create mode 100644 x/auth/simulation/proposals.go create mode 100644 x/auth/simulation/proposals_test.go create mode 100644 x/bank/simulation/proposals.go create mode 100644 x/bank/simulation/proposals_test.go create mode 100644 x/distribution/simulation/proposals.go create mode 100644 x/distribution/simulation/proposals_test.go delete mode 100644 x/mint/simulation/operations.go delete mode 100644 x/mint/simulation/operations_test.go create mode 100644 x/mint/simulation/proposals.go create mode 100644 x/mint/simulation/proposals_test.go create mode 100644 x/slashing/simulation/proposals.go create mode 100644 x/slashing/simulation/proposals_test.go create mode 100644 x/staking/simulation/proposals.go create mode 100644 x/staking/simulation/proposals_test.go diff --git a/UPGRADING.md b/UPGRADING.md index 475daa7450f4..1fd49d530638 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -83,6 +83,8 @@ The `x/nft` module is extracted to have a separate go.mod file which allows it b Remove `RandomizedParams` from `AppModuleSimulation` interface. Previously, it used to generate random parameter changes during simulations, however, it does so through ParamChangeProposal which is now legacy. Since all modules were migrated, we can now safely remove this from `AppModuleSimulation` interface. +Moreover, to support the `MsgUpdateParams` governance proposals for each modules, `AppModuleSimulation` now defines a `ProposalMsgs` method instead of `ProposalContents`. That method defines the messages that can be used to submit a proposal and that should be tested in simulation. + ### gRPC A new gRPC service, `proto/cosmos/base/node/v1beta1/query.proto`, has been introduced diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index ec6a619450a6..3b6af2102da9 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -67,7 +67,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - simState.Contents = app.SimulationManager().GetProposalContents(simState) + simState.ProposalMsg = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 6c6c467cbe59..3d52f9f5c4b9 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -17,8 +17,8 @@ type AppModuleSimulation interface { // randomized genesis states GenerateGenesisState(input *SimulationState) - // content functions used to simulate governance proposals - ProposalContents(simState SimulationState) []simulation.WeightedProposalContent + // msg functions used to simulate governance proposals + ProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg // register a func to decode the each module's defined types from their corresponding store key RegisterStoreDecoder(simulation.StoreDecoderRegistry) @@ -76,12 +76,12 @@ func NewSimulationManagerFromAppModules(modules map[string]interface{}, override return NewSimulationManager(simModules...) } -// GetProposalContents returns each module's proposal content generator function +// GetProposalMsgs returns each module's proposal msg generator function // with their default operation weight and key. -func (sm *SimulationManager) GetProposalContents(simState SimulationState) []simulation.WeightedProposalContent { - wContents := make([]simulation.WeightedProposalContent, 0, len(sm.Modules)) +func (sm *SimulationManager) GetProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg { + wContents := make([]simulation.WeightedProposalMsg, 0, len(sm.Modules)) for _, module := range sm.Modules { - wContents = append(wContents, module.ProposalContents(simState)...) + wContents = append(wContents, module.ProposalMsgs(simState)...) } return wContents @@ -116,15 +116,15 @@ func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simu // 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 - LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - Contents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key + 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 + ProposalMsg []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/types/simulation/types.go b/types/simulation/types.go index acb2d27d0d07..25b6dee46dcd 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -12,22 +12,33 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -type WeightedProposalContent interface { - AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params - DefaultWeight() int // default weight - ContentSimulatorFn() ContentSimulatorFn // content simulator function +// // Deprecated: Use WeightedProposalMsg instead. +// type WeightedProposalContent interface { +// AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params +// DefaultWeight() int // default weight +// ContentSimulatorFn() ContentSimulatorFn // content simulator function +// } + +// // Deprecated: Use MsgSimulatorFn instead. +// type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content + +// // Deprecated: Use MsgSimulatorFn instead. +// type Content interface { +// GetTitle() string +// GetDescription() string +// ProposalRoute() string +// ProposalType() string +// ValidateBasic() error +// String() string +// } + +type WeightedProposalMsg interface { + AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params + DefaultWeight() int // default weight + MsgSimulatorFn() MsgSimulatorFn // msg simulator function } -type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content - -type Content interface { - GetTitle() string - GetDescription() string - ProposalRoute() string - ProposalType() string - ValidateBasic() error - String() string -} +type MsgSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) sdk.Msg type SimValFn func(r *rand.Rand) string diff --git a/x/auth/module.go b/x/auth/module.go index a3dcb33d25c5..b3d9a36de4cd 100644 --- a/x/auth/module.go +++ b/x/auth/module.go @@ -178,9 +178,9 @@ func (am AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState, am.randGenAccountsFn) } -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for auth module's types diff --git a/x/auth/simulation/operations.go b/x/auth/simulation/operations.go deleted file mode 100644 index 0028c3915831..000000000000 --- a/x/auth/simulation/operations.go +++ /dev/null @@ -1,49 +0,0 @@ -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" -) - -// 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 - } -} diff --git a/x/auth/simulation/operations_test.go b/x/auth/simulation/operations_test.go deleted file mode 100644 index 5c6452f9a069..000000000000 --- a/x/auth/simulation/operations_test.go +++ /dev/null @@ -1 +0,0 @@ -package simulation_test diff --git a/x/auth/simulation/proposals.go b/x/auth/simulation/proposals.go new file mode 100644 index 000000000000..29d5e37e23cf --- /dev/null +++ b/x/auth/simulation/proposals.go @@ -0,0 +1,49 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/auth/types" + "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" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.MaxMemoCharacters = uint64(simtypes.RandIntBetween(r, 0, 1000)) + params.TxSigLimit = uint64(simtypes.RandIntBetween(r, 0, 1000)) + params.TxSizeCostPerByte = uint64(simtypes.RandIntBetween(r, 0, 1000)) + params.SigVerifyCostED25519 = uint64(simtypes.RandIntBetween(r, 0, 1000)) + params.SigVerifyCostSecp256k1 = uint64(simtypes.RandIntBetween(r, 0, 1000)) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/auth/simulation/proposals_test.go b/x/auth/simulation/proposals_test.go new file mode 100644 index 000000000000..ffce0aee11f6 --- /dev/null +++ b/x/auth/simulation/proposals_test.go @@ -0,0 +1,45 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/auth/simulation" + "github.com/cosmos/cosmos-sdk/x/auth/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.Equal(t, uint64(540), msgUpdateParams.Params.MaxMemoCharacters) + assert.Equal(t, uint64(456), msgUpdateParams.Params.TxSigLimit) + assert.Equal(t, uint64(300), msgUpdateParams.Params.TxSizeCostPerByte) + assert.Equal(t, uint64(694), msgUpdateParams.Params.SigVerifyCostED25519) + assert.Equal(t, uint64(511), msgUpdateParams.Params.SigVerifyCostSecp256k1) +} diff --git a/x/authz/module/module.go b/x/authz/module/module.go index cee8ad3b8666..76fadc8547f6 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -206,9 +206,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the authz content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs returns all the authz msgs functions used to simulate governance proposals. +func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/bank/module.go b/x/bank/module.go index 0b7329296423..c0d105e16e5c 100644 --- a/x/bank/module.go +++ b/x/bank/module.go @@ -182,9 +182,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(_ module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for supply module's types diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index f42174631ed9..0ad0972c5d15 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -20,19 +20,17 @@ import ( // //nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgSend = "op_weight_msg_send" - OpWeightMsgMultiSend = "op_weight_msg_multisend" - OpWeightMsgUpdateParams = "op_weight_msg_update_params" - DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend - DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend - DefaultWeightMsgUpdateParams = 5 + OpWeightMsgSend = "op_weight_msg_send" + OpWeightMsgMultiSend = "op_weight_msg_multisend" + DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend + DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend ) // 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, weightMsgUpdateParams int + var weightMsgSend, weightMsgMultiSend int appParams.GetOrGenerate(cdc, OpWeightMsgSend, &weightMsgSend, nil, func(_ *rand.Rand) { @@ -46,12 +44,6 @@ func WeightedOperations( }, ) - appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, - func(_ *rand.Rand) { - weightMsgUpdateParams = DefaultWeightMsgUpdateParams - }, - ) - return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgSend, @@ -61,10 +53,6 @@ func WeightedOperations( weightMsgMultiSend, SimulateMsgMultiSend(ak, bk), ), - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, bk), - ), } } @@ -336,43 +324,6 @@ 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) { - simAccount, _ := simtypes.RandomAcc(r, accs) - account := ak.GetAccount(ctx, simAccount.Address) - spendable := bk.SpendableCoins(ctx, account.GetAddress()) - - authority := ak.GetModuleAccount(ctx, "gov") - msg := &types.MsgUpdateParams{ - Authority: authority.String(), - Params: randomParams(), - } - - txConfig := moduletestutil.MakeTestEncodingConfig().TxConfig - txCtx := simulation.OperationInput{ - R: r, - App: app, - TxGen: txConfig, - Cdc: nil, - Msg: msg, - Context: ctx, - SimAccount: simAccount, - AccountKeeper: ak, - ModuleName: types.ModuleName, - } - - return simulation.GenAndDeliverTx(txCtx, spendable) - } -} - -func randomParams() types.Params { - return types.Params{ - DefaultSendEnabled: false, - } -} - // sendMsgMultiSend sends a transaction with a MsgMultiSend from a provided random // account. func sendMsgMultiSend( diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index a3250f7fd43b..5bfec9c70e62 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -207,28 +207,6 @@ func (suite *SimTestSuite) TestSimulateMsgMultiSendToModuleAccount() { suite.Require().Len(futureOperations, 0) } -func (suite *SimTestSuite) TestSimulateMsgUpdateParams() { - s := rand.NewSource(1) - r := rand.New(s) - accounts := suite.getTestingAccounts(r, 2) - - // begin a new block - suite.app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: suite.app.LastBlockHeight() + 1, AppHash: suite.app.LastCommitID().Hash}}) - - // execute operation - op := simulation.SimulateMsgUpdateParams(suite.accountKeeper, suite.bankKeeper) - - operationMsg, futureOperations, err := op(r, suite.app.BaseApp, suite.ctx, accounts, "") - suite.Require().Error(err) - - var msg types.MsgUpdateParams - types.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) - - suite.Require().False(operationMsg.OK) - suite.Require().Equal(sdk.MsgTypeURL(&types.MsgUpdateParams{}), sdk.MsgTypeURL(&msg)) - suite.Require().Len(futureOperations, 0) -} - func (suite *SimTestSuite) getTestingAccounts(r *rand.Rand, n int) []simtypes.Account { accounts := simtypes.RandomAccounts(r, n) diff --git a/x/bank/simulation/proposals.go b/x/bank/simulation/proposals.go new file mode 100644 index 000000000000..e1090cefe2ed --- /dev/null +++ b/x/bank/simulation/proposals.go @@ -0,0 +1,56 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/types" + "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" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.DefaultSendEnabled = r.Intn(2) == 0 + if r.Intn(2) == 0 { + params.SendEnabled = nil + } else { + params.SendEnabled = make([]*types.SendEnabled, 10) + for i := 0; i < r.Intn(10); i++ { + params.SendEnabled[i] = types.NewSendEnabled( + simtypes.RandStringOfLength(r, 10), + r.Intn(2) == 0, + ) + } + } + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/bank/simulation/proposals_test.go b/x/bank/simulation/proposals_test.go new file mode 100644 index 000000000000..df7d31398ca4 --- /dev/null +++ b/x/bank/simulation/proposals_test.go @@ -0,0 +1,44 @@ +package simulation_test + +import ( + "fmt" + "math/rand" + "testing" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/simulation" + "github.com/cosmos/cosmos-sdk/x/bank/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + fmt.Println(msgUpdateParams) + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) + assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled) +} diff --git a/x/capability/module.go b/x/capability/module.go index 7434eba8109c..85b8abc7c294 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -162,8 +162,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents performs a no-op -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs doesn't return any msg functions for governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/distribution/module.go b/x/distribution/module.go index f9d09cfd6ee1..d5b6f54e809a 100644 --- a/x/distribution/module.go +++ b/x/distribution/module.go @@ -184,10 +184,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the distribution content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for distribution module's types diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index c65e0a4e7275..7f9e61d1d03d 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -25,13 +25,11 @@ 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" 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 @@ -64,13 +62,6 @@ 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) @@ -91,10 +82,6 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty weightMsgFundCommunityPool, SimulateMsgFundCommunityPool(txConfig, ak, bk, k, sk), ), - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, k), - ), } } @@ -265,11 +252,3 @@ 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 - } -} diff --git a/x/distribution/simulation/proposals.go b/x/distribution/simulation/proposals.go new file mode 100644 index 000000000000..73bb25e4a1da --- /dev/null +++ b/x/distribution/simulation/proposals.go @@ -0,0 +1,46 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/distribution/types" + "github.com/cosmos/cosmos-sdk/x/simulation" +) + +// Simulation operation weights constants +// +//nolint:gosec // these are not hardcoded credentials. +const ( + DefaultWeightMsgUpdateParams int = 50 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.CommunityTax = simtypes.RandomDecAmount(r, sdk.NewDec(1)) + params.WithdrawAddrEnabled = r.Intn(2) == 0 + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/distribution/simulation/proposals_test.go b/x/distribution/simulation/proposals_test.go new file mode 100644 index 000000000000..77d7d570716e --- /dev/null +++ b/x/distribution/simulation/proposals_test.go @@ -0,0 +1,42 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/distribution/simulation" + "github.com/cosmos/cosmos-sdk/x/distribution/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.DeepEqual(t, sdk.NewDec(0), msgUpdateParams.Params.CommunityTax) + assert.Equal(t, true, msgUpdateParams.Params.WithdrawAddrEnabled) +} diff --git a/x/evidence/module.go b/x/evidence/module.go index 666f0d79cdb4..0a7ebdaa2a90 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -177,9 +177,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the evidence content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs doesn't return any msg functions for governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index b2dea8f55e1c..e52754b11bc6 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -207,9 +207,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the feegrant content functions used to -// simulate governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs doesn't return any msg functions for governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/gov/module.go b/x/gov/module.go index d5f7f4ac8145..eaca2496c7c3 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -331,10 +331,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the gov content functions used to -// simulate governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return simulation.ProposalContents() +// ProposalMsgs returns all the gov msgs used to simulate governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for gov module's types @@ -346,6 +345,6 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( simState.AppParams, simState.Cdc, - am.accountKeeper, am.bankKeeper, am.keeper, simState.Contents, + am.accountKeeper, am.bankKeeper, am.keeper, simState.ProposalMsg, ) } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index dc1f8de63a1b..27dc7a497da5 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -37,24 +37,21 @@ const ( OpWeightMsgVote = "op_weight_msg_vote" OpWeightMsgVoteWeighted = "op_weight_msg_weighted_vote" OpWeightMsgCancelProposal = "op_weight_msg_cancel_proposal" - OpWeightMsgUpdateParams = "op_weight_msg_update_params" DefaultWeightMsgDeposit = 100 DefaultWeightMsgVote = 67 DefaultWeightMsgVoteWeighted = 33 DefaultWeightTextProposal = 5 DefaultWeightMsgCancelProposal = 5 - DefaultWeightMsgUpdateParams = 5 ) // 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, wContents []simtypes.WeightedProposalContent) simulation.WeightedOperations { +func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, wMsgs []simtypes.WeightedProposalMsg) simulation.WeightedOperations { var ( weightMsgDeposit int weightMsgVote int weightMsgVoteWeighted int weightMsgCancelProposal int - weightMsgUpdateParams int ) appParams.GetOrGenerate(cdc, OpWeightMsgDeposit, &weightMsgDeposit, nil, @@ -81,26 +78,20 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty }, ) - appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, - func(_ *rand.Rand) { - weightMsgUpdateParams = DefaultWeightMsgUpdateParams - }, - ) - // generate the weighted operations for the proposal contents var wProposalOps simulation.WeightedOperations - for _, wContent := range wContents { - wContent := wContent // pin variable + for _, wMsg := range wMsgs { + wMsg := wMsg // pin variable var weight int - appParams.GetOrGenerate(cdc, wContent.AppParamsKey(), &weight, nil, - func(_ *rand.Rand) { weight = wContent.DefaultWeight() }) + appParams.GetOrGenerate(cdc, wMsg.AppParamsKey(), &weight, nil, + func(_ *rand.Rand) { weight = wMsg.DefaultWeight() }) wProposalOps = append( wProposalOps, simulation.NewWeightedOperation( weight, - SimulateMsgSubmitProposal(ak, bk, k, wContent.ContentSimulatorFn()), + SimulateMsgSubmitProposal(ak, bk, k, wMsg.MsgSimulatorFn()), ), ) } @@ -122,27 +113,15 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty weightMsgCancelProposal, SimulateMsgCancelProposal(ak, bk, k), ), - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, k), - ), } return append(wProposalOps, wGovOps...) } -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 - } -} - // SimulateMsgSubmitProposal simulates creating a msg Submit Proposal // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. -func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, contentSim simtypes.ContentSimulatorFn) simtypes.Operation { +func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, msgSim simtypes.MsgSimulatorFn) simtypes.Operation { // The states are: // column 1: All validators vote // column 2: 90% vote @@ -165,15 +144,12 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k curNumVotesState := 1 return func( - r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, - accs []simtypes.Account, chainID string, + r *rand.Rand, + app *baseapp.BaseApp, + ctx sdk.Context, + accs []simtypes.Account, + chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { - // 1) submit proposal now - content := contentSim(r, ctx, accs) - if content == nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "content is nil"), nil, nil - } - simAccount, _ := simtypes.RandomAcc(r, accs) deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true) switch { @@ -183,14 +159,21 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "unable to generate deposit"), nil, err } - macc := k.GetGovernanceAccount(ctx) - contentMsg, err := v1.NewLegacyContent(content, macc.GetAddress().String()) - if err != nil { - return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "error converting legacy content into proposal message"), nil, err + msgs := []sdk.Msg{} + proposalMsg := msgSim(r, ctx, accs) + if proposalMsg != nil { + msgs = append(msgs, proposalMsg) } - msg, err := v1.NewMsgSubmitProposal([]sdk.Msg{contentMsg}, deposit, simAccount.Address.String(), "", "Title of proposal", "Short description of proposal") - if err != nil { + msg, err := v1.NewMsgSubmitProposal( + msgs, + deposit, + simAccount.Address.String(), + simtypes.RandStringOfLength(r, 100), + simtypes.RandStringOfLength(r, 100), + simtypes.RandStringOfLength(r, 100), + ) + if err != nil || msg.ValidateBasic() != nil { return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err } diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 32cdc02ca246..95ac325db39d 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -10,7 +10,6 @@ import ( abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" "github.com/cosmos/cosmos-sdk/testutil/configurator" simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims" @@ -36,34 +35,31 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) -type MockWeightedProposalContent struct { +type MockWeightedProposalMsg struct { n int } -func (m MockWeightedProposalContent) AppParamsKey() string { +func (m MockWeightedProposalMsg) AppParamsKey() string { return fmt.Sprintf("AppParamsKey-%d", m.n) } -func (m MockWeightedProposalContent) DefaultWeight() int { +func (m MockWeightedProposalMsg) DefaultWeight() int { return m.n } -func (m MockWeightedProposalContent) ContentSimulatorFn() simtypes.ContentSimulatorFn { - return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { - return v1beta1.NewTextProposal( - fmt.Sprintf("title-%d: %s", m.n, simtypes.RandStringOfLength(r, 100)), - fmt.Sprintf("description-%d: %s", m.n, simtypes.RandStringOfLength(r, 4000)), - ) +func (m MockWeightedProposalMsg) MsgSimulatorFn() simtypes.MsgSimulatorFn { + return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + return nil } } -// make sure the MockWeightedProposalContent satisfied the WeightedProposalContent interface -var _ simtypes.WeightedProposalContent = MockWeightedProposalContent{} +// make sure the MockWeightedProposalMsg satisfies the WeightedProposalMsg interface +var _ simtypes.WeightedProposalMsg = MockWeightedProposalMsg{} -func mockWeightedProposalContent(n int) []simtypes.WeightedProposalContent { - wpc := make([]simtypes.WeightedProposalContent, n) +func mockWeightedProposalMsg(n int) []simtypes.WeightedProposalMsg { + wpc := make([]simtypes.WeightedProposalMsg, n) for i := 0; i < n; i++ { - wpc[i] = MockWeightedProposalContent{i} + wpc[i] = MockWeightedProposalMsg{i} } return wpc } @@ -73,12 +69,10 @@ func TestWeightedOperations(t *testing.T) { suite, ctx := createTestSuite(t, false) app := suite.App ctx.WithChainID("test-chain") - - cdc := suite.cdc appParams := make(simtypes.AppParams) - weightesOps := simulation.WeightedOperations(appParams, cdc, suite.AccountKeeper, - suite.BankKeeper, suite.GovKeeper, mockWeightedProposalContent(3), + weightesOps := simulation.WeightedOperations(appParams, govcodec.ModuleCdc, suite.AccountKeeper, + suite.BankKeeper, suite.GovKeeper, mockWeightedProposalMsg(3), ) // setup 3 accounts @@ -128,7 +122,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgSubmitProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposalContent{3}.ContentSimulatorFn()) + op := simulation.SimulateMsgSubmitProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposalMsg{3}.MsgSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -137,11 +131,9 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.NoError(t, err) require.True(t, operationMsg.OK) - require.Equal(t, "cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.Proposer) + require.Equal(t, "cosmos1ghekyjucln7y67ntx7cf27m9dpuxxemn4c8g4r", msg.Proposer) require.NotEqual(t, len(msg.InitialDeposit), 0) - require.Equal(t, "2686011stake", msg.InitialDeposit[0].String()) - require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) - require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) + require.Equal(t, "560969stake", msg.InitialDeposit[0].String()) require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) } @@ -323,7 +315,6 @@ func TestSimulateMsgVoteWeighted(t *testing.T) { } type suite struct { - cdc codec.Codec AccountKeeper authkeeper.AccountKeeper BankKeeper bankkeeper.Keeper GovKeeper *keeper.Keeper @@ -345,7 +336,7 @@ func createTestSuite(t *testing.T, isCheckTx bool) (suite, sdk.Context) { configurator.ConsensusModule(), configurator.DistributionModule(), configurator.GovModule(), - ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper, &res.cdc) + ), &res.AccountKeeper, &res.BankKeeper, &res.GovKeeper, &res.StakingKeeper, &res.DistributionKeeper) require.NoError(t, err) ctx := app.BaseApp.NewContext(isCheckTx, tmproto.Header{}) diff --git a/x/gov/simulation/proposals.go b/x/gov/simulation/proposals.go index 9a7bfdf21256..e723962bff3d 100644 --- a/x/gov/simulation/proposals.go +++ b/x/gov/simulation/proposals.go @@ -5,28 +5,25 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" - "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/simulation" ) // OpWeightSubmitTextProposal app params key for text proposal const OpWeightSubmitTextProposal = "op_weight_submit_text_proposal" -// ProposalContents defines the module weighted proposals' contents -func ProposalContents() []simtypes.WeightedProposalContent { - return []simtypes.WeightedProposalContent{ - simulation.NewWeightedProposalContent( - OpWeightMsgDeposit, +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightSubmitTextProposal, DefaultWeightTextProposal, - SimulateTextProposalContent, + SimulateTextProposal, ), } } -// SimulateTextProposalContent returns a random text proposal content. -func SimulateTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { - return v1beta1.NewTextProposal( - simtypes.RandStringOfLength(r, 140), - simtypes.RandStringOfLength(r, 5000), - ) +// SimulateTextProposal returns a random text proposal content. +// A text proposal is a proposal that contains no msgs. +func SimulateTextProposal(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + return nil } diff --git a/x/gov/simulation/proposals_test.go b/x/gov/simulation/proposals_test.go index f3c4b61ff626..72859748a071 100644 --- a/x/gov/simulation/proposals_test.go +++ b/x/gov/simulation/proposals_test.go @@ -12,7 +12,7 @@ import ( "github.com/cosmos/cosmos-sdk/x/gov/simulation" ) -func TestProposalContents(t *testing.T) { +func TestProposalMsgs(t *testing.T) { // initialize parameters s := rand.NewSource(1) r := rand.New(s) @@ -20,20 +20,16 @@ func TestProposalContents(t *testing.T) { ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) accounts := simtypes.RandomAccounts(r, 3) - // execute ProposalContents function - weightedProposalContent := simulation.ProposalContents() - require.Len(t, weightedProposalContent, 1) + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + require.Len(t, weightedProposalMsgs, 1) - w0 := weightedProposalContent[0] + w0 := weightedProposalMsgs[0] // tests w0 interface: - require.Equal(t, simulation.OpWeightMsgDeposit, w0.AppParamsKey()) + require.Equal(t, simulation.OpWeightSubmitTextProposal, w0.AppParamsKey()) require.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight()) - content := w0.ContentSimulatorFn()(r, ctx, accounts) - - require.Equal(t, "NxImpptHBIFDQfnxaTiOBJUgNzvqHbVcVJYlIFWFlzFqqRTTyFzDUMntPzyRamUFqeJAEaSHIuUHZoTWDjWXsYxYvwXwXZEsjRQKgKMselyUqWXMbHzRNDHnMzhWSirUgVggjiBxtWDfhzPDgrorEoNmDEiDdBldYegphCBTYWrmFFXNjxhtygsGBFHTejaKjMsqNdikEzDalEyWRHfJhKqifCKsedVuuJbQMbmRVuIPDluAWGpngjgBjOxuRFwSadayHNIhVVmNWBbfaTOldclxTTLUMvaBnLfwjHTtsKetEIvgrxLijhKJNablmvqpWIWsmhWQAYNLycREypoASHnyKWrxpoNLBJuyCGysZJgXbQAAmSIbGxMFXuwMVGZgBiZWfPWorAfjBeekCFvljHAtVZaTOsRxbPIioNxLTnWUTzGTvaNhplQQPmMADRRDuUIsiBpnGqPheKmLnopieVseFdTSAvOCacxaqFWFuXzsrVZzlGfeRpClwKuGEBujaPrzSLjVIOMvLlWxuznEOXlxbZroBRVEvEfBBAHOECribZNrYiFnzQqQmBnLksmFNAadusWAGltuqYNntgOlgOGwSdDjWdLboWyAWIcCfmpGJTfbljKPriLehwObuszICkaXNUkmeddeeRulbZBXJVLgteiKIfofGdNBregwUPlINQECatDSNXSIuefyMxxoKfcmjHEwbVtFiXtEnLJkLHUghmzFiymrgBChucZgOQUpGGVQEpRtIQjIBxYhtZPgUORdxXNWUMErWrUeriqYJPcgIDgLMWAyuuQnsHncCtjvHmvFbzYErxeunQllYDUVlXaRBveRUKeXwEGJFTSAqZtaBSDGDtzlADCnGjuTmYMJlapRsWfugmjwKEuoXJVpZvlcHeFvVvRRktRVGwzLfKezPEMABZtbLExQIjynSoahmkmoTHefdzFoBHMcQHFkKVHhpNtudPqJrYuQswzFuFHbSmpNltFnYJpvMrAYHFrNouZaanEUGHvbHIUUFTCtZrcpRHwgjblxlDNJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjf", content.GetDescription()) - require.Equal(t, "XhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeHVIkPZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", content.GetTitle()) - require.Equal(t, "gov", content.ProposalRoute()) - require.Equal(t, "Text", content.ProposalType()) + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + require.Nil(t, msg) } diff --git a/x/group/module/module.go b/x/group/module/module.go index 3543536ff7f5..c975b8c98bc1 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -172,9 +172,8 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents returns all the group content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs doesn't return any msg functions for governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/mint/module.go b/x/mint/module.go index f31eef38f3d5..9e2fb241248c 100644 --- a/x/mint/module.go +++ b/x/mint/module.go @@ -190,9 +190,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for mint module's types. diff --git a/x/mint/simulation/operations.go b/x/mint/simulation/operations.go deleted file mode 100644 index 310a94f02f7f..000000000000 --- a/x/mint/simulation/operations.go +++ /dev/null @@ -1,50 +0,0 @@ -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/mint/keeper" - "github.com/cosmos/cosmos-sdk/x/mint/types" - "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" -) - -// WeightedOperations returns all the operations from the module with their respective weights -func WeightedOperations( - appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, k *keeper.Keeper, -) simulation.WeightedOperations { - var weightMsgUpdateParams int - - appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, - func(_ *rand.Rand) { - weightMsgUpdateParams = DefaultWeightMsgUpdateParams - }, - ) - - return simulation.WeightedOperations{ - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, k), - ), - } -} - -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 - } -} diff --git a/x/mint/simulation/operations_test.go b/x/mint/simulation/operations_test.go deleted file mode 100644 index 5c6452f9a069..000000000000 --- a/x/mint/simulation/operations_test.go +++ /dev/null @@ -1 +0,0 @@ -package simulation_test diff --git a/x/mint/simulation/proposals.go b/x/mint/simulation/proposals.go new file mode 100644 index 000000000000..82878a80c62b --- /dev/null +++ b/x/mint/simulation/proposals.go @@ -0,0 +1,50 @@ +package simulation + +import ( + "math/rand" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/mint/types" + "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" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.BlocksPerYear = uint64(simtypes.RandIntBetween(r, 1, 1000000)) + params.GoalBonded = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) + params.InflationMin = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 50)), 2) + params.InflationMax = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 50, 100)), 2) + params.InflationRateChange = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) + params.MintDenom = simtypes.RandStringOfLength(r, 10) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/mint/simulation/proposals_test.go b/x/mint/simulation/proposals_test.go new file mode 100644 index 000000000000..eb14b31ad5b9 --- /dev/null +++ b/x/mint/simulation/proposals_test.go @@ -0,0 +1,46 @@ +package simulation_test + +import ( + "math/rand" + "testing" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/mint/simulation" + "github.com/cosmos/cosmos-sdk/x/mint/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.Equal(t, uint64(122877), msgUpdateParams.Params.BlocksPerYear) + assert.DeepEqual(t, sdk.NewDecWithPrec(95, 2), msgUpdateParams.Params.GoalBonded) + assert.DeepEqual(t, sdk.NewDecWithPrec(94, 2), msgUpdateParams.Params.InflationMax) + assert.DeepEqual(t, sdk.NewDecWithPrec(23, 2), msgUpdateParams.Params.InflationMin) + assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.InflationRateChange) + assert.Equal(t, "XhhuTSkuxK", msgUpdateParams.Params.MintDenom) +} diff --git a/x/params/module.go b/x/params/module.go index c885da447263..397bebbf2531 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -113,9 +113,8 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper) } -// ProposalContents returns all the params content functions used to -// simulate governance proposals. -func (am AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +// ProposalMsgs doesn't return any msg functions for governance proposals. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return nil } diff --git a/x/simulation/params.go b/x/simulation/params.go index 00f58fb59e7b..c37010abf2b1 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -121,33 +121,32 @@ func NewSimLegacyParamChange(subspace, key string, simVal simulation.SimValFn) s } } -// Proposal Contents +// Proposal Msgs -// WeightedProposalContent defines a common struct for proposal contents defined by -// external modules (i.e outside gov) -type WeightedProposalContent struct { - appParamsKey string // key used to retrieve the value of the weight from the simulation application params - defaultWeight int // default weight - contentSimulatorFn simulation.ContentSimulatorFn // content simulator function +// WeightedProposalMsg defines a common struct for proposal msgs defined by external modules (i.e outside gov) +type WeightedProposalMsg struct { + appParamsKey string // key used to retrieve the value of the weight from the simulation application params + defaultWeight int // default weight + msgSimulatorFn simulation.MsgSimulatorFn // msg simulator function } -func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { - return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} +func NewWeightedProposalMsg(appParamsKey string, defaultWeight int, msgSimulatorFn simulation.MsgSimulatorFn) simulation.WeightedProposalMsg { + return &WeightedProposalMsg{appParamsKey: appParamsKey, defaultWeight: defaultWeight, msgSimulatorFn: msgSimulatorFn} } -func (w WeightedProposalContent) AppParamsKey() string { +func (w WeightedProposalMsg) AppParamsKey() string { return w.appParamsKey } -func (w WeightedProposalContent) DefaultWeight() int { +func (w WeightedProposalMsg) DefaultWeight() int { return w.defaultWeight } -func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { - return w.contentSimulatorFn +func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFn { + return w.msgSimulatorFn } -// Param change proposals +// Consensus Params // randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state. func randomConsensusParams(r *rand.Rand, appState json.RawMessage, cdc codec.JSONCodec) *tmproto.ConsensusParams { diff --git a/x/slashing/module.go b/x/slashing/module.go index 877c88f9f917..0709c0b2ce55 100644 --- a/x/slashing/module.go +++ b/x/slashing/module.go @@ -181,9 +181,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for slashing module's types diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 84f915f519a7..5021c5f0cafb 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -21,11 +21,9 @@ import ( // //nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgUnjail = "op_weight_msg_unjail" - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUnjail = "op_weight_msg_unjail" - DefaultWeightMsgUnjail = 100 - DefaultWeightMsgUpdateParams int = 100 + DefaultWeightMsgUnjail = 100 ) // WeightedOperations returns all the operations from the module with their respective weights @@ -42,22 +40,11 @@ func WeightedOperations( }, ) - var weightMsgUpdateParams int - appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, - func(_ *rand.Rand) { - weightMsgUpdateParams = DefaultWeightMsgUpdateParams - }, - ) - return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgUnjail, SimulateMsgUnjail(codec.NewProtoCodec(interfaceRegistry), ak, bk, k, sk), ), - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, k), - ), } } @@ -155,11 +142,3 @@ func SimulateMsgUnjail(cdc *codec.ProtoCodec, ak types.AccountKeeper, bk types.B return simtypes.NewOperationMsg(msg, true, "", nil), nil, nil } } - -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 - } -} diff --git a/x/slashing/simulation/proposals.go b/x/slashing/simulation/proposals.go new file mode 100644 index 000000000000..03c2e09d8764 --- /dev/null +++ b/x/slashing/simulation/proposals.go @@ -0,0 +1,50 @@ +package simulation + +import ( + "math/rand" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +// Simulation operation weights constants +// +//nolint:gosec // these are not hardcoded credentials. +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.DowntimeJailDuration = time.Duration(simtypes.RandTimestamp(r).UnixNano()) + params.SignedBlocksWindow = int64(simtypes.RandIntBetween(r, 1, 1000)) + params.MinSignedPerWindow = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) + params.SlashFractionDoubleSign = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) + params.SlashFractionDowntime = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 1, 100)), 2) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/slashing/simulation/proposals_test.go b/x/slashing/simulation/proposals_test.go new file mode 100644 index 000000000000..ddf1b87a87d6 --- /dev/null +++ b/x/slashing/simulation/proposals_test.go @@ -0,0 +1,46 @@ +package simulation_test + +import ( + "math/rand" + "testing" + "time" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/simulation" + "github.com/cosmos/cosmos-sdk/x/slashing/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.Equal(t, int64(905), msgUpdateParams.Params.SignedBlocksWindow) + assert.DeepEqual(t, sdk.NewDecWithPrec(7, 2), msgUpdateParams.Params.MinSignedPerWindow) + assert.DeepEqual(t, sdk.NewDecWithPrec(60, 2), msgUpdateParams.Params.SlashFractionDoubleSign) + assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.SlashFractionDowntime) + assert.Equal(t, time.Duration(3313479009*time.Second), msgUpdateParams.Params.DowntimeJailDuration) +} diff --git a/x/staking/module.go b/x/staking/module.go index 682b0423505a..9fdf957eef17 100644 --- a/x/staking/module.go +++ b/x/staking/module.go @@ -288,9 +288,9 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalContents doesn't return any content functions for governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { - return nil +// ProposalMsgs returns msgs used for governance proposals for simulations. +func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { + return simulation.ProposalMsgs() } // RegisterStoreDecoder registers a decoder for staking module's types diff --git a/x/staking/simulation/operations.go b/x/staking/simulation/operations.go index e6a2e89c772c..18794553b037 100644 --- a/x/staking/simulation/operations.go +++ b/x/staking/simulation/operations.go @@ -26,7 +26,6 @@ const ( DefaultWeightMsgUndelegate int = 100 DefaultWeightMsgBeginRedelegate int = 100 DefaultWeightMsgCancelUnbondingDelegation int = 100 - DefaultWeightMsgUpdateParams int = 100 OpWeightMsgCreateValidator = "op_weight_msg_create_validator" OpWeightMsgEditValidator = "op_weight_msg_edit_validator" @@ -34,7 +33,6 @@ const ( OpWeightMsgUndelegate = "op_weight_msg_undelegate" OpWeightMsgBeginRedelegate = "op_weight_msg_begin_redelegate" OpWeightMsgCancelUnbondingDelegation = "op_weight_msg_cancel_unbonding_delegation" - OpWeightMsgUpdateParams = "op_weight_msg_update_params" ) // WeightedOperations returns all the operations from the module with their respective weights @@ -49,7 +47,6 @@ func WeightedOperations( weightMsgUndelegate int weightMsgBeginRedelegate int weightMsgCancelUnbondingDelegation int - weightMsgUpdateParams int ) appParams.GetOrGenerate(cdc, OpWeightMsgCreateValidator, &weightMsgCreateValidator, nil, @@ -88,10 +85,6 @@ func WeightedOperations( }, ) - appParams.GetOrGenerate(cdc, OpWeightMsgUpdateParams, &weightMsgUpdateParams, nil, func(r *rand.Rand) { - weightMsgUpdateParams = DefaultWeightMsgUpdateParams - }) - return simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgCreateValidator, @@ -117,10 +110,6 @@ func WeightedOperations( weightMsgCancelUnbondingDelegation, SimulateMsgCancelUnbondingDelegate(ak, bk, k), ), - simulation.NewWeightedOperation( - weightMsgUpdateParams, - SimulateMsgUpdateParams(ak, k), - ), } } @@ -590,11 +579,3 @@ func SimulateMsgBeginRedelegate(ak types.AccountKeeper, bk types.BankKeeper, k * return simulation.GenAndDeliverTxWithRandFees(txCtx) } } - -func SimulateMsgUpdateParams(ak types.AccountKeeper, sk *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 - } -} diff --git a/x/staking/simulation/proposals.go b/x/staking/simulation/proposals.go new file mode 100644 index 000000000000..708602565daf --- /dev/null +++ b/x/staking/simulation/proposals.go @@ -0,0 +1,51 @@ +package simulation + +import ( + "math/rand" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/simulation" + "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +// Simulation operation weights constants +// +//nolint:gosec // these are not hardcoded credentials. +const ( + DefaultWeightMsgUpdateParams int = 100 + + OpWeightMsgUpdateParams = "op_weight_msg_update_params" +) + +// ProposalMsgs defines the module weighted proposals' contents +func ProposalMsgs() []simtypes.WeightedProposalMsg { + return []simtypes.WeightedProposalMsg{ + simulation.NewWeightedProposalMsg( + OpWeightMsgUpdateParams, + DefaultWeightMsgUpdateParams, + SimulateMsgUpdateParams, + ), + } +} + +// SimulateMsgUpdateParams returns a random MsgUpdateParams +func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { + // use the default gov module account address as authority + var authority sdk.AccAddress = address.Module("gov") + + params := types.DefaultParams() + params.BondDenom = simtypes.RandStringOfLength(r, 10) + params.HistoricalEntries = uint32(simtypes.RandIntBetween(r, 0, 1000)) + params.MaxEntries = uint32(simtypes.RandIntBetween(r, 0, 1000)) + params.MaxValidators = uint32(simtypes.RandIntBetween(r, 0, 1000)) + params.UnbondingTime = time.Duration(simtypes.RandTimestamp(r).UnixNano()) + params.MinCommissionRate = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 0, 1000)), 2) + + return &types.MsgUpdateParams{ + Authority: authority.String(), + Params: params, + } +} diff --git a/x/staking/simulation/proposals_test.go b/x/staking/simulation/proposals_test.go new file mode 100644 index 000000000000..f17f77c3fcc9 --- /dev/null +++ b/x/staking/simulation/proposals_test.go @@ -0,0 +1,47 @@ +package simulation_test + +import ( + "math/rand" + "testing" + "time" + + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/types/address" + simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/staking/simulation" + "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +func TestProposalMsgs(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalMsgs function + weightedProposalMsgs := simulation.ProposalMsgs() + assert.Assert(t, len(weightedProposalMsgs) == 1) + + w0 := weightedProposalMsgs[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgUpdateParams, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightMsgUpdateParams, w0.DefaultWeight()) + + msg := w0.MsgSimulatorFn()(r, ctx, accounts) + msgUpdateParams, ok := msg.(*types.MsgUpdateParams) + assert.Assert(t, ok) + + assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) + assert.Equal(t, "GqiQWIXnku", msgUpdateParams.Params.BondDenom) + assert.Equal(t, uint32(694), msgUpdateParams.Params.MaxEntries) + assert.Equal(t, uint32(300), msgUpdateParams.Params.HistoricalEntries) + assert.Equal(t, uint32(511), msgUpdateParams.Params.MaxValidators) + assert.Equal(t, time.Duration(8898194435*time.Second), msgUpdateParams.Params.UnbondingTime) + assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.MinCommissionRate) +} From 1c62f8291ed14d263e2a9f75936639330339eab3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 15:19:15 +0100 Subject: [PATCH 20/32] updates --- x/bank/simulation/operations_test.go | 1 - x/staking/simulation/operations_test.go | 1 - 2 files changed, 2 deletions(-) diff --git a/x/bank/simulation/operations_test.go b/x/bank/simulation/operations_test.go index 5bfec9c70e62..0988c8d1c42b 100644 --- a/x/bank/simulation/operations_test.go +++ b/x/bank/simulation/operations_test.go @@ -74,7 +74,6 @@ func (suite *SimTestSuite) TestWeightedOperations() { }{ {100, types.ModuleName, sdk.MsgTypeURL(&types.MsgSend{})}, {10, types.ModuleName, sdk.MsgTypeURL(&types.MsgMultiSend{})}, - {5, types.ModuleName, sdk.MsgTypeURL(&types.MsgUpdateParams{})}, } for i, w := range weightesOps { diff --git a/x/staking/simulation/operations_test.go b/x/staking/simulation/operations_test.go index 55f9391809ea..d3f11642eae1 100644 --- a/x/staking/simulation/operations_test.go +++ b/x/staking/simulation/operations_test.go @@ -137,7 +137,6 @@ func (s *SimTestSuite) TestWeightedOperations() { {simulation.DefaultWeightMsgUndelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgUndelegate{})}, {simulation.DefaultWeightMsgBeginRedelegate, types.ModuleName, sdk.MsgTypeURL(&types.MsgBeginRedelegate{})}, {simulation.DefaultWeightMsgCancelUnbondingDelegation, types.ModuleName, sdk.MsgTypeURL(&types.MsgCancelUnbondingDelegation{})}, - {simulation.DefaultWeightMsgUpdateParams, types.ModuleName, sdk.MsgTypeURL(&types.MsgUpdateParams{})}, } for i, w := range weightesOps { From ce74425993a5d0d6d3de1c74d332fe132366b761 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 15:34:02 +0100 Subject: [PATCH 21/32] support legacy --- UPGRADING.md | 4 ++- testutil/sims/simulation_helpers.go | 1 + types/module/simulation.go | 56 +++++++++++++++++++++-------- types/simulation/types.go | 38 ++++++++++---------- x/authz/module/module.go | 5 --- x/bank/simulation/operations.go | 1 - x/capability/module.go | 5 --- x/evidence/module.go | 5 --- x/feegrant/module/module.go | 5 --- x/gov/module.go | 6 ++++ x/gov/simulation/proposals.go | 20 +++++++++++ x/gov/simulation/proposals_test.go | 36 ++++++++++++++++--- x/group/module/module.go | 5 --- x/params/module.go | 5 --- x/simulation/params.go | 25 +++++++++++++ 15 files changed, 146 insertions(+), 71 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 2a2d1bc06cc8..03a602de507b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -94,7 +94,9 @@ All the feegrant imports are now renamed to use `cosmossdk.io/x/feegrant` instea Remove `RandomizedParams` from `AppModuleSimulation` interface. Previously, it used to generate random parameter changes during simulations, however, it does so through ParamChangeProposal which is now legacy. Since all modules were migrated, we can now safely remove this from `AppModuleSimulation` interface. -Moreover, to support the `MsgUpdateParams` governance proposals for each modules, `AppModuleSimulation` now defines a `ProposalMsgs` method instead of `ProposalContents`. That method defines the messages that can be used to submit a proposal and that should be tested in simulation. +Moreover, to support the `MsgUpdateParams` governance proposals for each modules, `AppModuleSimulation` now defines a `AppModule.ProposalMsgs` method in addition to `AppModule.ProposalContents`. That method defines the messages that can be used to submit a proposal and that should be tested in simulation. + +When a module has no proposal messages or proposal content to be tested by simulation, the `AppModule.ProposalMsgs` and `AppModule.ProposalContents` methods be deleted. ### gRPC diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index f1f1d070bfdf..12c2697cb97c 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -68,6 +68,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } + simState.ProposalContents = app.SimulationManager().GetProposalContents(simState) simState.ProposalMsg = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 3d52f9f5c4b9..fcea2e7dbcb7 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -17,9 +17,6 @@ type AppModuleSimulation interface { // randomized genesis states GenerateGenesisState(input *SimulationState) - // msg functions used to simulate governance proposals - ProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg - // register a func to decode the each module's defined types from their corresponding store key RegisterStoreDecoder(simulation.StoreDecoderRegistry) @@ -27,6 +24,18 @@ type AppModuleSimulation interface { WeightedOperations(simState SimulationState) []simulation.WeightedOperation } +// HasProposalMsgs defines the messages that can be used to simulate governance (v1) proposals +type HasProposalMsgs interface { + // msg functions used to simulate governance proposals + ProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg +} + +// HasProposalContents defines the contents that can be used to simulate legacy governance (v1beta1) proposals +type HasProposalContents interface { + // content functions used to simulate governance proposals + ProposalContents(simState SimulationState) []simulation.WeightedProposalContent +} + // SimulationManager defines a simulation manager that provides the high level utility // for managing and executing simulation functionalities for a group of modules type SimulationManager struct { @@ -76,12 +85,28 @@ func NewSimulationManagerFromAppModules(modules map[string]interface{}, override return NewSimulationManager(simModules...) } +// Deprecated: Use GetProposalMsgs instead. +// GetProposalContents returns each module's proposal content generator function +// with their default operation weight and key. +func (sm *SimulationManager) GetProposalContents(simState SimulationState) []simulation.WeightedProposalContent { + wContents := make([]simulation.WeightedProposalContent, 0, len(sm.Modules)) + for _, module := range sm.Modules { + if module, ok := module.(HasProposalContents); ok { + wContents = append(wContents, module.ProposalContents(simState)...) + } + } + + return wContents +} + // GetProposalMsgs returns each module's proposal msg generator function // with their default operation weight and key. func (sm *SimulationManager) GetProposalMsgs(simState SimulationState) []simulation.WeightedProposalMsg { wContents := make([]simulation.WeightedProposalMsg, 0, len(sm.Modules)) for _, module := range sm.Modules { - wContents = append(wContents, module.ProposalMsgs(simState)...) + if module, ok := module.(HasProposalMsgs); ok { + wContents = append(wContents, module.ProposalMsgs(simState)...) + } } return wContents @@ -116,15 +141,16 @@ func (sm *SimulationManager) WeightedOperations(simState SimulationState) []simu // 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 - LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - ProposalMsg []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key + 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 + ProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck + ProposalMsg []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/types/simulation/types.go b/types/simulation/types.go index 25b6dee46dcd..34d29d04e323 100644 --- a/types/simulation/types.go +++ b/types/simulation/types.go @@ -12,25 +12,25 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/migrations/legacytx" ) -// // Deprecated: Use WeightedProposalMsg instead. -// type WeightedProposalContent interface { -// AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params -// DefaultWeight() int // default weight -// ContentSimulatorFn() ContentSimulatorFn // content simulator function -// } - -// // Deprecated: Use MsgSimulatorFn instead. -// type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content - -// // Deprecated: Use MsgSimulatorFn instead. -// type Content interface { -// GetTitle() string -// GetDescription() string -// ProposalRoute() string -// ProposalType() string -// ValidateBasic() error -// String() string -// } +// Deprecated: Use WeightedProposalMsg instead. +type WeightedProposalContent interface { + AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params + DefaultWeight() int // default weight + ContentSimulatorFn() ContentSimulatorFn // content simulator function +} + +// Deprecated: Use MsgSimulatorFn instead. +type ContentSimulatorFn func(r *rand.Rand, ctx sdk.Context, accs []Account) Content + +// Deprecated: Use MsgSimulatorFn instead. +type Content interface { + GetTitle() string + GetDescription() string + ProposalRoute() string + ProposalType() string + ValidateBasic() error + String() string +} type WeightedProposalMsg interface { AppParamsKey() string // key used to retrieve the value of the weight from the simulation application params diff --git a/x/authz/module/module.go b/x/authz/module/module.go index 5c6d310faf1e..5934aae60414 100644 --- a/x/authz/module/module.go +++ b/x/authz/module/module.go @@ -207,11 +207,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalMsgs returns all the authz msgs functions used to simulate governance proposals. -func (am AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder registers a decoder for authz module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[keeper.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 0ad0972c5d15..25aa67759269 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -31,7 +31,6 @@ func WeightedOperations( appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk keeper.Keeper, ) simulation.WeightedOperations { var weightMsgSend, weightMsgMultiSend int - appParams.GetOrGenerate(cdc, OpWeightMsgSend, &weightMsgSend, nil, func(_ *rand.Rand) { weightMsgSend = DefaultWeightMsgSend diff --git a/x/capability/module.go b/x/capability/module.go index 2f2b49268096..a704da4f4651 100644 --- a/x/capability/module.go +++ b/x/capability/module.go @@ -163,11 +163,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalMsgs doesn't return any msg functions for governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder registers a decoder for capability module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/evidence/module.go b/x/evidence/module.go index a488cc6dc380..65e964f015ab 100644 --- a/x/evidence/module.go +++ b/x/evidence/module.go @@ -177,11 +177,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalMsgs doesn't return any msg functions for governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder registers a decoder for evidence module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[types.StoreKey] = simulation.NewDecodeStore(am.keeper) diff --git a/x/feegrant/module/module.go b/x/feegrant/module/module.go index 1f9b3106783d..1fb8b3138205 100644 --- a/x/feegrant/module/module.go +++ b/x/feegrant/module/module.go @@ -208,11 +208,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalMsgs doesn't return any msg functions for governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder registers a decoder for feegrant module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[feegrant.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/gov/module.go b/x/gov/module.go index 441457b93813..227ce59c50fd 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -332,6 +332,12 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } +// ProposalContents returns all the gov content functions used to +// simulate governance proposals. +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { + return simulation.ProposalContents() +} + // ProposalMsgs returns all the gov msgs used to simulate governance proposals. func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { return simulation.ProposalMsgs() diff --git a/x/gov/simulation/proposals.go b/x/gov/simulation/proposals.go index e723962bff3d..6217e5ffdd6e 100644 --- a/x/gov/simulation/proposals.go +++ b/x/gov/simulation/proposals.go @@ -5,6 +5,7 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" + "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1" "github.com/cosmos/cosmos-sdk/x/simulation" ) @@ -27,3 +28,22 @@ func ProposalMsgs() []simtypes.WeightedProposalMsg { func SimulateTextProposal(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { return nil } + +// ProposalContents defines the module weighted proposals' contents +func ProposalContents() []simtypes.WeightedProposalContent { + return []simtypes.WeightedProposalContent{ + simulation.NewWeightedProposalContent( + OpWeightMsgDeposit, + DefaultWeightTextProposal, + SimulateLegacyTextProposalContent, + ), + } +} + +// SimulateTextProposalContent returns a random text proposal content. +func SimulateLegacyTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { + return v1beta1.NewTextProposal( + simtypes.RandStringOfLength(r, 140), + simtypes.RandStringOfLength(r, 5000), + ) +} diff --git a/x/gov/simulation/proposals_test.go b/x/gov/simulation/proposals_test.go index 72859748a071..a90c72008121 100644 --- a/x/gov/simulation/proposals_test.go +++ b/x/gov/simulation/proposals_test.go @@ -4,8 +4,8 @@ import ( "math/rand" "testing" - "github.com/stretchr/testify/require" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + "gotest.tools/v3/assert" sdk "github.com/cosmos/cosmos-sdk/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -22,14 +22,40 @@ func TestProposalMsgs(t *testing.T) { // execute ProposalMsgs function weightedProposalMsgs := simulation.ProposalMsgs() - require.Len(t, weightedProposalMsgs, 1) + assert.Assert(t, len(weightedProposalMsgs) == 1) w0 := weightedProposalMsgs[0] // tests w0 interface: - require.Equal(t, simulation.OpWeightSubmitTextProposal, w0.AppParamsKey()) - require.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight()) + assert.Equal(t, simulation.OpWeightSubmitTextProposal, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight()) msg := w0.MsgSimulatorFn()(r, ctx, accounts) - require.Nil(t, msg) + assert.Assert(t, msg == nil) +} + +func TestProposalContents(t *testing.T) { + // initialize parameters + s := rand.NewSource(1) + r := rand.New(s) + + ctx := sdk.NewContext(nil, tmproto.Header{}, true, nil) + accounts := simtypes.RandomAccounts(r, 3) + + // execute ProposalContents function + weightedProposalContent := simulation.ProposalContents() + assert.Assert(t, len(weightedProposalContent) == 1) + + w0 := weightedProposalContent[0] + + // tests w0 interface: + assert.Equal(t, simulation.OpWeightMsgDeposit, w0.AppParamsKey()) + assert.Equal(t, simulation.DefaultWeightTextProposal, w0.DefaultWeight()) + + content := w0.ContentSimulatorFn()(r, ctx, accounts) + + assert.Equal(t, "NxImpptHBIFDQfnxaTiOBJUgNzvqHbVcVJYlIFWFlzFqqRTTyFzDUMntPzyRamUFqeJAEaSHIuUHZoTWDjWXsYxYvwXwXZEsjRQKgKMselyUqWXMbHzRNDHnMzhWSirUgVggjiBxtWDfhzPDgrorEoNmDEiDdBldYegphCBTYWrmFFXNjxhtygsGBFHTejaKjMsqNdikEzDalEyWRHfJhKqifCKsedVuuJbQMbmRVuIPDluAWGpngjgBjOxuRFwSadayHNIhVVmNWBbfaTOldclxTTLUMvaBnLfwjHTtsKetEIvgrxLijhKJNablmvqpWIWsmhWQAYNLycREypoASHnyKWrxpoNLBJuyCGysZJgXbQAAmSIbGxMFXuwMVGZgBiZWfPWorAfjBeekCFvljHAtVZaTOsRxbPIioNxLTnWUTzGTvaNhplQQPmMADRRDuUIsiBpnGqPheKmLnopieVseFdTSAvOCacxaqFWFuXzsrVZzlGfeRpClwKuGEBujaPrzSLjVIOMvLlWxuznEOXlxbZroBRVEvEfBBAHOECribZNrYiFnzQqQmBnLksmFNAadusWAGltuqYNntgOlgOGwSdDjWdLboWyAWIcCfmpGJTfbljKPriLehwObuszICkaXNUkmeddeeRulbZBXJVLgteiKIfofGdNBregwUPlINQECatDSNXSIuefyMxxoKfcmjHEwbVtFiXtEnLJkLHUghmzFiymrgBChucZgOQUpGGVQEpRtIQjIBxYhtZPgUORdxXNWUMErWrUeriqYJPcgIDgLMWAyuuQnsHncCtjvHmvFbzYErxeunQllYDUVlXaRBveRUKeXwEGJFTSAqZtaBSDGDtzlADCnGjuTmYMJlapRsWfugmjwKEuoXJVpZvlcHeFvVvRRktRVGwzLfKezPEMABZtbLExQIjynSoahmkmoTHefdzFoBHMcQHFkKVHhpNtudPqJrYuQswzFuFHbSmpNltFnYJpvMrAYHFrNouZaanEUGHvbHIUUFTCtZrcpRHwgjblxlDNJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjf", content.GetDescription()) + assert.Equal(t, "XhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeHVIkPZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", content.GetTitle()) + assert.Equal(t, "gov", content.ProposalRoute()) + assert.Equal(t, "Text", content.ProposalType()) } diff --git a/x/group/module/module.go b/x/group/module/module.go index 917151e88761..6595ae71876b 100644 --- a/x/group/module/module.go +++ b/x/group/module/module.go @@ -173,11 +173,6 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { simulation.RandomizedGenState(simState) } -// ProposalMsgs doesn't return any msg functions for governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder registers a decoder for group module's types func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { sdr[group.StoreKey] = simulation.NewDecodeStore(am.cdc) diff --git a/x/params/module.go b/x/params/module.go index 08132681cdba..400aeb09b5bd 100644 --- a/x/params/module.go +++ b/x/params/module.go @@ -114,11 +114,6 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { proposal.RegisterQueryServer(cfg.QueryServer(), am.keeper) } -// ProposalMsgs doesn't return any msg functions for governance proposals. -func (AppModule) ProposalMsgs(simState module.SimulationState) []simtypes.WeightedProposalMsg { - return nil -} - // RegisterStoreDecoder doesn't register any type. func (AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) {} diff --git a/x/simulation/params.go b/x/simulation/params.go index c37010abf2b1..2867244159fd 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -146,6 +146,31 @@ func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFn { return w.msgSimulatorFn } +// Legacy Proposal Content + +// WeightedProposalContent defines a common struct for proposal content defined by external modules (i.e outside gov) +type WeightedProposalContent struct { + appParamsKey string // key used to retrieve the value of the weight from the simulation application params + defaultWeight int // default weight + contentSimulatorFn simulation.ContentSimulatorFn // content simulator function +} + +func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { + return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} +} + +func (w WeightedProposalContent) AppParamsKey() string { + return w.appParamsKey +} + +func (w WeightedProposalContent) DefaultWeight() int { + return w.defaultWeight +} + +func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { + return w.contentSimulatorFn +} + // Consensus Params // randomConsensusParams returns random simulation consensus parameters, it extracts the Evidence from the Staking genesis state. From 4016ed5f6c880d26ad9984f19fe247b4f8bf71c3 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 16:10:04 +0100 Subject: [PATCH 22/32] updates --- CHANGELOG.md | 2 +- testutil/sims/simulation_helpers.go | 2 +- types/module/simulation.go | 26 +++--- x/gov/module.go | 3 +- x/gov/simulation/operations.go | 135 +++++++++++++++++++++------- x/gov/simulation/operations_test.go | 79 ++++++++++++++-- 6 files changed, 194 insertions(+), 53 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ebe05ed169d..46e37c6b46d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -167,7 +167,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` in simulation. +* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` and `Contents` to `LegacyProposalConents` in `simulation.SimulationState` * (x/gov) [#14782](https://github.com/cosmos/cosmos-sdk/pull/14782) Move the `metadata` argument in `govv1.NewProposal` alongside `title` and `summary`. * (store) [#14746](https://github.com/cosmos/cosmos-sdk/pull/14746) Extract Store in its own go.mod and rename the package to `cosmossdk.io/store`. * (simulation) [#14751](https://github.com/cosmos/cosmos-sdk/pull/14751) Remove the `MsgType` field from `simulation.OperationInput` struct. diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 12c2697cb97c..5c1ccfda8b72 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -68,7 +68,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - simState.ProposalContents = app.SimulationManager().GetProposalContents(simState) + simState.LegacyProposalConents = app.SimulationManager().GetProposalContents(simState) simState.ProposalMsg = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index fcea2e7dbcb7..7872badba7fd 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -140,17 +140,17 @@ 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 - LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - ProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck - ProposalMsg []simulation.WeightedProposalMsg // proposal msg 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 + LegacyProposalConents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck + ProposalMsg []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/x/gov/module.go b/x/gov/module.go index 227ce59c50fd..bbd461adee3a 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -352,6 +352,7 @@ func (am AppModule) RegisterStoreDecoder(sdr simtypes.StoreDecoderRegistry) { func (am AppModule) WeightedOperations(simState module.SimulationState) []simtypes.WeightedOperation { return simulation.WeightedOperations( simState.AppParams, simState.Cdc, - am.accountKeeper, am.bankKeeper, am.keeper, simState.ProposalMsg, + am.accountKeeper, am.bankKeeper, am.keeper, + simState.ProposalMsg, simState.LegacyProposalConents, ) } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 27dc7a497da5..b4902d56d8e7 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -46,7 +46,7 @@ const ( ) // 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, wMsgs []simtypes.WeightedProposalMsg) simulation.WeightedOperations { +func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, wMsgs []simtypes.WeightedProposalMsg, wContents []simtypes.WeightedProposalContent) simulation.WeightedOperations { var ( weightMsgDeposit int weightMsgVote int @@ -78,9 +78,8 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty }, ) - // generate the weighted operations for the proposal contents + // generate the weighted operations for the proposal msgs var wProposalOps simulation.WeightedOperations - for _, wMsg := range wMsgs { wMsg := wMsg // pin variable var weight int @@ -96,6 +95,22 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty ) } + var wLegacyProposalOps simulation.WeightedOperations + for _, wContent := range wContents { + wContent := wContent // pin variable + var weight int + appParams.GetOrGenerate(cdc, wContent.AppParamsKey(), &weight, nil, + func(_ *rand.Rand) { weight = wContent.DefaultWeight() }) + + wLegacyProposalOps = append( + wLegacyProposalOps, + simulation.NewWeightedOperation( + weight, + SimulateMsgSubmitLegacyProposal(ak, bk, k, wContent.ContentSimulatorFn()), + ), + ) + } + wGovOps := simulation.WeightedOperations{ simulation.NewWeightedOperation( weightMsgDeposit, @@ -115,34 +130,13 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty ), } - return append(wProposalOps, wGovOps...) + return append(wGovOps, append(wProposalOps, wLegacyProposalOps...)...) } // SimulateMsgSubmitProposal simulates creating a msg Submit Proposal // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, msgSim simtypes.MsgSimulatorFn) simtypes.Operation { - // The states are: - // column 1: All validators vote - // column 2: 90% vote - // column 3: 75% vote - // column 4: 40% vote - // column 5: 15% vote - // column 6: noone votes - // All columns sum to 100 for simplicity, values chosen by @valardragon semi-arbitrarily, - // feel free to change. - numVotesTransitionMatrix, _ := simulation.CreateTransitionMatrix([][]int{ - {20, 10, 0, 0, 0, 0}, - {55, 50, 20, 10, 0, 0}, - {25, 25, 30, 25, 30, 15}, - {0, 15, 30, 25, 30, 30}, - {0, 0, 20, 30, 30, 30}, - {0, 0, 0, 10, 10, 25}, - }) - - statePercentageArray := []float64{1, .9, .75, .4, .15, 0} - curNumVotesState := 1 - return func( r *rand.Rand, app *baseapp.BaseApp, @@ -177,15 +171,94 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err } + return simulateMsgSubmitProposal(ak, bk, k, msg, simAccount, deposit)(r, app, ctx, accs, chainID) + } +} + +// SimulateMsgSubmitLegacyProposal simulates creating a msg Submit Proposal +// voting on the proposal, and subsequently slashing the proposal. It is implemented using +// future operations. +func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, contentSim simtypes.ContentSimulatorFn) simtypes.Operation { + return func( + r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, + accs []simtypes.Account, chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + // 1) submit proposal now + content := contentSim(r, ctx, accs) + if content == nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "content is nil"), nil, nil + } + + simAccount, _ := simtypes.RandomAcc(r, accs) + deposit, skip, err := randomDeposit(r, ctx, ak, bk, k, simAccount.Address, true) + switch { + case skip: + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "skip deposit"), nil, nil + case err != nil: + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "unable to generate deposit"), nil, err + } + + macc := k.GetGovernanceAccount(ctx) + contentMsg, err := v1.NewLegacyContent(content, macc.GetAddress().String()) + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "error converting legacy content into proposal message"), nil, err + } + + msg, err := v1.NewMsgSubmitProposal([]sdk.Msg{contentMsg}, deposit, simAccount.Address.String(), "", "Title of proposal", "Short description of proposal") + if err != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err + } + + return simulateMsgSubmitProposal(ak, bk, k, msg, simAccount, deposit)(r, app, ctx, accs, chainID) + } +} + +func simulateMsgSubmitProposal( + ak types.AccountKeeper, + bk types.BankKeeper, + k *keeper.Keeper, + msgSubmitProposal sdk.Msg, + simAccount simtypes.Account, + deposit sdk.Coins, +) simtypes.Operation { + // The states are: + // column 1: All validators vote + // column 2: 90% vote + // column 3: 75% vote + // column 4: 40% vote + // column 5: 15% vote + // column 6: noone votes + // All columns sum to 100 for simplicity, values chosen by @valardragon semi-arbitrarily, + // feel free to change. + numVotesTransitionMatrix, _ := simulation.CreateTransitionMatrix([][]int{ + {20, 10, 0, 0, 0, 0}, + {55, 50, 20, 10, 0, 0}, + {25, 25, 30, 25, 30, 15}, + {0, 15, 30, 25, 30, 30}, + {0, 0, 20, 30, 30, 30}, + {0, 0, 0, 10, 10, 25}, + }) + + statePercentageArray := []float64{1, .9, .75, .4, .15, 0} + curNumVotesState := 1 + + return func( + r *rand.Rand, + app *baseapp.BaseApp, + ctx sdk.Context, + accs []simtypes.Account, + chainID string, + ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { account := ak.GetAccount(ctx, simAccount.Address) spendable := bk.SpendableCoins(ctx, account.GetAddress()) var fees sdk.Coins + var err error coins, hasNeg := spendable.SafeSub(deposit...) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate fees"), nil, err } } @@ -193,7 +266,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{msg}, + []sdk.Msg{msgSubmitProposal}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -202,20 +275,20 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate mock tx"), nil, err } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to deliver tx"), nil, err } - opMsg := simtypes.NewOperationMsg(msg, true, "", nil) + opMsg := simtypes.NewOperationMsg(msgSubmitProposal, true, "", nil) // get the submitted proposal ID proposalID, err := k.GetProposalID(ctx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate proposalID"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate proposalID"), nil, err } // 2) Schedule operations for votes diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 31156802c778..9b3324da2026 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -64,6 +64,38 @@ func mockWeightedProposalMsg(n int) []simtypes.WeightedProposalMsg { return wpc } +type MockWeightedLegacyProposalContent struct { + n int +} + +func (m MockWeightedLegacyProposalContent) AppParamsKey() string { + return fmt.Sprintf("AppParamsKey-%d", m.n) +} + +func (m MockWeightedLegacyProposalContent) DefaultWeight() int { + return m.n +} + +func (m MockWeightedLegacyProposalContent) ContentSimulatorFn() simtypes.ContentSimulatorFn { + return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { + return v1beta1.NewTextProposal( + fmt.Sprintf("title-%d: %s", m.n, simtypes.RandStringOfLength(r, 100)), + fmt.Sprintf("description-%d: %s", m.n, simtypes.RandStringOfLength(r, 4000)), + ) + } +} + +// make sure the MockWeightedProposalContent satisfied the WeightedProposalContent interface +var _ simtypes.WeightedProposalContent = MockWeightedLegacyProposalContent{} + +func mockWeightedLegacyProposalContent(n int) []simtypes.WeightedProposalContent { + wpc := make([]simtypes.WeightedProposalContent, n) + for i := 0; i < n; i++ { + wpc[i] = MockWeightedLegacyProposalContent{i} + } + return wpc +} + // TestWeightedOperations tests the weights of the operations. func TestWeightedOperations(t *testing.T) { suite, ctx := createTestSuite(t, false) @@ -72,7 +104,7 @@ func TestWeightedOperations(t *testing.T) { appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, govcodec.ModuleCdc, suite.AccountKeeper, - suite.BankKeeper, suite.GovKeeper, mockWeightedProposalMsg(3), + suite.BankKeeper, suite.GovKeeper, mockWeightedProposalMsg(3), mockWeightedLegacyProposalContent(3), ) // setup 3 accounts @@ -85,18 +117,21 @@ func TestWeightedOperations(t *testing.T) { opMsgRoute string opMsgName string }{ - {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, - {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, - {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, {simulation.DefaultWeightMsgDeposit, types.ModuleName, simulation.TypeMsgDeposit}, {simulation.DefaultWeightMsgVote, types.ModuleName, simulation.TypeMsgVote}, {simulation.DefaultWeightMsgVoteWeighted, types.ModuleName, simulation.TypeMsgVoteWeighted}, {simulation.DefaultWeightMsgCancelProposal, types.ModuleName, simulation.TypeMsgCancelProposal}, + {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, + {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, + {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, + {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, + {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, + {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, } for i, w := range weightesOps { - operationMsg, _, _ := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) - // require.NoError(t, err) // TODO check if it should be NoError + operationMsg, _, err := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + require.NoError(t, err) // the following checks are very much dependent from the ordering of the output given // by WeightedOperations. if the ordering in WeightedOperations changes some tests @@ -137,6 +172,38 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) } +// TestSimulateMsgSubmitProposal tests the normal scenario of a valid message of type TypeMsgSubmitProposal. +// Abnormal scenarios, where errors occur, are not tested here. +func TestSimulateMsgSubmitLegacyProposal(t *testing.T) { + suite, ctx := createTestSuite(t, false) + app := suite.App + + // setup 3 accounts + s := rand.NewSource(1) + r := rand.New(s) + accounts := getTestingAccounts(t, r, suite.AccountKeeper, suite.BankKeeper, suite.StakingKeeper, ctx, 3) + + // begin a new block + app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) + + // execute operation + op := simulation.SimulateMsgSubmitLegacyProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedLegacyProposalContent{3}.ContentSimulatorFn()) + operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") + require.NoError(t, err) + + var msg v1.MsgSubmitProposal + err = govcodec.ModuleCdc.UnmarshalJSON(operationMsg.Msg, &msg) + require.NoError(t, err) + + require.True(t, operationMsg.OK) + require.Equal(t, "cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.Proposer) + require.NotEqual(t, len(msg.InitialDeposit), 0) + require.Equal(t, "2686011stake", msg.InitialDeposit[0].String()) + require.Equal(t, "title-3: ZBSpYuLyYggwexjxusrBqDOTtGTOWeLrQKjLxzIivHSlcxgdXhhuTSkuxKGLwQvuyNhYFmBZHeAerqyNEUzXPFGkqEGqiQWIXnku", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetTitle()) + require.Equal(t, "description-3: NJWzHdBNpAXKJPHWQdrGYcAHSctgVlqwqHoLfHsXUdStwfefwzqLuKEhmMyYLdbZrcPgYqjNHxPexsruwEGStAneKbWkQDDIlCWBLSiAASNhZqNFlPtfqPJoxKsgMdzjWqLWdqKQuJqWPMvwPQWZUtVMOTMYKJbfdlZsjdsomuScvDmbDkgRualsxDvRJuCAmPOXitIbcyWsKGSdrEunFAOdmXnsuyFVgJqEjbklvmwrUlsxjRSfKZxGcpayDdgoFcnVSutxjRgOSFzPwidAjubMncNweqpbxhXGchpZUxuFDOtpnhNUycJICRYqsPhPSCjPTWZFLkstHWJxvdPEAyEIxXgLwbNOjrgzmaujiBABBIXvcXpLrbcEWNNQsbjvgJFgJkflpRohHUutvnaUqoopuKjTDaemDeSdqbnOzcfJpcTuAQtZoiLZOoAIlboFDAeGmSNwkvObPRvRWQgWkGkxwtPauYgdkmypLjbqhlHJIQTntgWjXwZdOyYEdQRRLfMSdnxqppqUofqLbLQDUjwKVKfZJUJQPsWIPwIVaSTrmKskoAhvmZyJgeRpkaTfGgrJzAigcxtfshmiDCFkuiluqtMOkidknnTBtumyJYlIsWLnCQclqdVmikUoMOPdPWwYbJxXyqUVicNxFxyqJTenNblyyKSdlCbiXxUiYUiMwXZASYfvMDPFgxniSjWaZTjHkqlJvtBsXqwPpyVxnJVGFWhfSxgOcduoxkiopJvFjMmFabrGYeVtTXLhxVUEiGwYUvndjFGzDVntUvibiyZhfMQdMhgsiuysLMiePBNXifRLMsSmXPkwlPloUbJveCvUlaalhZHuvdkCnkSHbMbmOnrfEGPwQiACiPlnihiaOdbjPqPiTXaHDoJXjSlZmltGqNHHNrcKdlFSCdmVOuvDcBLdSklyGJmcLTbSFtALdGlPkqqecJrpLCXNPWefoTJNgEJlyMEPneVaxxduAAEqQpHWZodWyRkDAxzyMnFMcjSVqeRXLqsNyNtQBbuRvunZflWSbbvXXdkyLikYqutQhLPONXbvhcQZJPSWnOulqQaXmbfFxAkqfYeseSHOQidHwbcsOaMnSrrmGjjRmEMQNuknupMxJiIeVjmgZvbmjPIQTEhQFULQLBMPrxcFPvBinaOPYWGvYGRKxLZdwamfRQQFngcdSlvwjfaPbURasIsGJVHtcEAxnIIrhSriiXLOlbEBLXFElXJFGxHJczRBIxAuPKtBisjKBwfzZFagdNmjdwIRvwzLkFKWRTDPxJCmpzHUcrPiiXXHnOIlqNVoGSXZewdnCRhuxeYGPVTfrNTQNOxZmxInOazUYNTNDgzsxlgiVEHPKMfbesvPHUqpNkUqbzeuzfdrsuLDpKHMUbBMKczKKWOdYoIXoPYtEjfOnlQLoGnbQUCuERdEFaptwnsHzTJDsuZkKtzMpFaZobynZdzNydEeJJHDYaQcwUxcqvwfWwNUsCiLvkZQiSfzAHftYgAmVsXgtmcYgTqJIawstRYJrZdSxlfRiqTufgEQVambeZZmaAyRQbcmdjVUZZCgqDrSeltJGXPMgZnGDZqISrGDOClxXCxMjmKqEPwKHoOfOeyGmqWqihqjINXLqnyTesZePQRqaWDQNqpLgNrAUKulklmckTijUltQKuWQDwpLmDyxLppPVMwsmBIpOwQttYFMjgJQZLYFPmxWFLIeZihkRNnkzoypBICIxgEuYsVWGIGRbbxqVasYnstWomJnHwmtOhAFSpttRYYzBmyEtZXiCthvKvWszTXDbiJbGXMcrYpKAgvUVFtdKUfvdMfhAryctklUCEdjetjuGNfJjajZtvzdYaqInKtFPPLYmRaXPdQzxdSQfmZDEVHlHGEGNSPRFJuIfKLLfUmnHxHnRjmzQPNlqrXgifUdzAGKVabYqvcDeYoTYgPsBUqehrBhmQUgTvDnsdpuhUoxskDdppTsYMcnDIPSwKIqhXDCIxOuXrywahvVavvHkPuaenjLmEbMgrkrQLHEAwrhHkPRNvonNQKqprqOFVZKAtpRSpvQUxMoXCMZLSSbnLEFsjVfANdQNQVwTmGxqVjVqRuxREAhuaDrFgEZpYKhwWPEKBevBfsOIcaZKyykQafzmGPLRAKDtTcJxJVgiiuUkmyMYuDUNEUhBEdoBLJnamtLmMJQgmLiUELIhLpiEvpOXOvXCPUeldLFqkKOwfacqIaRcnnZvERKRMCKUkMABbDHytQqQblrvoxOZkwzosQfDKGtIdfcXRJNqlBNwOCWoQBcEWyqrMlYZIAXYJmLfnjoJepgSFvrgajaBAIksoyeHqgqbGvpAstMIGmIhRYGGNPRIfOQKsGoKgxtsidhTaAePRCBFqZgPDWCIkqOJezGVkjfYUCZTlInbxBXwUAVRsxHTQtJFnnpmMvXDYCVlEmnZBKhmmxQOIQzxFWpJQkQoSAYzTEiDWEOsVLNrbfzeHFRyeYATakQQWmFDLPbVMCJcWjFGJjfqCoVzlbNNEsqxdSmNPjTjHYOkuEMFLkXYGaoJlraLqayMeCsTjWNRDPBywBJLAPVkGQqTwApVVwYAetlwSbzsdHWsTwSIcctkyKDuRWYDQikRqsKTMJchrliONJeaZIzwPQrNbTwxsGdwuduvibtYndRwpdsvyCktRHFalvUuEKMqXbItfGcNGWsGzubdPMYayOUOINjpcFBeESdwpdlTYmrPsLsVDhpTzoMegKrytNVZkfJRPuDCUXxSlSthOohmsuxmIZUedzxKmowKOdXTMcEtdpHaPWgIsIjrViKrQOCONlSuazmLuCUjLltOGXeNgJKedTVrrVCpWYWHyVrdXpKgNaMJVjbXxnVMSChdWKuZdqpisvrkBJPoURDYxWOtpjzZoOpWzyUuYNhCzRoHsMjmmWDcXzQiHIyjwdhPNwiPqFxeUfMVFQGImhykFgMIlQEoZCaRoqSBXTSWAeDumdbsOGtATwEdZlLfoBKiTvodQBGOEcuATWXfiinSjPmJKcWgQrTVYVrwlyMWhxqNbCMpIQNoSMGTiWfPTCezUjYcdWppnsYJihLQCqbNLRGgqrwHuIvsazapTpoPZIyZyeeSueJuTIhpHMEJfJpScshJubJGfkusuVBgfTWQoywSSliQQSfbvaHKiLnyjdSbpMkdBgXepoSsHnCQaYuHQqZsoEOmJCiuQUpJkmfyfbIShzlZpHFmLCsbknEAkKXKfRTRnuwdBeuOGgFbJLbDksHVapaRayWzwoYBEpmrlAxrUxYMUekKbpjPNfjUCjhbdMAnJmYQVZBQZkFVweHDAlaqJjRqoQPoOMLhyvYCzqEuQsAFoxWrzRnTVjStPadhsESlERnKhpEPsfDxNvxqcOyIulaCkmPdambLHvGhTZzysvqFauEgkFRItPfvisehFmoBhQqmkfbHVsgfHXDPJVyhwPllQpuYLRYvGodxKjkarnSNgsXoKEMlaSKxKdcVgvOkuLcfLFfdtXGTclqfPOfeoVLbqcjcXCUEBgAGplrkgsmIEhWRZLlGPGCwKWRaCKMkBHTAcypUrYjWwCLtOPVygMwMANGoQwFnCqFrUGMCRZUGJKTZIGPyldsifauoMnJPLTcDHmilcmahlqOELaAUYDBuzsVywnDQfwRLGIWozYaOAilMBcObErwgTDNGWnwQMUgFFSKtPDMEoEQCTKVREqrXZSGLqwTMcxHfWotDllNkIJPMbXzjDVjPOOjCFuIvTyhXKLyhUScOXvYthRXpPfKwMhptXaxIxgqBoUqzrWbaoLTVpQoottZyPFfNOoMioXHRuFwMRYUiKvcWPkrayyTLOCFJlAyslDameIuqVAuxErqFPEWIScKpBORIuZqoXlZuTvAjEdlEWDODFRregDTqGNoFBIHxvimmIZwLfFyKUfEWAnNBdtdzDmTPXtpHRGdIbuucfTjOygZsTxPjfweXhSUkMhPjMaxKlMIJMOXcnQfyzeOcbWwNbeH", msg.Messages[0].GetCachedValue().(*v1.MsgExecLegacyContent).Content.GetCachedValue().(v1beta1.Content).GetDescription()) + require.Equal(t, simulation.TypeMsgSubmitProposal, sdk.MsgTypeURL(&msg)) +} + // TestSimulateMsgCancelProposal tests the normal scenario of a valid message of type TypeMsgCancelProposal. // Abnormal scenarios, where errors occur, are not tested here. func TestSimulateMsgCancelProposal(t *testing.T) { From c7dc45ae9702f392d7f73d2873f27138ce27817e Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 16:14:19 +0100 Subject: [PATCH 23/32] updates --- x/gov/simulation/operations.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index b4902d56d8e7..7592d29723d8 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -95,6 +95,7 @@ func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak ty ) } + // generate the weighted operations for the proposal contents var wLegacyProposalOps simulation.WeightedOperations for _, wContent := range wContents { wContent := wContent // pin variable From 837bb8ff44cc2f117f5a7fbbce55b2e2caf93554 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 16:19:57 +0100 Subject: [PATCH 24/32] gosec --- x/auth/simulation/proposals.go | 4 +--- x/authz/simulation/operations.go | 8 +++----- x/bank/simulation/operations.go | 10 ++++------ x/bank/simulation/proposals.go | 4 +--- x/distribution/simulation/operations.go | 10 ++++------ x/distribution/simulation/proposals.go | 4 +--- x/mint/simulation/proposals.go | 4 +--- x/nft/simulation/operations.go | 5 +---- x/slashing/simulation/operations.go | 4 +--- x/slashing/simulation/proposals.go | 4 +--- x/staking/simulation/proposals.go | 4 +--- 11 files changed, 19 insertions(+), 42 deletions(-) diff --git a/x/auth/simulation/proposals.go b/x/auth/simulation/proposals.go index 29d5e37e23cf..1f85086a2703 100644 --- a/x/auth/simulation/proposals.go +++ b/x/auth/simulation/proposals.go @@ -11,12 +11,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/authz/simulation/operations.go b/x/authz/simulation/operations.go index 39172a1e5ec8..33fe08dea025 100644 --- a/x/authz/simulation/operations.go +++ b/x/authz/simulation/operations.go @@ -26,12 +26,10 @@ var ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgGrant = "op_weight_msg_grant" - OpWeightRevoke = "op_weight_msg_revoke" - OpWeightExec = "op_weight_msg_execute" + OpWeightMsgGrant = "op_weight_msg_grant" //nolint:gosec + OpWeightRevoke = "op_weight_msg_revoke" //nolint:gosec + OpWeightExec = "op_weight_msg_execute" //nolint:gosec ) // authz operations weights diff --git a/x/bank/simulation/operations.go b/x/bank/simulation/operations.go index 25aa67759269..3f7a1b024d91 100644 --- a/x/bank/simulation/operations.go +++ b/x/bank/simulation/operations.go @@ -17,13 +17,11 @@ import ( ) // Simulation operation weights constants -// -//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" //nolint:gosec + OpWeightMsgMultiSend = "op_weight_msg_multisend" //nolint:gosec + DefaultWeightMsgSend = 100 // from simappparams.DefaultWeightMsgSend + DefaultWeightMsgMultiSend = 10 // from simappparams.DefaultWeightMsgMultiSend ) // WeightedOperations returns all the operations from the module with their respective weights diff --git a/x/bank/simulation/proposals.go b/x/bank/simulation/proposals.go index e1090cefe2ed..cc785b7c7236 100644 --- a/x/bank/simulation/proposals.go +++ b/x/bank/simulation/proposals.go @@ -11,12 +11,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/distribution/simulation/operations.go b/x/distribution/simulation/operations.go index 7f9e61d1d03d..40165a31798a 100644 --- a/x/distribution/simulation/operations.go +++ b/x/distribution/simulation/operations.go @@ -18,13 +18,11 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address" - OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" - OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" - OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool" + OpWeightMsgSetWithdrawAddress = "op_weight_msg_set_withdraw_address" //nolint:gosec + OpWeightMsgWithdrawDelegationReward = "op_weight_msg_withdraw_delegation_reward" //nolint:gosec + OpWeightMsgWithdrawValidatorCommission = "op_weight_msg_withdraw_validator_commission" //nolint:gosec + OpWeightMsgFundCommunityPool = "op_weight_msg_fund_community_pool" //nolint:gosec DefaultWeightMsgSetWithdrawAddress int = 50 DefaultWeightMsgWithdrawDelegationReward int = 50 diff --git a/x/distribution/simulation/proposals.go b/x/distribution/simulation/proposals.go index 73bb25e4a1da..6330691afc26 100644 --- a/x/distribution/simulation/proposals.go +++ b/x/distribution/simulation/proposals.go @@ -11,12 +11,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 50 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/mint/simulation/proposals.go b/x/mint/simulation/proposals.go index 82878a80c62b..129658adcf22 100644 --- a/x/mint/simulation/proposals.go +++ b/x/mint/simulation/proposals.go @@ -11,12 +11,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/nft/simulation/operations.go b/x/nft/simulation/operations.go index 68159a672e3a..7667d7067388 100644 --- a/x/nft/simulation/operations.go +++ b/x/nft/simulation/operations.go @@ -16,13 +16,10 @@ import ( "cosmossdk.io/x/nft/keeper" ) -//nolint:gosec // these are not hardcoded credentials. const ( // OpWeightMsgSend Simulation operation weights constants - OpWeightMsgSend = "op_weight_msg_send" -) + OpWeightMsgSend = "op_weight_msg_send" //nolint:gosec -const ( // WeightSend nft operations weights WeightSend = 100 ) diff --git a/x/slashing/simulation/operations.go b/x/slashing/simulation/operations.go index 5021c5f0cafb..41649e2793d1 100644 --- a/x/slashing/simulation/operations.go +++ b/x/slashing/simulation/operations.go @@ -18,10 +18,8 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( - OpWeightMsgUnjail = "op_weight_msg_unjail" + OpWeightMsgUnjail = "op_weight_msg_unjail" //nolint:gosec DefaultWeightMsgUnjail = 100 ) diff --git a/x/slashing/simulation/proposals.go b/x/slashing/simulation/proposals.go index 03c2e09d8764..6c17b9c44a0a 100644 --- a/x/slashing/simulation/proposals.go +++ b/x/slashing/simulation/proposals.go @@ -12,12 +12,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents diff --git a/x/staking/simulation/proposals.go b/x/staking/simulation/proposals.go index 708602565daf..872e272d0cc1 100644 --- a/x/staking/simulation/proposals.go +++ b/x/staking/simulation/proposals.go @@ -12,12 +12,10 @@ import ( ) // Simulation operation weights constants -// -//nolint:gosec // these are not hardcoded credentials. const ( DefaultWeightMsgUpdateParams int = 100 - OpWeightMsgUpdateParams = "op_weight_msg_update_params" + OpWeightMsgUpdateParams = "op_weight_msg_update_params" //nolint:gosec ) // ProposalMsgs defines the module weighted proposals' contents From cbb711de6ffaabc99a699b8d1356ed1dced3b201 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 17:55:01 +0100 Subject: [PATCH 25/32] updates --- x/gov/simulation/operations.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 7592d29723d8..476961a4a00e 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -205,12 +205,7 @@ func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "error converting legacy content into proposal message"), nil, err } - msg, err := v1.NewMsgSubmitProposal([]sdk.Msg{contentMsg}, deposit, simAccount.Address.String(), "", "Title of proposal", "Short description of proposal") - if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err - } - - return simulateMsgSubmitProposal(ak, bk, k, msg, simAccount, deposit)(r, app, ctx, accs, chainID) + return simulateMsgSubmitProposal(ak, bk, k, contentMsg, simAccount, deposit)(r, app, ctx, accs, chainID) } } From 8e4293c3956aa8eb4714024eaf428385ffc688d6 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 26 Jan 2023 18:36:55 +0100 Subject: [PATCH 26/32] updates --- x/bank/simulation/proposals.go | 6 +++--- x/gov/module.go | 2 +- x/gov/simulation/operations.go | 4 ++-- x/gov/simulation/operations_test.go | 3 ++- x/gov/simulation/proposals.go | 4 ++-- x/params/simulation/operations.go | 4 ++-- x/simulation/params.go | 6 +++--- x/simulation/params_test.go | 2 +- x/slashing/simulation/proposals_test.go | 2 +- x/staking/simulation/proposals_test.go | 2 +- 10 files changed, 18 insertions(+), 17 deletions(-) diff --git a/x/bank/simulation/proposals.go b/x/bank/simulation/proposals.go index cc785b7c7236..43ec1817e315 100644 --- a/x/bank/simulation/proposals.go +++ b/x/bank/simulation/proposals.go @@ -36,11 +36,11 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) params := types.DefaultParams() params.DefaultSendEnabled = r.Intn(2) == 0 if r.Intn(2) == 0 { - params.SendEnabled = nil + params.SendEnabled = nil //nolint:staticcheck } else { - params.SendEnabled = make([]*types.SendEnabled, 10) + params.SendEnabled = make([]*types.SendEnabled, 10) //nolint:staticcheck for i := 0; i < r.Intn(10); i++ { - params.SendEnabled[i] = types.NewSendEnabled( + params.SendEnabled[i] = types.NewSendEnabled( //nolint:staticcheck simtypes.RandStringOfLength(r, 10), r.Intn(2) == 0, ) diff --git a/x/gov/module.go b/x/gov/module.go index bbd461adee3a..a10b7a4b48a8 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -334,7 +334,7 @@ func (AppModule) GenerateGenesisState(simState *module.SimulationState) { // ProposalContents returns all the gov content functions used to // simulate governance proposals. -func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { +func (AppModule) ProposalContents(simState module.SimulationState) []simtypes.WeightedProposalContent { //nolint:staticcheck return simulation.ProposalContents() } diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 476961a4a00e..1a31d0c93c3f 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -46,7 +46,7 @@ const ( ) // 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, wMsgs []simtypes.WeightedProposalMsg, wContents []simtypes.WeightedProposalContent) simulation.WeightedOperations { +func WeightedOperations(appParams simtypes.AppParams, cdc codec.JSONCodec, ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, wMsgs []simtypes.WeightedProposalMsg, wContents []simtypes.WeightedProposalContent) simulation.WeightedOperations { //nolint:staticcheck var ( weightMsgDeposit int weightMsgVote int @@ -179,7 +179,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k // SimulateMsgSubmitLegacyProposal simulates creating a msg Submit Proposal // voting on the proposal, and subsequently slashing the proposal. It is implemented using // future operations. -func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, contentSim simtypes.ContentSimulatorFn) simtypes.Operation { +func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, contentSim simtypes.ContentSimulatorFn) simtypes.Operation { //nolint:staticcheck return func( r *rand.Rand, app *baseapp.BaseApp, ctx sdk.Context, accs []simtypes.Account, chainID string, diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 9b3324da2026..9f2aa7342e1d 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -6,6 +6,7 @@ import ( "testing" "time" + storetypes "cosmossdk.io/store/types" "github.com/stretchr/testify/require" abci "github.com/tendermint/tendermint/abci/types" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" @@ -130,7 +131,7 @@ func TestWeightedOperations(t *testing.T) { } for i, w := range weightesOps { - operationMsg, _, err := w.Op()(r, app.BaseApp, ctx, accs, ctx.ChainID()) + operationMsg, _, err := w.Op()(r, app.BaseApp, ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()), accs, ctx.ChainID()) require.NoError(t, err) // the following checks are very much dependent from the ordering of the output given diff --git a/x/gov/simulation/proposals.go b/x/gov/simulation/proposals.go index 6217e5ffdd6e..d022a714fee8 100644 --- a/x/gov/simulation/proposals.go +++ b/x/gov/simulation/proposals.go @@ -30,7 +30,7 @@ func SimulateTextProposal(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk } // ProposalContents defines the module weighted proposals' contents -func ProposalContents() []simtypes.WeightedProposalContent { +func ProposalContents() []simtypes.WeightedProposalContent { //nolint:staticcheck return []simtypes.WeightedProposalContent{ simulation.NewWeightedProposalContent( OpWeightMsgDeposit, @@ -41,7 +41,7 @@ func ProposalContents() []simtypes.WeightedProposalContent { } // SimulateTextProposalContent returns a random text proposal content. -func SimulateLegacyTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { +func SimulateLegacyTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { //nolint:staticcheck return v1beta1.NewTextProposal( simtypes.RandStringOfLength(r, 140), simtypes.RandStringOfLength(r, 5000), diff --git a/x/params/simulation/operations.go b/x/params/simulation/operations.go index 037dff3ff0f2..fe6a5069e6b7 100644 --- a/x/params/simulation/operations.go +++ b/x/params/simulation/operations.go @@ -19,7 +19,7 @@ func min(a int, b int) int { // SimulateParamChangeProposalContent returns random parameter change content. // It will generate a ParameterChangeProposal object with anywhere between 1 and // the total amount of defined parameters changes, all of which have random valid values. -func SimulateParamChangeProposalContent(paramChangePool []simulation.LegacyParamChange) simulation.ContentSimulatorFn { +func SimulateParamChangeProposalContent(paramChangePool []simulation.LegacyParamChange) simulation.ContentSimulatorFn { //nolint:staticcheck numProposals := 0 // Bound the maximum number of simultaneous parameter changes maxSimultaneousParamChanges := min(len(paramChangePool), 1000) @@ -27,7 +27,7 @@ func SimulateParamChangeProposalContent(paramChangePool []simulation.LegacyParam panic("param changes array is empty") } - return func(r *rand.Rand, _ sdk.Context, _ []simulation.Account) simulation.Content { + return func(r *rand.Rand, _ sdk.Context, _ []simulation.Account) simulation.Content { //nolint:staticcheck numChanges := simulation.RandIntBetween(r, 1, maxSimultaneousParamChanges) paramChanges := make([]proposal.ParamChange, numChanges) diff --git a/x/simulation/params.go b/x/simulation/params.go index 2867244159fd..2f7bc258981e 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -152,10 +152,10 @@ func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFn { type WeightedProposalContent struct { appParamsKey string // key used to retrieve the value of the weight from the simulation application params defaultWeight int // default weight - contentSimulatorFn simulation.ContentSimulatorFn // content simulator function + contentSimulatorFn simulation.ContentSimulatorFn // content simulator function //nolint:staticcheck } -func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { +func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { //nolint:staticcheck return &WeightedProposalContent{appParamsKey: appParamsKey, defaultWeight: defaultWeight, contentSimulatorFn: contentSimulatorFn} } @@ -167,7 +167,7 @@ func (w WeightedProposalContent) DefaultWeight() int { return w.defaultWeight } -func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { +func (w WeightedProposalContent) ContentSimulatorFn() simulation.ContentSimulatorFn { //nolint:staticcheck return w.contentSimulatorFn } diff --git a/x/simulation/params_test.go b/x/simulation/params_test.go index 0edc1432e5ec..23f0bb129f45 100644 --- a/x/simulation/params_test.go +++ b/x/simulation/params_test.go @@ -30,7 +30,7 @@ func TestNewWeightedProposalContent(t *testing.T) { key := "theKey" weight := 1 content := &testContent{} - f := func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { + f := func(r *rand.Rand, ctx sdk.Context, accs []simtypes.Account) simtypes.Content { //nolint:staticcheck return content } diff --git a/x/slashing/simulation/proposals_test.go b/x/slashing/simulation/proposals_test.go index ddf1b87a87d6..4a8edf75e9cf 100644 --- a/x/slashing/simulation/proposals_test.go +++ b/x/slashing/simulation/proposals_test.go @@ -42,5 +42,5 @@ func TestProposalMsgs(t *testing.T) { assert.DeepEqual(t, sdk.NewDecWithPrec(7, 2), msgUpdateParams.Params.MinSignedPerWindow) assert.DeepEqual(t, sdk.NewDecWithPrec(60, 2), msgUpdateParams.Params.SlashFractionDoubleSign) assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.SlashFractionDowntime) - assert.Equal(t, time.Duration(3313479009*time.Second), msgUpdateParams.Params.DowntimeJailDuration) + assert.Equal(t, 3313479009*time.Second, msgUpdateParams.Params.DowntimeJailDuration) } diff --git a/x/staking/simulation/proposals_test.go b/x/staking/simulation/proposals_test.go index f17f77c3fcc9..9d31e5e56d1c 100644 --- a/x/staking/simulation/proposals_test.go +++ b/x/staking/simulation/proposals_test.go @@ -42,6 +42,6 @@ func TestProposalMsgs(t *testing.T) { assert.Equal(t, uint32(694), msgUpdateParams.Params.MaxEntries) assert.Equal(t, uint32(300), msgUpdateParams.Params.HistoricalEntries) assert.Equal(t, uint32(511), msgUpdateParams.Params.MaxValidators) - assert.Equal(t, time.Duration(8898194435*time.Second), msgUpdateParams.Params.UnbondingTime) + assert.Equal(t, 8898194435*time.Second, msgUpdateParams.Params.UnbondingTime) assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.MinCommissionRate) } From 3b57fd8cd1f0767667f986e19cf6facc87a12de9 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 19:58:19 +0100 Subject: [PATCH 27/32] updates --- x/gov/simulation/operations.go | 43 +++++++++++----------- x/gov/simulation/operations_test.go | 56 +++++++++++------------------ 2 files changed, 41 insertions(+), 58 deletions(-) diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 1a31d0c93c3f..712ff3896132 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -160,19 +160,7 @@ func SimulateMsgSubmitProposal(ak types.AccountKeeper, bk types.BankKeeper, k *k msgs = append(msgs, proposalMsg) } - msg, err := v1.NewMsgSubmitProposal( - msgs, - deposit, - simAccount.Address.String(), - simtypes.RandStringOfLength(r, 100), - simtypes.RandStringOfLength(r, 100), - simtypes.RandStringOfLength(r, 100), - ) - if err != nil || msg.ValidateBasic() != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err - } - - return simulateMsgSubmitProposal(ak, bk, k, msg, simAccount, deposit)(r, app, ctx, accs, chainID) + return simulateMsgSubmitProposal(ak, bk, k, msgs, simAccount, deposit)(r, app, ctx, accs, chainID) } } @@ -205,7 +193,7 @@ func SimulateMsgSubmitLegacyProposal(ak types.AccountKeeper, bk types.BankKeeper return simtypes.NoOpMsg(types.ModuleName, TypeMsgSubmitProposal, "error converting legacy content into proposal message"), nil, err } - return simulateMsgSubmitProposal(ak, bk, k, contentMsg, simAccount, deposit)(r, app, ctx, accs, chainID) + return simulateMsgSubmitProposal(ak, bk, k, []sdk.Msg{contentMsg}, simAccount, deposit)(r, app, ctx, accs, chainID) } } @@ -213,7 +201,7 @@ func simulateMsgSubmitProposal( ak types.AccountKeeper, bk types.BankKeeper, k *keeper.Keeper, - msgSubmitProposal sdk.Msg, + proposalMsgs []sdk.Msg, simAccount simtypes.Account, deposit sdk.Coins, ) simtypes.Operation { @@ -245,16 +233,27 @@ func simulateMsgSubmitProposal( accs []simtypes.Account, chainID string, ) (simtypes.OperationMsg, []simtypes.FutureOperation, error) { + msg, err := v1.NewMsgSubmitProposal( + proposalMsgs, + deposit, + simAccount.Address.String(), + simtypes.RandStringOfLength(r, 100), + simtypes.RandStringOfLength(r, 100), + simtypes.RandStringOfLength(r, 100), + ) + if err != nil || msg.ValidateBasic() != nil { + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err + } + account := ak.GetAccount(ctx, simAccount.Address) spendable := bk.SpendableCoins(ctx, account.GetAddress()) var fees sdk.Coins - var err error coins, hasNeg := spendable.SafeSub(deposit...) if !hasNeg { fees, err = simtypes.RandomFees(r, ctx, coins) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate fees"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate fees"), nil, err } } @@ -262,7 +261,7 @@ func simulateMsgSubmitProposal( tx, err := simtestutil.GenSignedMockTx( r, txGen, - []sdk.Msg{msgSubmitProposal}, + []sdk.Msg{msg}, fees, simtestutil.DefaultGenTxGas, chainID, @@ -271,20 +270,20 @@ func simulateMsgSubmitProposal( simAccount.PrivKey, ) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate mock tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate mock tx"), nil, err } _, _, err = app.SimDeliver(txGen.TxEncoder(), tx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to deliver tx"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to deliver tx"), nil, err } - opMsg := simtypes.NewOperationMsg(msgSubmitProposal, true, "", nil) + opMsg := simtypes.NewOperationMsg(msg, true, "", nil) // get the submitted proposal ID proposalID, err := k.GetProposalID(ctx) if err != nil { - return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msgSubmitProposal), "unable to generate proposalID"), nil, err + return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate proposalID"), nil, err } // 2) Schedule operations for votes diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 9f2aa7342e1d..75086f6b8388 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -36,48 +36,28 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) -type MockWeightedProposalMsg struct { +var _ simtypes.WeightedProposalMsg = MockWeightedProposals{} +var _ simtypes.WeightedProposalContent = MockWeightedProposals{} + +type MockWeightedProposals struct { n int } -func (m MockWeightedProposalMsg) AppParamsKey() string { +func (m MockWeightedProposals) AppParamsKey() string { return fmt.Sprintf("AppParamsKey-%d", m.n) } -func (m MockWeightedProposalMsg) DefaultWeight() int { +func (m MockWeightedProposals) DefaultWeight() int { return m.n } -func (m MockWeightedProposalMsg) MsgSimulatorFn() simtypes.MsgSimulatorFn { +func (m MockWeightedProposals) MsgSimulatorFn() simtypes.MsgSimulatorFn { return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk.Msg { return nil } } -// make sure the MockWeightedProposalMsg satisfies the WeightedProposalMsg interface -var _ simtypes.WeightedProposalMsg = MockWeightedProposalMsg{} - -func mockWeightedProposalMsg(n int) []simtypes.WeightedProposalMsg { - wpc := make([]simtypes.WeightedProposalMsg, n) - for i := 0; i < n; i++ { - wpc[i] = MockWeightedProposalMsg{i} - } - return wpc -} - -type MockWeightedLegacyProposalContent struct { - n int -} - -func (m MockWeightedLegacyProposalContent) AppParamsKey() string { - return fmt.Sprintf("AppParamsKey-%d", m.n) -} - -func (m MockWeightedLegacyProposalContent) DefaultWeight() int { - return m.n -} - -func (m MockWeightedLegacyProposalContent) ContentSimulatorFn() simtypes.ContentSimulatorFn { +func (m MockWeightedProposals) ContentSimulatorFn() simtypes.ContentSimulatorFn { return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { return v1beta1.NewTextProposal( fmt.Sprintf("title-%d: %s", m.n, simtypes.RandStringOfLength(r, 100)), @@ -86,13 +66,18 @@ func (m MockWeightedLegacyProposalContent) ContentSimulatorFn() simtypes.Content } } -// make sure the MockWeightedProposalContent satisfied the WeightedProposalContent interface -var _ simtypes.WeightedProposalContent = MockWeightedLegacyProposalContent{} +func mockWeightedProposalMsg(n int) []simtypes.WeightedProposalMsg { + wpc := make([]simtypes.WeightedProposalMsg, n) + for i := 0; i < n; i++ { + wpc[i] = MockWeightedProposals{i} + } + return wpc +} func mockWeightedLegacyProposalContent(n int) []simtypes.WeightedProposalContent { wpc := make([]simtypes.WeightedProposalContent, n) for i := 0; i < n; i++ { - wpc[i] = MockWeightedLegacyProposalContent{i} + wpc[i] = MockWeightedProposals{i} } return wpc } @@ -105,7 +90,7 @@ func TestWeightedOperations(t *testing.T) { appParams := make(simtypes.AppParams) weightesOps := simulation.WeightedOperations(appParams, govcodec.ModuleCdc, suite.AccountKeeper, - suite.BankKeeper, suite.GovKeeper, mockWeightedProposalMsg(3), mockWeightedLegacyProposalContent(3), + suite.BankKeeper, suite.GovKeeper, mockWeightedProposalMsg(3), mockWeightedLegacyProposalContent(1), ) // setup 3 accounts @@ -126,12 +111,11 @@ func TestWeightedOperations(t *testing.T) { {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, {0, types.ModuleName, simulation.TypeMsgSubmitProposal}, - {1, types.ModuleName, simulation.TypeMsgSubmitProposal}, - {2, types.ModuleName, simulation.TypeMsgSubmitProposal}, } for i, w := range weightesOps { operationMsg, _, err := w.Op()(r, app.BaseApp, ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()), accs, ctx.ChainID()) + fmt.Println(i, operationMsg) require.NoError(t, err) // the following checks are very much dependent from the ordering of the output given @@ -158,7 +142,7 @@ func TestSimulateMsgSubmitProposal(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgSubmitProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposalMsg{3}.MsgSimulatorFn()) + op := simulation.SimulateMsgSubmitProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposals{3}.MsgSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) @@ -188,7 +172,7 @@ func TestSimulateMsgSubmitLegacyProposal(t *testing.T) { app.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{Height: app.LastBlockHeight() + 1, AppHash: app.LastCommitID().Hash}}) // execute operation - op := simulation.SimulateMsgSubmitLegacyProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedLegacyProposalContent{3}.ContentSimulatorFn()) + op := simulation.SimulateMsgSubmitLegacyProposal(suite.AccountKeeper, suite.BankKeeper, suite.GovKeeper, MockWeightedProposals{3}.ContentSimulatorFn()) operationMsg, _, err := op(r, app.BaseApp, ctx, accounts, "") require.NoError(t, err) From 81c577dcb4a3478c0162fba55e0b6d3a4a3ee6ef Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 20:40:52 +0100 Subject: [PATCH 28/32] updates --- x/auth/simulation/proposals.go | 10 +++++----- x/bank/simulation/proposals.go | 11 ----------- x/gov/simulation/operations.go | 2 +- x/gov/simulation/operations_test.go | 1 - x/staking/simulation/proposals.go | 6 +++--- x/staking/types/params.go | 4 ++++ 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/x/auth/simulation/proposals.go b/x/auth/simulation/proposals.go index 1f85086a2703..87746569c22f 100644 --- a/x/auth/simulation/proposals.go +++ b/x/auth/simulation/proposals.go @@ -34,11 +34,11 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) var authority sdk.AccAddress = address.Module("gov") params := types.DefaultParams() - params.MaxMemoCharacters = uint64(simtypes.RandIntBetween(r, 0, 1000)) - params.TxSigLimit = uint64(simtypes.RandIntBetween(r, 0, 1000)) - params.TxSizeCostPerByte = uint64(simtypes.RandIntBetween(r, 0, 1000)) - params.SigVerifyCostED25519 = uint64(simtypes.RandIntBetween(r, 0, 1000)) - params.SigVerifyCostSecp256k1 = uint64(simtypes.RandIntBetween(r, 0, 1000)) + params.MaxMemoCharacters = uint64(simtypes.RandIntBetween(r, 1, 1000)) + params.TxSigLimit = uint64(simtypes.RandIntBetween(r, 1, 1000)) + params.TxSizeCostPerByte = uint64(simtypes.RandIntBetween(r, 1, 1000)) + params.SigVerifyCostED25519 = uint64(simtypes.RandIntBetween(r, 1, 1000)) + params.SigVerifyCostSecp256k1 = uint64(simtypes.RandIntBetween(r, 1, 1000)) return &types.MsgUpdateParams{ Authority: authority.String(), diff --git a/x/bank/simulation/proposals.go b/x/bank/simulation/proposals.go index 43ec1817e315..5a63b8632cea 100644 --- a/x/bank/simulation/proposals.go +++ b/x/bank/simulation/proposals.go @@ -35,17 +35,6 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) params := types.DefaultParams() params.DefaultSendEnabled = r.Intn(2) == 0 - if r.Intn(2) == 0 { - params.SendEnabled = nil //nolint:staticcheck - } else { - params.SendEnabled = make([]*types.SendEnabled, 10) //nolint:staticcheck - for i := 0; i < r.Intn(10); i++ { - params.SendEnabled[i] = types.NewSendEnabled( //nolint:staticcheck - simtypes.RandStringOfLength(r, 10), - r.Intn(2) == 0, - ) - } - } return &types.MsgUpdateParams{ Authority: authority.String(), diff --git a/x/gov/simulation/operations.go b/x/gov/simulation/operations.go index 712ff3896132..1256fed08ebb 100644 --- a/x/gov/simulation/operations.go +++ b/x/gov/simulation/operations.go @@ -241,7 +241,7 @@ func simulateMsgSubmitProposal( simtypes.RandStringOfLength(r, 100), simtypes.RandStringOfLength(r, 100), ) - if err != nil || msg.ValidateBasic() != nil { + if err != nil { return simtypes.NoOpMsg(types.ModuleName, sdk.MsgTypeURL(msg), "unable to generate a submit proposal msg"), nil, err } diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 75086f6b8388..5bdb9e910ce3 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -115,7 +115,6 @@ func TestWeightedOperations(t *testing.T) { for i, w := range weightesOps { operationMsg, _, err := w.Op()(r, app.BaseApp, ctx.WithBlockGasMeter(storetypes.NewInfiniteGasMeter()), accs, ctx.ChainID()) - fmt.Println(i, operationMsg) require.NoError(t, err) // the following checks are very much dependent from the ordering of the output given diff --git a/x/staking/simulation/proposals.go b/x/staking/simulation/proposals.go index 872e272d0cc1..6b1f43128247 100644 --- a/x/staking/simulation/proposals.go +++ b/x/staking/simulation/proposals.go @@ -37,10 +37,10 @@ func SimulateMsgUpdateParams(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) params := types.DefaultParams() params.BondDenom = simtypes.RandStringOfLength(r, 10) params.HistoricalEntries = uint32(simtypes.RandIntBetween(r, 0, 1000)) - params.MaxEntries = uint32(simtypes.RandIntBetween(r, 0, 1000)) - params.MaxValidators = uint32(simtypes.RandIntBetween(r, 0, 1000)) + params.MaxEntries = uint32(simtypes.RandIntBetween(r, 1, 1000)) + params.MaxValidators = uint32(simtypes.RandIntBetween(r, 1, 1000)) params.UnbondingTime = time.Duration(simtypes.RandTimestamp(r).UnixNano()) - params.MinCommissionRate = sdk.NewDecWithPrec(int64(simtypes.RandIntBetween(r, 0, 1000)), 2) + params.MinCommissionRate = simtypes.RandomDecAmount(r, sdk.NewDec(1)) return &types.MsgUpdateParams{ Authority: authority.String(), diff --git a/x/staking/types/params.go b/x/staking/types/params.go index cbcacf67b413..9211cf9f5206 100644 --- a/x/staking/types/params.go +++ b/x/staking/types/params.go @@ -100,6 +100,10 @@ func (p Params) Validate() error { return err } + if err := validateHistoricalEntries(p.HistoricalEntries); err != nil { + return err + } + return nil } From 3b2d65d73ea61ea380c91bdedead84201842e0e5 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 20:41:28 +0100 Subject: [PATCH 29/32] updates --- UPGRADING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/UPGRADING.md b/UPGRADING.md index 9a3f26f354e8..b8d5d116ae84 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -103,7 +103,7 @@ Remove `RandomizedParams` from `AppModuleSimulation` interface. Previously, it u Moreover, to support the `MsgUpdateParams` governance proposals for each modules, `AppModuleSimulation` now defines a `AppModule.ProposalMsgs` method in addition to `AppModule.ProposalContents`. That method defines the messages that can be used to submit a proposal and that should be tested in simulation. -When a module has no proposal messages or proposal content to be tested by simulation, the `AppModule.ProposalMsgs` and `AppModule.ProposalContents` methods be deleted. +When a module has no proposal messages or proposal content to be tested by simulation, the `AppModule.ProposalMsgs` and `AppModule.ProposalContents` methods can be deleted. ### gRPC From 745dc78e56d7634f314d9942e41c973e94423c4c Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 20:45:50 +0100 Subject: [PATCH 30/32] fix typos --- CHANGELOG.md | 2 +- testutil/sims/simulation_helpers.go | 4 ++-- types/module/simulation.go | 4 ++-- x/gov/module.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d47152ff282..479145c22569 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -168,7 +168,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes -* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` and `Contents` to `LegacyProposalConents` in `simulation.SimulationState` +* (simulation) [#14728](https://github.com/cosmos/cosmos-sdk/pull/14728) Rename the `ParamChanges` field to `LegacyParamChange` and `Contents` to `LegacyProposalContents` in `simulation.SimulationState`. Additionally it adds a `ProposalMsgs` field to `simulation.SimulationState`. * (x/upgrade) [14764](https://github.com/cosmos/cosmos-sdk/pull/14764) The `x/upgrade` module is extracted to have a separate go.mod file which allows it to be a standalone module. * (x/gov) [#14782](https://github.com/cosmos/cosmos-sdk/pull/14782) Move the `metadata` argument in `govv1.NewProposal` alongside `title` and `summary`. * (store) [#14746](https://github.com/cosmos/cosmos-sdk/pull/14746) Extract Store in its own go.mod and rename the package to `cosmossdk.io/store`. diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 5c1ccfda8b72..8dc02cc7b0c7 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -68,8 +68,8 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - simState.LegacyProposalConents = app.SimulationManager().GetProposalContents(simState) - simState.ProposalMsg = app.SimulationManager().GetProposalMsgs(simState) + simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) + simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 7872badba7fd..8fa979e4721a 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -151,6 +151,6 @@ type SimulationState struct { 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 - LegacyProposalConents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck - ProposalMsg []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key + LegacyProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck + ProposalMsgs []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/x/gov/module.go b/x/gov/module.go index a10b7a4b48a8..dedb7e6ebd65 100644 --- a/x/gov/module.go +++ b/x/gov/module.go @@ -353,6 +353,6 @@ func (am AppModule) WeightedOperations(simState module.SimulationState) []simtyp return simulation.WeightedOperations( simState.AppParams, simState.Cdc, am.accountKeeper, am.bankKeeper, am.keeper, - simState.ProposalMsg, simState.LegacyProposalConents, + simState.ProposalMsgs, simState.LegacyProposalContents, ) } From 05021e5c19273d43b6e68cbf86791f5392d62926 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 21:04:52 +0100 Subject: [PATCH 31/32] updates --- x/auth/simulation/proposals_test.go | 2 +- x/staking/simulation/proposals_test.go | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/x/auth/simulation/proposals_test.go b/x/auth/simulation/proposals_test.go index ffce0aee11f6..db2d0e665c30 100644 --- a/x/auth/simulation/proposals_test.go +++ b/x/auth/simulation/proposals_test.go @@ -37,7 +37,7 @@ func TestProposalMsgs(t *testing.T) { assert.Assert(t, ok) assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) - assert.Equal(t, uint64(540), msgUpdateParams.Params.MaxMemoCharacters) + assert.Equal(t, uint64(999), msgUpdateParams.Params.MaxMemoCharacters) assert.Equal(t, uint64(456), msgUpdateParams.Params.TxSigLimit) assert.Equal(t, uint64(300), msgUpdateParams.Params.TxSizeCostPerByte) assert.Equal(t, uint64(694), msgUpdateParams.Params.SigVerifyCostED25519) diff --git a/x/staking/simulation/proposals_test.go b/x/staking/simulation/proposals_test.go index 9d31e5e56d1c..4f3f79f67a54 100644 --- a/x/staking/simulation/proposals_test.go +++ b/x/staking/simulation/proposals_test.go @@ -39,9 +39,9 @@ func TestProposalMsgs(t *testing.T) { assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) assert.Equal(t, "GqiQWIXnku", msgUpdateParams.Params.BondDenom) - assert.Equal(t, uint32(694), msgUpdateParams.Params.MaxEntries) + assert.Equal(t, uint32(213), msgUpdateParams.Params.MaxEntries) assert.Equal(t, uint32(300), msgUpdateParams.Params.HistoricalEntries) - assert.Equal(t, uint32(511), msgUpdateParams.Params.MaxValidators) + assert.Equal(t, uint32(539), msgUpdateParams.Params.MaxValidators) assert.Equal(t, 8898194435*time.Second, msgUpdateParams.Params.UnbondingTime) - assert.DeepEqual(t, sdk.NewDecWithPrec(89, 2), msgUpdateParams.Params.MinCommissionRate) + assert.DeepEqual(t, sdk.NewDecWithPrec(579040435581502128, 18), msgUpdateParams.Params.MinCommissionRate) } From 4d2001c4e82cadfd7a0239b7394bcfb3e1c0f872 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 27 Jan 2023 21:18:52 +0100 Subject: [PATCH 32/32] updates --- testutil/sims/simulation_helpers.go | 2 +- types/module/simulation.go | 27 ++++++++++++++------------- x/auth/simulation/proposals_test.go | 8 ++++---- x/bank/simulation/proposals_test.go | 2 +- x/gov/simulation/operations_test.go | 14 ++++++++------ x/gov/simulation/proposals.go | 8 ++++++-- x/params/simulation/proposals.go | 2 ++ x/simulation/params.go | 4 +++- 8 files changed, 39 insertions(+), 28 deletions(-) diff --git a/testutil/sims/simulation_helpers.go b/testutil/sims/simulation_helpers.go index 8dc02cc7b0c7..059c9aada434 100644 --- a/testutil/sims/simulation_helpers.go +++ b/testutil/sims/simulation_helpers.go @@ -68,7 +68,7 @@ func SimulationOperations(app runtime.AppI, cdc codec.JSONCodec, config simtypes } } - simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) + simState.LegacyProposalContents = app.SimulationManager().GetProposalContents(simState) //nolint:staticcheck simState.ProposalMsgs = app.SimulationManager().GetProposalMsgs(simState) return app.SimulationManager().WeightedOperations(simState) } diff --git a/types/module/simulation.go b/types/module/simulation.go index 8fa979e4721a..036ef3a9f755 100644 --- a/types/module/simulation.go +++ b/types/module/simulation.go @@ -33,7 +33,7 @@ type HasProposalMsgs interface { // HasProposalContents defines the contents that can be used to simulate legacy governance (v1beta1) proposals type HasProposalContents interface { // content functions used to simulate governance proposals - ProposalContents(simState SimulationState) []simulation.WeightedProposalContent + ProposalContents(simState SimulationState) []simulation.WeightedProposalContent //nolint:staticcheck } // SimulationManager defines a simulation manager that provides the high level utility @@ -140,17 +140,18 @@ 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 - LegacyParamChange []simulation.LegacyParamChange // simulated parameter changes from modules - LegacyProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key //nolint:staticcheck + 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 + //nolint:staticcheck + LegacyProposalContents []simulation.WeightedProposalContent // proposal content generator functions with their default weight and app sim key ProposalMsgs []simulation.WeightedProposalMsg // proposal msg generator functions with their default weight and app sim key } diff --git a/x/auth/simulation/proposals_test.go b/x/auth/simulation/proposals_test.go index db2d0e665c30..285985cad31d 100644 --- a/x/auth/simulation/proposals_test.go +++ b/x/auth/simulation/proposals_test.go @@ -38,8 +38,8 @@ func TestProposalMsgs(t *testing.T) { assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) assert.Equal(t, uint64(999), msgUpdateParams.Params.MaxMemoCharacters) - assert.Equal(t, uint64(456), msgUpdateParams.Params.TxSigLimit) - assert.Equal(t, uint64(300), msgUpdateParams.Params.TxSizeCostPerByte) - assert.Equal(t, uint64(694), msgUpdateParams.Params.SigVerifyCostED25519) - assert.Equal(t, uint64(511), msgUpdateParams.Params.SigVerifyCostSecp256k1) + assert.Equal(t, uint64(905), msgUpdateParams.Params.TxSigLimit) + assert.Equal(t, uint64(151), msgUpdateParams.Params.TxSizeCostPerByte) + assert.Equal(t, uint64(213), msgUpdateParams.Params.SigVerifyCostED25519) + assert.Equal(t, uint64(539), msgUpdateParams.Params.SigVerifyCostSecp256k1) } diff --git a/x/bank/simulation/proposals_test.go b/x/bank/simulation/proposals_test.go index df7d31398ca4..8fa38af01056 100644 --- a/x/bank/simulation/proposals_test.go +++ b/x/bank/simulation/proposals_test.go @@ -39,6 +39,6 @@ func TestProposalMsgs(t *testing.T) { fmt.Println(msgUpdateParams) assert.Equal(t, sdk.AccAddress(address.Module("gov")).String(), msgUpdateParams.Authority) - assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) + assert.Assert(t, len(msgUpdateParams.Params.SendEnabled) == 0) //nolint:staticcheck assert.Equal(t, true, msgUpdateParams.Params.DefaultSendEnabled) } diff --git a/x/gov/simulation/operations_test.go b/x/gov/simulation/operations_test.go index 5bdb9e910ce3..7d34ad040efe 100644 --- a/x/gov/simulation/operations_test.go +++ b/x/gov/simulation/operations_test.go @@ -36,8 +36,10 @@ import ( stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" ) -var _ simtypes.WeightedProposalMsg = MockWeightedProposals{} -var _ simtypes.WeightedProposalContent = MockWeightedProposals{} +var ( + _ simtypes.WeightedProposalMsg = MockWeightedProposals{} + _ simtypes.WeightedProposalContent = MockWeightedProposals{} //nolint:staticcheck +) type MockWeightedProposals struct { n int @@ -57,8 +59,8 @@ func (m MockWeightedProposals) MsgSimulatorFn() simtypes.MsgSimulatorFn { } } -func (m MockWeightedProposals) ContentSimulatorFn() simtypes.ContentSimulatorFn { - return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { +func (m MockWeightedProposals) ContentSimulatorFn() simtypes.ContentSimulatorFn { //nolint:staticcheck + return func(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { //nolint:staticcheck return v1beta1.NewTextProposal( fmt.Sprintf("title-%d: %s", m.n, simtypes.RandStringOfLength(r, 100)), fmt.Sprintf("description-%d: %s", m.n, simtypes.RandStringOfLength(r, 4000)), @@ -74,8 +76,8 @@ func mockWeightedProposalMsg(n int) []simtypes.WeightedProposalMsg { return wpc } -func mockWeightedLegacyProposalContent(n int) []simtypes.WeightedProposalContent { - wpc := make([]simtypes.WeightedProposalContent, n) +func mockWeightedLegacyProposalContent(n int) []simtypes.WeightedProposalContent { //nolint:staticcheck + wpc := make([]simtypes.WeightedProposalContent, n) //nolint:staticcheck for i := 0; i < n; i++ { wpc[i] = MockWeightedProposals{i} } diff --git a/x/gov/simulation/proposals.go b/x/gov/simulation/proposals.go index d022a714fee8..4afda5b0e498 100644 --- a/x/gov/simulation/proposals.go +++ b/x/gov/simulation/proposals.go @@ -30,7 +30,9 @@ func SimulateTextProposal(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) sdk } // ProposalContents defines the module weighted proposals' contents -func ProposalContents() []simtypes.WeightedProposalContent { //nolint:staticcheck +// +//nolint:staticcheck +func ProposalContents() []simtypes.WeightedProposalContent { return []simtypes.WeightedProposalContent{ simulation.NewWeightedProposalContent( OpWeightMsgDeposit, @@ -41,7 +43,9 @@ func ProposalContents() []simtypes.WeightedProposalContent { //nolint:staticchec } // SimulateTextProposalContent returns a random text proposal content. -func SimulateLegacyTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { //nolint:staticcheck +// +//nolint:staticcheck +func SimulateLegacyTextProposalContent(r *rand.Rand, _ sdk.Context, _ []simtypes.Account) simtypes.Content { return v1beta1.NewTextProposal( simtypes.RandStringOfLength(r, 140), simtypes.RandStringOfLength(r, 5000), diff --git a/x/params/simulation/proposals.go b/x/params/simulation/proposals.go index 9f49b9102421..30b8f8434794 100644 --- a/x/params/simulation/proposals.go +++ b/x/params/simulation/proposals.go @@ -12,6 +12,8 @@ const ( ) // ProposalContents defines the module weighted proposals' contents +// +//nolint:staticcheck func ProposalContents(paramChanges []simtypes.LegacyParamChange) []simtypes.WeightedProposalContent { return []simtypes.WeightedProposalContent{ simulation.NewWeightedProposalContent( diff --git a/x/simulation/params.go b/x/simulation/params.go index 2f7bc258981e..4ef3d2201a6b 100644 --- a/x/simulation/params.go +++ b/x/simulation/params.go @@ -149,10 +149,12 @@ func (w WeightedProposalMsg) MsgSimulatorFn() simulation.MsgSimulatorFn { // Legacy Proposal Content // WeightedProposalContent defines a common struct for proposal content defined by external modules (i.e outside gov) +// +//nolint:staticcheck type WeightedProposalContent struct { appParamsKey string // key used to retrieve the value of the weight from the simulation application params defaultWeight int // default weight - contentSimulatorFn simulation.ContentSimulatorFn // content simulator function //nolint:staticcheck + contentSimulatorFn simulation.ContentSimulatorFn // content simulator function } func NewWeightedProposalContent(appParamsKey string, defaultWeight int, contentSimulatorFn simulation.ContentSimulatorFn) simulation.WeightedProposalContent { //nolint:staticcheck