You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
1.0 KiB

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