Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Genesis File Timestamp #5148

Merged
merged 1 commit into from
Oct 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}