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.

64 lines
1.7 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 err != nil {
  26. t.Error("AddVote error", err)
  27. }
  28. if added {
  29. t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
  30. }
  31. added, err = hvs.AddVote(vote1001_0, "peer2")
  32. if !added || err != nil {
  33. t.Error("Expected to successfully add vote from another peer")
  34. }
  35. }
  36. func makeVoteHR(t *testing.T, height, round int, privVals []*types.PrivValidator, valIndex int) *types.Vote {
  37. privVal := privVals[valIndex]
  38. vote := &types.Vote{
  39. ValidatorAddress: privVal.Address,
  40. ValidatorIndex: valIndex,
  41. Height: height,
  42. Round: round,
  43. Type: types.VoteTypePrecommit,
  44. BlockID: types.BlockID{[]byte("fakehash"), types.PartSetHeader{}},
  45. }
  46. chainID := config.ChainID
  47. err := privVal.SignVote(chainID, vote)
  48. if err != nil {
  49. panic(Fmt("Error signing vote: %v", err))
  50. return nil
  51. }
  52. return vote
  53. }