39 lines
1.1 KiB
Go
Raw Normal View History

2018-02-19 20:34:51 +00:00
package kvstore
import (
2018-06-22 06:59:02 +02:00
"github.com/tendermint/tendermint/abci/types"
2018-07-01 22:36:49 -04:00
cmn "github.com/tendermint/tendermint/libs/common"
)
// RandVal creates one random validator, with a key derived
// from the input value
func RandVal(i int) types.Validator {
2018-05-23 22:20:35 -04:00
addr := cmn.RandBytes(20)
pubkey := cmn.RandBytes(32)
power := cmn.RandUint16() + 1
2018-05-23 22:20:35 -04:00
v := types.Ed25519Validator(pubkey, int64(power))
v.Address = addr
return v
}
// RandVals returns a list of cnt validators for initializing
// the application. Note that the keys are deterministically
// derived from the index in the array, while the power is
// random (Change this if not desired)
func RandVals(cnt int) []types.Validator {
res := make([]types.Validator, cnt)
for i := 0; i < cnt; i++ {
res[i] = RandVal(i)
}
return res
}
2018-02-19 20:43:36 +00:00
// InitKVStore initializes the kvstore app with some data,
// which allows tests to pass and is fine as long as you
// don't make any tx that modify the validator state
2018-02-19 20:34:51 +00:00
func InitKVStore(app *PersistentKVStoreApplication) {
app.InitChain(types.RequestInitChain{
Validators: RandVals(1),
2018-02-16 19:49:33 -05:00
})
}