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.

48 lines
1.2 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 TestPeerCatchupRounds(t *testing.T) {
  8. valSet, privVals := types.RandValidatorSet(10, 1)
  9. hvs := NewHeightVoteSet(1, valSet)
  10. vote999_0 := makeVoteHR(t, 1, 999, privVals[0])
  11. added, _, err := hvs.AddByIndex(0, vote999_0, "peer1")
  12. if !added || err != nil {
  13. t.Error("Expected to successfully add vote from peer", added, err)
  14. }
  15. vote1000_0 := makeVoteHR(t, 1, 1000, privVals[0])
  16. added, _, err = hvs.AddByIndex(0, vote1000_0, "peer1")
  17. if added {
  18. t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
  19. }
  20. added, _, err = hvs.AddByIndex(0, vote1000_0, "peer2")
  21. if !added || err != nil {
  22. t.Error("Expected to successfully add vote from another peer")
  23. }
  24. }
  25. func makeVoteHR(t *testing.T, height, round int, privVal *types.PrivValidator) *types.Vote {
  26. vote := &types.Vote{
  27. Height: height,
  28. Round: round,
  29. Type: types.VoteTypePrecommit,
  30. BlockHash: []byte("fakehash"),
  31. }
  32. chainID := config.GetString("chain_id")
  33. err := privVal.SignVote(chainID, vote)
  34. if err != nil {
  35. t.Fatalf("Error signing vote: %v", err)
  36. return nil
  37. }
  38. return vote
  39. }