github.com/Finschia/finschia-sdk@v0.48.1/simapp/config.go (about)

     1  package simapp
     2  
     3  import (
     4  	"flag"
     5  
     6  	"github.com/Finschia/finschia-sdk/types/simulation"
     7  )
     8  
     9  // List of available flags for the simulator
    10  var (
    11  	FlagGenesisFileValue        string
    12  	FlagParamsFileValue         string
    13  	FlagExportParamsPathValue   string
    14  	FlagExportParamsHeightValue int
    15  	FlagExportStatePathValue    string
    16  	FlagExportStatsPathValue    string
    17  	FlagSeedValue               int64
    18  	FlagInitialBlockHeightValue int
    19  	FlagNumBlocksValue          int
    20  	FlagBlockSizeValue          int
    21  	FlagLeanValue               bool
    22  	FlagCommitValue             bool
    23  	FlagOnOperationValue        bool // TODO: Remove in favor of binary search for invariant violation
    24  	FlagAllInvariantsValue      bool
    25  
    26  	FlagEnabledValue     bool
    27  	FlagVerboseValue     bool
    28  	FlagPeriodValue      uint
    29  	FlagGenesisTimeValue int64
    30  )
    31  
    32  // GetSimulatorFlags gets the values of all the available simulation flags
    33  func GetSimulatorFlags() {
    34  	// config fields
    35  	flag.StringVar(&FlagGenesisFileValue, "Genesis", "", "custom simulation genesis file; cannot be used with params file")
    36  	flag.StringVar(&FlagParamsFileValue, "Params", "", "custom simulation params file which overrides any random params; cannot be used with genesis")
    37  	flag.StringVar(&FlagExportParamsPathValue, "ExportParamsPath", "", "custom file path to save the exported params JSON")
    38  	flag.IntVar(&FlagExportParamsHeightValue, "ExportParamsHeight", 0, "height to which export the randomly generated params")
    39  	flag.StringVar(&FlagExportStatePathValue, "ExportStatePath", "", "custom file path to save the exported app state JSON")
    40  	flag.StringVar(&FlagExportStatsPathValue, "ExportStatsPath", "", "custom file path to save the exported simulation statistics JSON")
    41  	flag.Int64Var(&FlagSeedValue, "Seed", 42, "simulation random seed")
    42  	flag.IntVar(&FlagInitialBlockHeightValue, "InitialBlockHeight", 1, "initial block to start the simulation")
    43  	flag.IntVar(&FlagNumBlocksValue, "NumBlocks", 500, "number of new blocks to simulate from the initial block height")
    44  	flag.IntVar(&FlagBlockSizeValue, "BlockSize", 200, "operations per block")
    45  	flag.BoolVar(&FlagLeanValue, "Lean", false, "lean simulation log output")
    46  	flag.BoolVar(&FlagCommitValue, "Commit", false, "have the simulation commit")
    47  	flag.BoolVar(&FlagOnOperationValue, "SimulateEveryOperation", false, "run slow invariants every operation")
    48  	flag.BoolVar(&FlagAllInvariantsValue, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
    49  
    50  	// simulation flags
    51  	flag.BoolVar(&FlagEnabledValue, "Enabled", false, "enable the simulation")
    52  	flag.BoolVar(&FlagVerboseValue, "Verbose", false, "verbose log output")
    53  	flag.UintVar(&FlagPeriodValue, "Period", 0, "run slow invariants only once every period assertions")
    54  	flag.Int64Var(&FlagGenesisTimeValue, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
    55  }
    56  
    57  // NewConfigFromFlags creates a simulation from the retrieved values of the flags.
    58  func NewConfigFromFlags() simulation.Config {
    59  	return simulation.Config{
    60  		GenesisFile:        FlagGenesisFileValue,
    61  		ParamsFile:         FlagParamsFileValue,
    62  		ExportParamsPath:   FlagExportParamsPathValue,
    63  		ExportParamsHeight: FlagExportParamsHeightValue,
    64  		ExportStatePath:    FlagExportStatePathValue,
    65  		ExportStatsPath:    FlagExportStatsPathValue,
    66  		Seed:               FlagSeedValue,
    67  		InitialBlockHeight: FlagInitialBlockHeightValue,
    68  		NumBlocks:          FlagNumBlocksValue,
    69  		BlockSize:          FlagBlockSizeValue,
    70  		Lean:               FlagLeanValue,
    71  		Commit:             FlagCommitValue,
    72  		OnOperation:        FlagOnOperationValue,
    73  		AllInvariants:      FlagAllInvariantsValue,
    74  	}
    75  }