2015-12-31 15:02:38 -08:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
2016-07-11 18:10:05 -07:00
|
|
|
"testing"
|
|
|
|
|
2015-12-31 15:02:38 -08:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2017-05-01 21:43:49 -07:00
|
|
|
. "github.com/tendermint/tmlibs/common"
|
2015-12-31 15:02:38 -08:00
|
|
|
)
|
|
|
|
|
2016-03-06 15:05:50 -08:00
|
|
|
func init() {
|
2017-05-01 21:43:49 -07:00
|
|
|
config = ResetConfig("consensus_height_vote_set_test")
|
2016-03-06 15:05:50 -08:00
|
|
|
}
|
|
|
|
|
2015-12-31 15:02:38 -08:00
|
|
|
func TestPeerCatchupRounds(t *testing.T) {
|
|
|
|
valSet, privVals := types.RandValidatorSet(10, 1)
|
|
|
|
|
2017-05-01 21:43:49 -07:00
|
|
|
hvs := NewHeightVoteSet(config.ChainID, 1, valSet)
|
2015-12-31 15:02:38 -08:00
|
|
|
|
2016-07-01 14:47:31 -07:00
|
|
|
vote999_0 := makeVoteHR(t, 1, 999, privVals, 0)
|
|
|
|
added, err := hvs.AddVote(vote999_0, "peer1")
|
2015-12-31 15:02:38 -08:00
|
|
|
if !added || err != nil {
|
|
|
|
t.Error("Expected to successfully add vote from peer", added, err)
|
|
|
|
}
|
|
|
|
|
2016-07-01 14:47:31 -07:00
|
|
|
vote1000_0 := makeVoteHR(t, 1, 1000, privVals, 0)
|
|
|
|
added, err = hvs.AddVote(vote1000_0, "peer1")
|
2016-09-16 09:20:07 -07:00
|
|
|
if !added || err != nil {
|
|
|
|
t.Error("Expected to successfully add vote from peer", added, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
vote1001_0 := makeVoteHR(t, 1, 1001, privVals, 0)
|
|
|
|
added, err = hvs.AddVote(vote1001_0, "peer1")
|
2017-05-29 20:11:40 -07:00
|
|
|
if err != nil {
|
|
|
|
t.Error("AddVote error", err)
|
|
|
|
}
|
2015-12-31 15:02:38 -08:00
|
|
|
if added {
|
|
|
|
t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
|
|
|
|
}
|
|
|
|
|
2016-09-16 09:20:07 -07:00
|
|
|
added, err = hvs.AddVote(vote1001_0, "peer2")
|
2015-12-31 15:02:38 -08:00
|
|
|
if !added || err != nil {
|
|
|
|
t.Error("Expected to successfully add vote from another peer")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2017-09-18 20:16:14 -07:00
|
|
|
func makeVoteHR(t *testing.T, height, round int, privVals []*types.PrivValidatorFS, valIndex int) *types.Vote {
|
2016-07-01 14:47:31 -07:00
|
|
|
privVal := privVals[valIndex]
|
2015-12-31 15:02:38 -08:00
|
|
|
vote := &types.Vote{
|
2017-09-21 13:32:02 -07:00
|
|
|
ValidatorAddress: privVal.GetAddress(),
|
2016-07-01 14:47:31 -07:00
|
|
|
ValidatorIndex: valIndex,
|
|
|
|
Height: height,
|
|
|
|
Round: round,
|
|
|
|
Type: types.VoteTypePrecommit,
|
2016-08-16 14:59:19 -07:00
|
|
|
BlockID: types.BlockID{[]byte("fakehash"), types.PartSetHeader{}},
|
2015-12-31 15:02:38 -08:00
|
|
|
}
|
2017-05-01 21:43:49 -07:00
|
|
|
chainID := config.ChainID
|
2015-12-31 15:02:38 -08:00
|
|
|
err := privVal.SignVote(chainID, vote)
|
|
|
|
if err != nil {
|
2016-07-11 18:10:05 -07:00
|
|
|
panic(Fmt("Error signing vote: %v", err))
|
2015-12-31 15:02:38 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return vote
|
|
|
|
}
|