2021-10-11 11:09:53 +00:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
2022-04-28 07:43:39 +00:00
|
|
|
"math/rand"
|
2021-10-11 11:09:53 +00:00
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/types/module"
|
|
|
|
|
2022-09-07 06:36:11 +00:00
|
|
|
"github.com/cerc-io/laconicd/x/evm/types"
|
2021-10-11 11:09:53 +00:00
|
|
|
)
|
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
const (
|
|
|
|
extraEIPsKey = "extra_eips"
|
|
|
|
)
|
|
|
|
|
|
|
|
// GenExtraEIPs defines a set of extra EIPs with 50% probability
|
|
|
|
func GenExtraEIPs(r *rand.Rand) []int64 {
|
2022-04-28 07:43:39 +00:00
|
|
|
var extraEIPs []int64
|
2022-10-10 10:38:33 +00:00
|
|
|
// 50% chance of having extra EIPs
|
|
|
|
if r.Intn(2) == 0 {
|
2022-04-28 07:43:39 +00:00
|
|
|
extraEIPs = []int64{1344, 1884, 2200, 2929, 3198, 3529}
|
|
|
|
}
|
|
|
|
return extraEIPs
|
|
|
|
}
|
|
|
|
|
2022-10-10 10:38:33 +00:00
|
|
|
// GenEnableCreate enables the EnableCreate param with 80% probability
|
|
|
|
func GenEnableCreate(r *rand.Rand) bool {
|
|
|
|
// 80% chance of enabling create contract
|
|
|
|
enableCreate := r.Intn(100) < 80
|
|
|
|
return enableCreate
|
|
|
|
}
|
|
|
|
|
|
|
|
// GenEnableCall enables the EnableCall param with 80% probability
|
|
|
|
func GenEnableCall(r *rand.Rand) bool {
|
|
|
|
// 80% chance of enabling evm account transfer and calling contract
|
|
|
|
enableCall := r.Intn(100) < 80
|
|
|
|
return enableCall
|
|
|
|
}
|
|
|
|
|
|
|
|
// RandomizedGenState generates a random GenesisState for the EVM module
|
2021-10-11 11:09:53 +00:00
|
|
|
func RandomizedGenState(simState *module.SimulationState) {
|
2022-10-10 10:38:33 +00:00
|
|
|
// evm params
|
|
|
|
var extraEIPs []int64
|
|
|
|
|
|
|
|
simState.AppParams.GetOrGenerate(
|
|
|
|
simState.Cdc, extraEIPsKey, &extraEIPs, simState.Rand,
|
|
|
|
func(r *rand.Rand) { extraEIPs = GenExtraEIPs(r) },
|
|
|
|
)
|
|
|
|
|
|
|
|
params := types.NewParams(types.DefaultEVMDenom, true, true, types.DefaultChainConfig(), extraEIPs...)
|
2021-10-11 11:09:53 +00:00
|
|
|
evmGenesis := types.NewGenesisState(params, []types.GenesisAccount{})
|
|
|
|
|
|
|
|
bz, err := json.MarshalIndent(evmGenesis, "", " ")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
fmt.Printf("Selected randomly generated %s parameters:\n%s\n", types.ModuleName, bz)
|
|
|
|
|
|
|
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(evmGenesis)
|
|
|
|
}
|