diff --git a/simapp/state.go b/simapp/state.go index f00e478ec947..1801dd36f7bc 100644 --- a/simapp/state.go +++ b/simapp/state.go @@ -34,7 +34,16 @@ func AppStateFn(cdc *codec.Codec, simManager *module.SimulationManager) simulati panic("cannot provide both a genesis file and a params file") case config.GenesisFile != "": - appState, simAccs, chainID = AppStateFromGenesisFileFn(r, cdc, config.GenesisFile) + genesisDoc, accounts := AppStateFromGenesisFileFn(r, cdc, config.GenesisFile) + + if FlagGenesisTimeValue == 0 { + // use genesis timestamp if no custom timestamp is provided (i.e no random timestamp) + genesisTimestamp = genesisDoc.GenesisTime + } + + appState = genesisDoc.AppState + chainID = genesisDoc.ChainID + simAccs = accounts case config.ParamsFile != "": appParams := make(simulation.AppParams) @@ -111,10 +120,8 @@ func AppStateRandomizedFn( } // AppStateFromGenesisFileFn util function to generate the genesis AppState -// from a genesis.json file -func AppStateFromGenesisFileFn(r *rand.Rand, cdc *codec.Codec, genesisFile string) ( - genState json.RawMessage, newAccs []simulation.Account, chainID string) { - +// from a genesis.json file. +func AppStateFromGenesisFileFn(r *rand.Rand, cdc *codec.Codec, genesisFile string) (tmtypes.GenesisDoc, []simulation.Account) { bytes, err := ioutil.ReadFile(genesisFile) if err != nil { panic(err) @@ -131,7 +138,8 @@ func AppStateFromGenesisFileFn(r *rand.Rand, cdc *codec.Codec, genesisFile strin cdc.MustUnmarshalJSON(appState[auth.ModuleName], &authGenesis) } - for _, acc := range authGenesis.Accounts { + newAccs := make([]simulation.Account, len(authGenesis.Accounts)) + for i, acc := range authGenesis.Accounts { // Pick a random private key, since we don't know the actual key // This should be fine as it's only used for mock Tendermint validators // and these keys are never actually used to sign by mock Tendermint. @@ -144,8 +152,8 @@ func AppStateFromGenesisFileFn(r *rand.Rand, cdc *codec.Codec, genesisFile strin // create simulator accounts simAcc := simulation.Account{PrivKey: privKey, PubKey: privKey.PubKey(), Address: acc.GetAddress()} - newAccs = append(newAccs, simAcc) + newAccs[i] = simAcc } - return genesis.AppState, newAccs, genesis.ChainID + return genesis, newAccs }