2018-02-19 20:34:51 +00:00
|
|
|
package kvstore
|
2017-10-23 14:20:15 +02:00
|
|
|
|
|
|
|
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"
|
2017-10-23 14:20:15 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// RandVal creates one random validator, with a key derived
|
|
|
|
// from the input value
|
2017-12-22 19:41:19 -08:00
|
|
|
func RandVal(i int) types.Validator {
|
2018-05-23 22:20:35 -04:00
|
|
|
addr := cmn.RandBytes(20)
|
|
|
|
pubkey := cmn.RandBytes(32)
|
2017-10-23 14:20:15 +02:00
|
|
|
power := cmn.RandUint16() + 1
|
2018-05-23 22:20:35 -04:00
|
|
|
v := types.Ed25519Validator(pubkey, int64(power))
|
|
|
|
v.Address = addr
|
|
|
|
return v
|
2017-10-23 14:20:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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)
|
2017-12-22 19:41:19 -08:00
|
|
|
func RandVals(cnt int) []types.Validator {
|
|
|
|
res := make([]types.Validator, cnt)
|
2017-10-23 14:20:15 +02:00
|
|
|
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,
|
2017-10-23 14:20:15 +02:00
|
|
|
// 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) {
|
2018-05-31 21:45:14 -04:00
|
|
|
app.InitChain(types.RequestInitChain{
|
2018-05-31 23:58:02 -04:00
|
|
|
Validators: RandVals(1),
|
2018-02-16 19:49:33 -05:00
|
|
|
})
|
2017-10-23 14:20:15 +02:00
|
|
|
}
|