2018-02-19 20:34:51 +00:00
|
|
|
package kvstore
|
2017-10-23 14:20:15 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/tendermint/abci/types"
|
|
|
|
cmn "github.com/tendermint/tmlibs/common"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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-02-03 02:39:34 -05:00
|
|
|
pubkey := cmn.RandBytes(33)
|
2017-10-23 14:20:15 +02:00
|
|
|
power := cmn.RandUint16() + 1
|
2017-12-22 19:41:19 -08:00
|
|
|
return types.Validator{pubkey, int64(power)}
|
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:34:51 +00:00
|
|
|
// InitKVStore initializes the dummy 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-02-16 19:49:33 -05:00
|
|
|
app.InitChain(types.RequestInitChain{
|
|
|
|
Validators: RandVals(1),
|
|
|
|
AppStateBytes: []byte("[]"),
|
|
|
|
})
|
2017-10-23 14:20:15 +02:00
|
|
|
}
|