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.

34 lines
1.1 KiB

  1. package dummy
  2. import (
  3. "github.com/tendermint/abci/types"
  4. crypto "github.com/tendermint/go-crypto"
  5. cmn "github.com/tendermint/tmlibs/common"
  6. )
  7. // RandVal creates one random validator, with a key derived
  8. // from the input value
  9. func RandVal(i int) *types.Validator {
  10. pubkey := crypto.GenPrivKeyEd25519FromSecret([]byte(cmn.Fmt("test%d", i))).PubKey().Bytes()
  11. power := cmn.RandUint16() + 1
  12. return &types.Validator{pubkey, uint64(power)}
  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.Validator {
  19. res := make([]*types.Validator, cnt)
  20. for i := 0; i < cnt; i++ {
  21. res[i] = RandVal(i)
  22. }
  23. return res
  24. }
  25. // InitDummy initializes the dummy 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 InitDummy(app *PersistentDummyApplication) {
  29. app.InitChain(types.RequestInitChain{RandVals(1)})
  30. }