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/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. pubkey := cmn.RandBytes(33)
  10. power := cmn.RandUint16() + 1
  11. return types.Validator{pubkey, int64(power)}
  12. }
  13. // RandVals returns a list of cnt validators for initializing
  14. // the application. Note that the keys are deterministically
  15. // derived from the index in the array, while the power is
  16. // random (Change this if not desired)
  17. func RandVals(cnt int) []types.Validator {
  18. res := make([]types.Validator, cnt)
  19. for i := 0; i < cnt; i++ {
  20. res[i] = RandVal(i)
  21. }
  22. return res
  23. }
  24. // InitKVStore initializes the kvstore app with some data,
  25. // which allows tests to pass and is fine as long as you
  26. // don't make any tx that modify the validator state
  27. func InitKVStore(app *PersistentKVStoreApplication) {
  28. app.InitChain(types.RequestInitChain{
  29. Validators: RandVals(1),
  30. GenesisBytes: []byte("[]"),
  31. })
  32. }