2015-12-31 15:02:38 -08:00
|
|
|
package consensus
|
|
|
|
|
|
|
|
import (
|
2016-07-11 21:10:05 -04:00
|
|
|
"testing"
|
|
|
|
|
2015-12-31 15:02:38 -08:00
|
|
|
"github.com/tendermint/tendermint/types"
|
2017-05-02 00:43:49 -04: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-02 00:43:49 -04: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-02 00:43:49 -04:00
|
|
|
hvs := NewHeightVoteSet(config.ChainID, 1, valSet)
|
2015-12-31 15:02:38 -08:00
|
|
|
|
2016-07-01 17:47:31 -04: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 17:47:31 -04: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 23:11:40 -04: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")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-07-01 17:47:31 -04:00
|
|
|
func makeVoteHR(t *testing.T, height, round int, privVals []*types.PrivValidator, valIndex int) *types.Vote {
|
|
|
|
privVal := privVals[valIndex]
|
2015-12-31 15:02:38 -08:00
|
|
|
vote := &types.Vote{
|
2016-07-01 17:47:31 -04:00
|
|
|
ValidatorAddress: privVal.Address,
|
|
|
|
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-02 00:43:49 -04:00
|
|
|
chainID := config.ChainID
|
2015-12-31 15:02:38 -08:00
|
|
|
err := privVal.SignVote(chainID, vote)
|
|
|
|
if err != nil {
|
2016-07-11 21:10:05 -04:00
|
|
|
panic(Fmt("Error signing vote: %v", err))
|
2015-12-31 15:02:38 -08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return vote
|
|
|
|
}
|