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.

52 lines
1.3 KiB

  1. package consensus
  2. import (
  3. "github.com/tendermint/tendermint/config/tendermint_test"
  4. "github.com/tendermint/tendermint/types"
  5. "testing"
  6. )
  7. func init() {
  8. tendermint_test.ResetConfig("consensus_height_vote_set_test")
  9. }
  10. func TestPeerCatchupRounds(t *testing.T) {
  11. valSet, privVals := types.RandValidatorSet(10, 1)
  12. hvs := NewHeightVoteSet(1, valSet)
  13. vote999_0 := makeVoteHR(t, 1, 999, privVals[0])
  14. added, _, err := hvs.AddByIndex(0, 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.AddByIndex(0, vote1000_0, "peer1")
  20. if added {
  21. t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
  22. }
  23. added, _, err = hvs.AddByIndex(0, vote1000_0, "peer2")
  24. if !added || err != nil {
  25. t.Error("Expected to successfully add vote from another peer")
  26. }
  27. }
  28. func makeVoteHR(t *testing.T, height, round int, privVal *types.PrivValidator) *types.Vote {
  29. vote := &types.Vote{
  30. Height: height,
  31. Round: round,
  32. Type: types.VoteTypePrecommit,
  33. BlockHash: []byte("fakehash"),
  34. }
  35. chainID := config.GetString("chain_id")
  36. err := privVal.SignVote(chainID, vote)
  37. if err != nil {
  38. t.Fatalf("Error signing vote: %v", err)
  39. return nil
  40. }
  41. return vote
  42. }