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.

39 lines
1.2 KiB

  1. package kvstore
  2. import (
  3. mrand "math/rand"
  4. "github.com/tendermint/tendermint/abci/types"
  5. tmrand "github.com/tendermint/tendermint/libs/rand"
  6. )
  7. // RandVal creates one random validator, with a key derived
  8. // from the input value
  9. func RandVal(i int) types.ValidatorUpdate {
  10. pubkey := tmrand.Bytes(32)
  11. // Random value between [0, 2^16 - 1]
  12. power := mrand.Uint32() & (1<<16 - 1) // nolint:gosec // G404: Use of weak random number generator
  13. v := types.UpdateValidator(pubkey, int64(power), "")
  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.ValidatorUpdate {
  21. res := make([]types.ValidatorUpdate, 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. }