mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-01 09:42:12 +00:00
49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
|
package consensus
|
||
|
|
||
|
import (
|
||
|
_ "github.com/tendermint/tendermint/config/tendermint_test"
|
||
|
"github.com/tendermint/tendermint/types"
|
||
|
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestPeerCatchupRounds(t *testing.T) {
|
||
|
valSet, privVals := types.RandValidatorSet(10, 1)
|
||
|
|
||
|
hvs := NewHeightVoteSet(1, valSet)
|
||
|
|
||
|
vote999_0 := makeVoteHR(t, 1, 999, privVals[0])
|
||
|
added, _, err := hvs.AddByIndex(0, vote999_0, "peer1")
|
||
|
if !added || err != nil {
|
||
|
t.Error("Expected to successfully add vote from peer", added, err)
|
||
|
}
|
||
|
|
||
|
vote1000_0 := makeVoteHR(t, 1, 1000, privVals[0])
|
||
|
added, _, err = hvs.AddByIndex(0, vote1000_0, "peer1")
|
||
|
if added {
|
||
|
t.Error("Expected to *not* add vote from peer, too many catchup rounds.")
|
||
|
}
|
||
|
|
||
|
added, _, err = hvs.AddByIndex(0, vote1000_0, "peer2")
|
||
|
if !added || err != nil {
|
||
|
t.Error("Expected to successfully add vote from another peer")
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
func makeVoteHR(t *testing.T, height, round int, privVal *types.PrivValidator) *types.Vote {
|
||
|
vote := &types.Vote{
|
||
|
Height: height,
|
||
|
Round: round,
|
||
|
Type: types.VoteTypePrecommit,
|
||
|
BlockHash: []byte("fakehash"),
|
||
|
}
|
||
|
chainID := config.GetString("chain_id")
|
||
|
err := privVal.SignVote(chainID, vote)
|
||
|
if err != nil {
|
||
|
t.Fatalf("Error signing vote: %v", err)
|
||
|
return nil
|
||
|
}
|
||
|
return vote
|
||
|
}
|