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.

53 lines
1.4 KiB

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