github.com/number571/tendermint@v0.34.11-gost/abci/example/kvstore/helpers.go (about) 1 package kvstore 2 3 import ( 4 mrand "math/rand" 5 6 "github.com/number571/tendermint/abci/types" 7 tmrand "github.com/number571/tendermint/libs/rand" 8 ) 9 10 // RandVal creates one random validator, with a key derived 11 // from the input value 12 func RandVal(i int) types.ValidatorUpdate { 13 pubkey := tmrand.Bytes(32) 14 // Random value between [0, 2^16 - 1] 15 power := mrand.Uint32() & (1<<16 - 1) // nolint:gosec // G404: Use of weak random number generator 16 v := types.UpdateValidator(pubkey, int64(power), "") 17 return v 18 } 19 20 // RandVals returns a list of cnt validators for initializing 21 // the application. Note that the keys are deterministically 22 // derived from the index in the array, while the power is 23 // random (Change this if not desired) 24 func RandVals(cnt int) []types.ValidatorUpdate { 25 res := make([]types.ValidatorUpdate, cnt) 26 for i := 0; i < cnt; i++ { 27 res[i] = RandVal(i) 28 } 29 return res 30 } 31 32 // InitKVStore initializes the kvstore app with some data, 33 // which allows tests to pass and is fine as long as you 34 // don't make any tx that modify the validator state 35 func InitKVStore(app *PersistentKVStoreApplication) { 36 app.InitChain(types.RequestInitChain{ 37 Validators: RandVals(1), 38 }) 39 }