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