Skip to content

Commit

Permalink
Merge PR #5149: 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 8e23731 commit 7cf79cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
11 changes: 10 additions & 1 deletion simapp/sim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,16 @@ func appStateFn(
panic("cannot provide both a genesis file and a params file")

case genesisFile != "":
appState, simAccs, chainID = AppStateFromGenesisFileFn(r, accs, genesisTimestamp)
genesisDoc, accounts := AppStateFromGenesisFileFn(r)

if genesisTime == 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 paramsFile != "":
appParams := make(simulation.AppParams)
Expand Down
13 changes: 5 additions & 8 deletions simapp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ func NewSimAppUNSAFE(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLat

// AppStateFromGenesisFileFn util function to generate the genesis AppState
// from a genesis.json file
func AppStateFromGenesisFileFn(
r *rand.Rand, _ []simulation.Account, _ time.Time,
) (json.RawMessage, []simulation.Account, string) {

func AppStateFromGenesisFileFn(r *rand.Rand) (tmtypes.GenesisDoc, []simulation.Account) {
var genesis tmtypes.GenesisDoc
cdc := MakeCodec()

Expand All @@ -87,19 +84,19 @@ func AppStateFromGenesisFileFn(

accounts := genaccounts.GetGenesisStateFromAppState(cdc, appState)

var newAccs []simulation.Account
for _, acc := range accounts {
newAccs := make([]simulation.Account, len(accounts))
for i, acc := range 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.
privkeySeed := make([]byte, 15)
r.Read(privkeySeed)

privKey := secp256k1.GenPrivKeySecp256k1(privkeySeed)
newAccs = append(newAccs, simulation.Account{privKey, privKey.PubKey(), acc.Address})
newAccs[i] = simulation.Account{privKey, privKey.PubKey(), acc.Address}
}

return genesis.AppState, newAccs, genesis.ChainID
return genesis, newAccs
}

// GenAuthGenesisState generates a random GenesisState for auth
Expand Down

0 comments on commit 7cf79cc

Please sign in to comment.