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.

56 lines
1.5 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.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 {
  22. t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
  23. }
  24. added, err = hvs.AddVote(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, privVals []*types.PrivValidator, valIndex int) *types.Vote {
  30. privVal := privVals[valIndex]
  31. vote := &types.Vote{
  32. ValidatorAddress: privVal.Address,
  33. ValidatorIndex: valIndex,
  34. Height: height,
  35. Round: round,
  36. Type: types.VoteTypePrecommit,
  37. BlockID: types.BlockID{[]byte("fakehash"), types.PartSetHeader{}},
  38. }
  39. chainID := config.GetString("chain_id")
  40. err := privVal.SignVote(chainID, vote)
  41. if err != nil {
  42. panic(Fmt("Error signing vote: %v", err))
  43. return nil
  44. }
  45. return vote
  46. }