Merge PR #5019: Export sim CLI flags
This commit is contained in:
parent
47ffaa2504
commit
15517afeb2
|
@ -306,7 +306,7 @@ func BenchmarkFullAppSimulation(b *testing.B) {
|
|||
os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, interBlockCacheOpt())
|
||||
|
||||
// Run randomized simulation
|
||||
// TODO: parameterize numbers, save for a later PR
|
||||
|
@ -343,14 +343,14 @@ func BenchmarkFullAppSimulation(b *testing.B) {
|
|||
}
|
||||
|
||||
func TestFullAppSimulation(t *testing.T) {
|
||||
if !flagEnabledValue {
|
||||
if !FlagEnabledValue {
|
||||
t.Skip("skipping application simulation")
|
||||
}
|
||||
|
||||
var logger log.Logger
|
||||
config := NewConfigFromFlags()
|
||||
|
||||
if flagVerboseValue {
|
||||
if FlagVerboseValue {
|
||||
logger = log.TestingLogger()
|
||||
} else {
|
||||
logger = log.NewNopLogger()
|
||||
|
@ -365,7 +365,7 @@ func TestFullAppSimulation(t *testing.T) {
|
|||
os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// Run randomized simulation
|
||||
|
@ -397,14 +397,14 @@ func TestFullAppSimulation(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAppImportExport(t *testing.T) {
|
||||
if !flagEnabledValue {
|
||||
if !FlagEnabledValue {
|
||||
t.Skip("skipping application import/export simulation")
|
||||
}
|
||||
|
||||
var logger log.Logger
|
||||
config := NewConfigFromFlags()
|
||||
|
||||
if flagVerboseValue {
|
||||
if FlagVerboseValue {
|
||||
logger = log.TestingLogger()
|
||||
} else {
|
||||
logger = log.NewNopLogger()
|
||||
|
@ -419,7 +419,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// Run randomized simulation
|
||||
|
@ -463,7 +463,7 @@ func TestAppImportExport(t *testing.T) {
|
|||
_ = os.RemoveAll(newDir)
|
||||
}()
|
||||
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, flagPeriodValue, fauxMerkleModeOpt)
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", newApp.Name())
|
||||
|
||||
var genesisState GenesisState
|
||||
|
@ -515,14 +515,14 @@ func TestAppImportExport(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestAppSimulationAfterImport(t *testing.T) {
|
||||
if !flagEnabledValue {
|
||||
if !FlagEnabledValue {
|
||||
t.Skip("skipping application simulation after import")
|
||||
}
|
||||
|
||||
var logger log.Logger
|
||||
config := NewConfigFromFlags()
|
||||
|
||||
if flagVerboseValue {
|
||||
if FlagVerboseValue {
|
||||
logger = log.TestingLogger()
|
||||
} else {
|
||||
logger = log.NewNopLogger()
|
||||
|
@ -536,7 +536,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, fauxMerkleModeOpt)
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", app.Name())
|
||||
|
||||
// Run randomized simulation
|
||||
|
@ -587,7 +587,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
_ = os.RemoveAll(newDir)
|
||||
}()
|
||||
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, flagPeriodValue, fauxMerkleModeOpt)
|
||||
newApp := NewSimApp(log.NewNopLogger(), newDB, nil, true, FlagPeriodValue, fauxMerkleModeOpt)
|
||||
require.Equal(t, "SimApp", newApp.Name())
|
||||
|
||||
newApp.InitChain(abci.RequestInitChain{
|
||||
|
@ -606,7 +606,7 @@ func TestAppSimulationAfterImport(t *testing.T) {
|
|||
// TODO: Make another test for the fuzzer itself, which just has noOp txs
|
||||
// and doesn't depend on the application.
|
||||
func TestAppStateDeterminism(t *testing.T) {
|
||||
if !flagEnabledValue {
|
||||
if !FlagEnabledValue {
|
||||
t.Skip("skipping application simulation")
|
||||
}
|
||||
|
||||
|
@ -627,7 +627,7 @@ func TestAppStateDeterminism(t *testing.T) {
|
|||
logger := log.NewNopLogger()
|
||||
db := dbm.NewMemDB()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, interBlockCacheOpt())
|
||||
|
||||
fmt.Printf(
|
||||
"running non-determinism simulation; seed %d: %d/%d, attempt: %d/%d\n",
|
||||
|
@ -667,7 +667,7 @@ func BenchmarkInvariants(b *testing.B) {
|
|||
os.RemoveAll(dir)
|
||||
}()
|
||||
|
||||
app := NewSimApp(logger, db, nil, true, flagPeriodValue, interBlockCacheOpt())
|
||||
app := NewSimApp(logger, db, nil, true, FlagPeriodValue, interBlockCacheOpt())
|
||||
|
||||
// 2. Run parameterized simulation (w/o invariants)
|
||||
_, simParams, simErr := simulation.SimulateFromSeed(
|
||||
|
|
|
@ -23,10 +23,10 @@ func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simulati
|
|||
return func(r *rand.Rand, accs []simulation.Account, config simulation.Config,
|
||||
) (appState json.RawMessage, simAccs []simulation.Account, chainID string, genesisTimestamp time.Time) {
|
||||
|
||||
if flagGenesisTimeValue == 0 {
|
||||
if FlagGenesisTimeValue == 0 {
|
||||
genesisTimestamp = simulation.RandTimestamp(r)
|
||||
} else {
|
||||
genesisTimestamp = time.Unix(flagGenesisTimeValue, 0)
|
||||
genesisTimestamp = time.Unix(FlagGenesisTimeValue, 0)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
|
107
simapp/utils.go
107
simapp/utils.go
|
@ -18,70 +18,69 @@ import (
|
|||
|
||||
// List of available flags for the simulator
|
||||
var (
|
||||
flagGenesisFileValue string
|
||||
flagParamsFileValue string
|
||||
flagExportParamsPathValue string
|
||||
flagExportParamsHeightValue int
|
||||
flagExportStatePathValue string
|
||||
flagExportStatsPathValue string
|
||||
flagSeedValue int64
|
||||
flagInitialBlockHeightValue int
|
||||
flagNumBlocksValue int
|
||||
flagBlockSizeValue int
|
||||
flagLeanValue bool
|
||||
flagCommitValue bool
|
||||
flagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation
|
||||
flagAllInvariantsValue bool
|
||||
FlagGenesisFileValue string
|
||||
FlagParamsFileValue string
|
||||
FlagExportParamsPathValue string
|
||||
FlagExportParamsHeightValue int
|
||||
FlagExportStatePathValue string
|
||||
FlagExportStatsPathValue string
|
||||
FlagSeedValue int64
|
||||
FlagInitialBlockHeightValue int
|
||||
FlagNumBlocksValue int
|
||||
FlagBlockSizeValue int
|
||||
FlagLeanValue bool
|
||||
FlagCommitValue bool
|
||||
FlagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation
|
||||
FlagAllInvariantsValue bool
|
||||
|
||||
flagEnabledValue bool
|
||||
flagVerboseValue bool
|
||||
flagPeriodValue uint
|
||||
flagGenesisTimeValue int64
|
||||
FlagEnabledValue bool
|
||||
FlagVerboseValue bool
|
||||
FlagPeriodValue uint
|
||||
FlagGenesisTimeValue int64
|
||||
)
|
||||
|
||||
// GetSimulatorFlags gets the values of all the available simulation flags
|
||||
func GetSimulatorFlags() {
|
||||
// config fields
|
||||
flag.StringVar(&FlagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file")
|
||||
flag.StringVar(&FlagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis")
|
||||
flag.StringVar(&FlagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON")
|
||||
flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
|
||||
flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
|
||||
flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
|
||||
flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed")
|
||||
flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
|
||||
flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
|
||||
flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
|
||||
flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
|
||||
flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit")
|
||||
flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
|
||||
flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
|
||||
|
||||
// Config fields
|
||||
flag.StringVar(&flagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file")
|
||||
flag.StringVar(&flagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis")
|
||||
flag.StringVar(&flagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON")
|
||||
flag.IntVar(&flagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
|
||||
flag.StringVar(&flagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
|
||||
flag.StringVar(&flagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
|
||||
flag.Int64Var(&flagSeedValue, "Seed", 42, "simulation random seed")
|
||||
flag.IntVar(&flagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
|
||||
flag.IntVar(&flagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
|
||||
flag.IntVar(&flagBlockSizeValue, "BlockSize", 200, "operations per block")
|
||||
flag.BoolVar(&flagLeanValue, "Lean", false, "lean simulation log output")
|
||||
flag.BoolVar(&flagCommitValue, "Commit", false, "have the simulation commit")
|
||||
flag.BoolVar(&flagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
|
||||
flag.BoolVar(&flagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
|
||||
|
||||
// SimApp flags
|
||||
flag.BoolVar(&flagEnabledValue, "Enabled", false, "enable the simulation")
|
||||
flag.BoolVar(&flagVerboseValue, "Verbose", false, "verbose log output")
|
||||
flag.UintVar(&flagPeriodValue, "Period", 0, "run slow invariants only once every period assertions")
|
||||
flag.Int64Var(&flagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
|
||||
// simulation flags
|
||||
flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
|
||||
flag.BoolVar(&FlagVerboseValue, "Verbose", false, "verbose log output")
|
||||
flag.UintVar(&FlagPeriodValue, "Period", 0, "run slow invariants only once every period assertions")
|
||||
flag.Int64Var(&FlagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
|
||||
}
|
||||
|
||||
// NewConfigFromFlags creates a simulation from the retrieved values of the flags
|
||||
// NewConfigFromFlags creates a simulation from the retrieved values of the flags.
|
||||
func NewConfigFromFlags() simulation.Config {
|
||||
return simulation.Config{
|
||||
GenesisFile: flagGenesisFileValue,
|
||||
ParamsFile: flagParamsFileValue,
|
||||
ExportParamsPath: flagExportParamsPathValue,
|
||||
ExportParamsHeight: flagExportParamsHeightValue,
|
||||
ExportStatePath: flagExportStatePathValue,
|
||||
ExportStatsPath: flagExportStatsPathValue,
|
||||
Seed: flagSeedValue,
|
||||
InitialBlockHeight: flagInitialBlockHeightValue,
|
||||
NumBlocks: flagNumBlocksValue,
|
||||
BlockSize: flagBlockSizeValue,
|
||||
Lean: flagLeanValue,
|
||||
Commit: flagCommitValue,
|
||||
OnOperation: flagOnOperationValue,
|
||||
AllInvariants: flagAllInvariantsValue,
|
||||
GenesisFile: FlagGenesisFileValue,
|
||||
ParamsFile: FlagParamsFileValue,
|
||||
ExportParamsPath: FlagExportParamsPathValue,
|
||||
ExportParamsHeight: FlagExportParamsHeightValue,
|
||||
ExportStatePath: FlagExportStatePathValue,
|
||||
ExportStatsPath: FlagExportStatsPathValue,
|
||||
Seed: FlagSeedValue,
|
||||
InitialBlockHeight: FlagInitialBlockHeightValue,
|
||||
NumBlocks: FlagNumBlocksValue,
|
||||
BlockSize: FlagBlockSizeValue,
|
||||
Lean: FlagLeanValue,
|
||||
Commit: FlagCommitValue,
|
||||
OnOperation: FlagOnOperationValue,
|
||||
AllInvariants: FlagAllInvariantsValue,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue