forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#5378: application interfaces for simulation
- Loading branch information
1 parent
17d5f4f
commit 2e61d4e
Showing
10 changed files
with
296 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package simapp | ||
|
||
import ( | ||
"flag" | ||
|
||
"github.com/cosmos/cosmos-sdk/x/simulation" | ||
) | ||
|
||
// 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 | ||
|
||
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") | ||
|
||
// 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. | ||
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package simapp | ||
package params | ||
|
||
// Simulation parameter constants | ||
const ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.