Files
wasmd/x/wasm/simulation/params.go
Leonardo Bragagnolo d0befd973d Added randomized simulation parameters generation (#389)
* added simulation params

* fixed return types

* implemented full sim test on wasmd

* removed wrong committed github action

* switched to a import export test since i'm introducing params and genesis simulations

* fixed makefile

* Fixed sim test flags not working

* fixed some errors on sim test

* fixed conflicts
still a failure to be solved

* fixed wasm params error

* added missing codec

* Update params.go

removed unused import

* fixed intellij cache errors

* added full app simulation test that pass

* added README.md for sims credits
added me into contributors list

Co-authored-by: riccardo.montagnin <riccardo.montagnin@gmail.com>
2021-02-05 13:19:14 +01:00

48 lines
1.5 KiB
Go

package simulation
import (
"fmt"
"math/rand"
"github.com/CosmWasm/wasmd/x/wasm/internal/types"
"github.com/cosmos/cosmos-sdk/codec"
simtypes "github.com/cosmos/cosmos-sdk/types/simulation"
"github.com/cosmos/cosmos-sdk/x/simulation"
)
func ParamChanges(r *rand.Rand, cdc codec.Marshaler) []simtypes.ParamChange {
params := RandomParams(r)
return []simtypes.ParamChange{
simulation.NewSimParamChange(types.ModuleName, string(types.ParamStoreKeyUploadAccess),
func(r *rand.Rand) string {
jsonBz, err := cdc.MarshalJSON(&params.CodeUploadAccess)
if err != nil {
panic(err)
}
return string(jsonBz)
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.ParamStoreKeyInstantiateAccess),
func(r *rand.Rand) string {
return fmt.Sprintf("%q", params.CodeUploadAccess.Permission.String())
},
),
simulation.NewSimParamChange(types.ModuleName, string(types.ParamStoreKeyMaxWasmCodeSize),
func(r *rand.Rand) string {
return fmt.Sprintf(`"%d"`, params.MaxWasmCodeSize)
},
),
}
}
func RandomParams(r *rand.Rand) types.Params {
permissionType := types.AccessType(simtypes.RandIntBetween(r, 1, 3))
account, _ := simtypes.RandomAcc(r, simtypes.RandomAccounts(r, 10))
accessConfig := permissionType.With(account.Address)
return types.Params{
CodeUploadAccess: accessConfig,
InstantiateDefaultPermission: accessConfig.Permission,
MaxWasmCodeSize: uint64(simtypes.RandIntBetween(r, 1, 600) * 1024),
}
}