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.

61 lines
1.6 KiB

  1. package consensus
  2. import (
  3. "testing"
  4. "github.com/tendermint/tendermint/types"
  5. . "github.com/tendermint/tmlibs/common"
  6. )
  7. func init() {
  8. config = ResetConfig("consensus_height_vote_set_test")
  9. }
  10. func TestPeerCatchupRounds(t *testing.T) {
  11. valSet, privVals := types.RandValidatorSet(10, 1)
  12. hvs := NewHeightVoteSet(config.ChainID, 1, valSet)
  13. vote999_0 := makeVoteHR(t, 1, 999, privVals, 0)
  14. added, err := hvs.AddVote(vote999_0, "peer1")
  15. if !added || err != nil {
  16. t.Error("Expected to successfully add vote from peer", added, err)
  17. }
  18. vote1000_0 := makeVoteHR(t, 1, 1000, privVals, 0)
  19. added, err = hvs.AddVote(vote1000_0, "peer1")
  20. if !added || err != nil {
  21. t.Error("Expected to successfully add vote from peer", added, err)
  22. }
  23. vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0)
  24. added, err = hvs.AddVote(vote1001_0, "peer1")
  25. if added {
  26. t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
  27. }
  28. added, err = hvs.AddVote(vote1001_0, "peer2")
  29. if !added || err != nil {
  30. t.Error("Expected to successfully add vote from another peer")
  31. }
  32. }
  33. func makeVoteHR(t *testing.T, height, round int, privVals []*types.PrivValidator, valIndex int) *types.Vote {
  34. privVal := privVals[valIndex]
  35. vote := &types.Vote{
  36. ValidatorAddress: privVal.Address,
  37. ValidatorIndex: valIndex,
  38. Height: height,
  39. Round: round,
  40. Type: types.VoteTypePrecommit,
  41. BlockID: types.BlockID{[]byte("fakehash"), types.PartSetHeader{}},
  42. }
  43. chainID := config.ChainID
  44. err := privVal.SignVote(chainID, vote)
  45. if err != nil {
  46. panic(Fmt("Error signing vote: %v", err))
  47. return nil
  48. }
  49. return vote
  50. }