x/staking v0.43 Audit updates (#9267)
* update staking specs * use gosimple code in x/staking/client/testutil/suite.go * small fixes * add godoc to methods in msg_server and grpc_query * changes to godoc and small fixes * remove unnecessary lines * remove mentions of serviceMsg and avoid having slash after Msg
This commit is contained in:
@@ -21,18 +21,18 @@ const (
|
||||
historicalEntries = "historical_entries"
|
||||
)
|
||||
|
||||
// GenUnbondingTime randomized UnbondingTime
|
||||
func GenUnbondingTime(r *rand.Rand) (ubdTime time.Duration) {
|
||||
// genUnbondingTime returns randomized UnbondingTime
|
||||
func genUnbondingTime(r *rand.Rand) (ubdTime time.Duration) {
|
||||
return time.Duration(simulation.RandIntBetween(r, 60, 60*60*24*3*2)) * time.Second
|
||||
}
|
||||
|
||||
// GenMaxValidators randomized MaxValidators
|
||||
func GenMaxValidators(r *rand.Rand) (maxValidators uint32) {
|
||||
// genMaxValidators returns randomized MaxValidators
|
||||
func genMaxValidators(r *rand.Rand) (maxValidators uint32) {
|
||||
return uint32(r.Intn(250) + 1)
|
||||
}
|
||||
|
||||
// GetHistEntries randomized HistoricalEntries between 0-100.
|
||||
func GetHistEntries(r *rand.Rand) uint32 {
|
||||
// getHistEntries returns randomized HistoricalEntries between 0-100.
|
||||
func getHistEntries(r *rand.Rand) uint32 {
|
||||
return uint32(r.Intn(int(types.DefaultHistoricalEntries + 1)))
|
||||
}
|
||||
|
||||
@@ -47,17 +47,17 @@ func RandomizedGenState(simState *module.SimulationState) {
|
||||
|
||||
simState.AppParams.GetOrGenerate(
|
||||
simState.Cdc, unbondingTime, &unbondTime, simState.Rand,
|
||||
func(r *rand.Rand) { unbondTime = GenUnbondingTime(r) },
|
||||
func(r *rand.Rand) { unbondTime = genUnbondingTime(r) },
|
||||
)
|
||||
|
||||
simState.AppParams.GetOrGenerate(
|
||||
simState.Cdc, maxValidators, &maxVals, simState.Rand,
|
||||
func(r *rand.Rand) { maxVals = GenMaxValidators(r) },
|
||||
func(r *rand.Rand) { maxVals = genMaxValidators(r) },
|
||||
)
|
||||
|
||||
simState.AppParams.GetOrGenerate(
|
||||
simState.Cdc, historicalEntries, &histEntries, simState.Rand,
|
||||
func(r *rand.Rand) { histEntries = GetHistEntries(r) },
|
||||
func(r *rand.Rand) { histEntries = getHistEntries(r) },
|
||||
)
|
||||
|
||||
// NOTE: the slashing module need to be defined after the staking module on the
|
||||
|
||||
@@ -68,7 +68,7 @@ func TestRandomizedGenState(t *testing.T) {
|
||||
require.Equal(t, "1", stakingGenesis.Validators[2].MinSelfDelegation.String())
|
||||
}
|
||||
|
||||
// TestRandomizedGenState tests abnormal scenarios of applying RandomizedGenState.
|
||||
// TestRandomizedGenState1 tests abnormal scenarios of applying RandomizedGenState.
|
||||
func TestRandomizedGenState1(t *testing.T) {
|
||||
interfaceRegistry := codectypes.NewInterfaceRegistry()
|
||||
cdc := codec.NewProtoCodec(interfaceRegistry)
|
||||
|
||||
@@ -6,9 +6,8 @@ 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/simulation"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
@@ -18,17 +17,17 @@ 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))
|
||||
return fmt.Sprintf("%d", genMaxValidators(r))
|
||||
},
|
||||
),
|
||||
simulation.NewSimParamChange(types.ModuleName, string(types.KeyUnbondingTime),
|
||||
func(r *rand.Rand) string {
|
||||
return fmt.Sprintf("\"%d\"", GenUnbondingTime(r))
|
||||
return fmt.Sprintf("\"%d\"", genUnbondingTime(r))
|
||||
},
|
||||
),
|
||||
simulation.NewSimParamChange(types.ModuleName, string(types.KeyHistoricalEntries),
|
||||
func(r *rand.Rand) string {
|
||||
return fmt.Sprintf("%d", GetHistEntries(r))
|
||||
return fmt.Sprintf("%d", getHistEntries(r))
|
||||
},
|
||||
),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user