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.

38 lines
1.0 KiB

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