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.

47 lines
1.5 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package consensus
  2. import (
  3. "sort"
  4. . "github.com/tendermint/tendermint/block"
  5. db_ "github.com/tendermint/tendermint/db"
  6. mempool_ "github.com/tendermint/tendermint/mempool"
  7. "github.com/tendermint/tendermint/state"
  8. )
  9. // Common test methods
  10. func makeValidator(valInfo *state.ValidatorInfo) *state.Validator {
  11. return &state.Validator{
  12. Address: valInfo.Address,
  13. PubKey: valInfo.PubKey,
  14. BondHeight: 0,
  15. UnbondHeight: 0,
  16. LastCommitHeight: 0,
  17. VotingPower: valInfo.FirstBondAmount,
  18. Accum: 0,
  19. }
  20. }
  21. func randVoteSet(height uint, round uint, type_ byte, numValidators int, votingPower uint64) (*VoteSet, *state.ValidatorSet, []*state.PrivValidator) {
  22. vals := make([]*state.Validator, numValidators)
  23. privValidators := make([]*state.PrivValidator, numValidators)
  24. for i := 0; i < numValidators; i++ {
  25. valInfo, privValidator := state.RandValidator(false, votingPower)
  26. val := makeValidator(valInfo)
  27. vals[i] = val
  28. privValidators[i] = privValidator
  29. }
  30. valSet := state.NewValidatorSet(vals)
  31. sort.Sort(state.PrivValidatorsByAddress(privValidators))
  32. return NewVoteSet(height, round, type_, valSet), valSet, privValidators
  33. }
  34. func randConsensusState() (*ConsensusState, []*state.PrivValidator) {
  35. state, _, privValidators := state.RandGenesisState(20, false, 1000, 10, false, 1000)
  36. blockStore := NewBlockStore(db_.NewMemDB())
  37. mempool := mempool_.NewMempool(state)
  38. mempoolReactor := mempool_.NewMempoolReactor(mempool)
  39. cs := NewConsensusState(state, blockStore, mempoolReactor)
  40. return cs, privValidators
  41. }