Skip to content

Commit

Permalink
Merge PR cosmos#4750: Allow the use of a custom genesis time in simul…
Browse files Browse the repository at this point in the history
…ations
  • Loading branch information
alexanderbez authored and jackzampolin committed Jul 19, 2019
1 parent bd63560 commit 4c451f4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
13 changes: 10 additions & 3 deletions sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func init() {
flag.IntVar(&period, "Period", 1, "run slow invariants only once every period assertions")
flag.BoolVar(&onOperation, "SimulateEveryOperation", false, "run slow invariants every operation")
flag.BoolVar(&allInvariants, "PrintAllInvariants", false, "print all invariants if a broken invariant is found")
flag.Int64Var(&genesisTime, "GenesisTime", 0, "override genesis UNIX time instead of using a random UNIX time")
}

// helper function for populating input for SimulateFromSeed
Expand All @@ -63,11 +64,17 @@ func getSimulateFromSeedInput(tb testing.TB, w io.Writer, app *SimApp) (
}

func appStateFn(
r *rand.Rand, accs []simulation.Account, genesisTimestamp time.Time,
) (appState json.RawMessage, simAccs []simulation.Account, chainID string) {
r *rand.Rand, accs []simulation.Account,
) (appState json.RawMessage, simAccs []simulation.Account, chainID string, genesisTimestamp time.Time) {

cdc := MakeCodec()

if genesisTime == 0 {
genesisTimestamp = simulation.RandTimestamp(r)
} else {
genesisTimestamp = time.Unix(genesisTime, 0)
}

switch {
case paramsFile != "" && genesisFile != "":
panic("cannot provide both a genesis file and a params file")
Expand All @@ -90,7 +97,7 @@ func appStateFn(
appState, simAccs, chainID = appStateRandomizedFn(r, accs, genesisTimestamp, appParams)
}

return appState, simAccs, chainID
return appState, simAccs, chainID, genesisTimestamp
}

// TODO refactor out random initialization code to the modules
Expand Down
1 change: 1 addition & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
period int
onOperation bool // TODO Remove in favor of binary search for invariant violation
allInvariants bool
genesisTime int64
)

// NewSimAppUNSAFE is used for debugging purposes only.
Expand Down

0 comments on commit 4c451f4

Please sign in to comment.