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.

62 lines
1.7 KiB

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