Skip to content

Commit

Permalink
Merge PR #5148: Use genesis file timestamp if none provided
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez authored Oct 7, 2019
1 parent 41cb642 commit fd76e62
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions simapp/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
}

0 comments on commit fd76e62

Please sign in to comment.