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