mirror of
https://github.com/fluencelabs/tendermint
synced 2025-08-01 04:31:57 +00:00
Dot import -> named import
Changed modulename_ to short module names Also removed Unreader, replaced with PrefixdReader in select locations
This commit is contained in:
@@ -3,10 +3,10 @@ package consensus
|
||||
import (
|
||||
"bytes"
|
||||
|
||||
. "github.com/tendermint/tendermint/block"
|
||||
"github.com/tendermint/tendermint/block"
|
||||
. "github.com/tendermint/tendermint/common"
|
||||
. "github.com/tendermint/tendermint/common/test"
|
||||
"github.com/tendermint/tendermint/state"
|
||||
sm "github.com/tendermint/tendermint/state"
|
||||
|
||||
"testing"
|
||||
)
|
||||
@@ -14,41 +14,41 @@ import (
|
||||
// NOTE: see consensus/test.go for common test methods.
|
||||
|
||||
// Convenience: Return new vote with different height
|
||||
func withHeight(vote *Vote, height uint) *Vote {
|
||||
func withHeight(vote *block.Vote, height uint) *block.Vote {
|
||||
vote = vote.Copy()
|
||||
vote.Height = height
|
||||
return vote
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different round
|
||||
func withRound(vote *Vote, round uint) *Vote {
|
||||
func withRound(vote *block.Vote, round uint) *block.Vote {
|
||||
vote = vote.Copy()
|
||||
vote.Round = round
|
||||
return vote
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different type
|
||||
func withType(vote *Vote, type_ byte) *Vote {
|
||||
func withType(vote *block.Vote, type_ byte) *block.Vote {
|
||||
vote = vote.Copy()
|
||||
vote.Type = type_
|
||||
return vote
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different blockHash
|
||||
func withBlockHash(vote *Vote, blockHash []byte) *Vote {
|
||||
func withBlockHash(vote *block.Vote, blockHash []byte) *block.Vote {
|
||||
vote = vote.Copy()
|
||||
vote.BlockHash = blockHash
|
||||
return vote
|
||||
}
|
||||
|
||||
// Convenience: Return new vote with different blockParts
|
||||
func withBlockParts(vote *Vote, blockParts PartSetHeader) *Vote {
|
||||
func withBlockParts(vote *block.Vote, blockParts block.PartSetHeader) *block.Vote {
|
||||
vote = vote.Copy()
|
||||
vote.BlockParts = blockParts
|
||||
return vote
|
||||
}
|
||||
|
||||
func signAddVote(privVal *state.PrivValidator, vote *Vote, voteSet *VoteSet) (bool, error) {
|
||||
func signAddVote(privVal *sm.PrivValidator, vote *block.Vote, voteSet *VoteSet) (bool, error) {
|
||||
privVal.SignVoteUnsafe(vote)
|
||||
added, _, err := voteSet.Add(privVal.Address, vote)
|
||||
return added, err
|
||||
@@ -56,7 +56,7 @@ func signAddVote(privVal *state.PrivValidator, vote *Vote, voteSet *VoteSet) (bo
|
||||
|
||||
func TestAddVote(t *testing.T) {
|
||||
height, round := uint(1), uint(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypePrevote, 10, 1)
|
||||
val0 := privValidators[0]
|
||||
|
||||
// t.Logf(">> %v", voteSet)
|
||||
@@ -72,7 +72,7 @@ func TestAddVote(t *testing.T) {
|
||||
t.Errorf("There should be no 2/3 majority")
|
||||
}
|
||||
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypePrevote, BlockHash: nil}
|
||||
signAddVote(val0, vote, voteSet)
|
||||
|
||||
if voteSet.GetByAddress(val0.Address) == nil {
|
||||
@@ -89,9 +89,9 @@ func TestAddVote(t *testing.T) {
|
||||
|
||||
func Test2_3Majority(t *testing.T) {
|
||||
height, round := uint(1), uint(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypePrevote, 10, 1)
|
||||
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypePrevote, BlockHash: nil}
|
||||
|
||||
// 6 out of 10 voted for nil.
|
||||
for i := 0; i < 6; i++ {
|
||||
@@ -123,13 +123,13 @@ func Test2_3Majority(t *testing.T) {
|
||||
|
||||
func Test2_3MajorityRedux(t *testing.T) {
|
||||
height, round := uint(1), uint(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 100, 1)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypePrevote, 100, 1)
|
||||
|
||||
blockHash := CRandBytes(32)
|
||||
blockPartsTotal := uint(123)
|
||||
blockParts := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||
blockParts := block.PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: blockHash, BlockParts: blockParts}
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypePrevote, BlockHash: blockHash, BlockParts: blockParts}
|
||||
|
||||
// 66 out of 100 voted for nil.
|
||||
for i := 0; i < 66; i++ {
|
||||
@@ -151,7 +151,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
|
||||
// 68th validator voted for a different BlockParts PartSetHeader
|
||||
{
|
||||
blockParts := PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||
blockParts := block.PartSetHeader{blockPartsTotal, CRandBytes(32)}
|
||||
signAddVote(privValidators[67], withBlockParts(vote, blockParts), voteSet)
|
||||
hash, header, ok = voteSet.TwoThirdsMajority()
|
||||
if hash != nil || !header.IsZero() || ok {
|
||||
@@ -161,7 +161,7 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
|
||||
// 69th validator voted for different BlockParts Total
|
||||
{
|
||||
blockParts := PartSetHeader{blockPartsTotal + 1, blockParts.Hash}
|
||||
blockParts := block.PartSetHeader{blockPartsTotal + 1, blockParts.Hash}
|
||||
signAddVote(privValidators[68], withBlockParts(vote, blockParts), voteSet)
|
||||
hash, header, ok = voteSet.TwoThirdsMajority()
|
||||
if hash != nil || !header.IsZero() || ok {
|
||||
@@ -190,10 +190,10 @@ func Test2_3MajorityRedux(t *testing.T) {
|
||||
|
||||
func TestBadVotes(t *testing.T) {
|
||||
height, round := uint(1), uint(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypePrevote, 10, 1)
|
||||
|
||||
// val0 votes for nil.
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypePrevote, BlockHash: nil}
|
||||
added, err := signAddVote(privValidators[0], vote, voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected Add() to succeed")
|
||||
@@ -218,7 +218,7 @@ func TestBadVotes(t *testing.T) {
|
||||
}
|
||||
|
||||
// val3 votes of another type.
|
||||
added, err = signAddVote(privValidators[3], withType(vote, VoteTypePrecommit), voteSet)
|
||||
added, err = signAddVote(privValidators[3], withType(vote, block.VoteTypePrecommit), voteSet)
|
||||
if added {
|
||||
t.Errorf("Expected Add() to fail, wrong type")
|
||||
}
|
||||
@@ -226,10 +226,10 @@ func TestBadVotes(t *testing.T) {
|
||||
|
||||
func TestAddCommitsToPrevoteVotes(t *testing.T) {
|
||||
height, round := uint(2), uint(5)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypePrevote, 10, 1)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypePrevote, 10, 1)
|
||||
|
||||
// val0, val1, val2, val3, val4, val5 vote for nil.
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypePrevote, BlockHash: nil}
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypePrevote, BlockHash: nil}
|
||||
for i := 0; i < 6; i++ {
|
||||
signAddVote(privValidators[i], vote, voteSet)
|
||||
}
|
||||
@@ -239,35 +239,35 @@ func TestAddCommitsToPrevoteVotes(t *testing.T) {
|
||||
}
|
||||
|
||||
// Attempt to add a commit from val6 at a previous height
|
||||
vote = &Vote{Height: height - 1, Round: round, Type: VoteTypeCommit, BlockHash: nil}
|
||||
vote = &block.Vote{Height: height - 1, Round: round, Type: block.VoteTypeCommit, BlockHash: nil}
|
||||
added, _ := signAddVote(privValidators[6], vote, voteSet)
|
||||
if added {
|
||||
t.Errorf("Expected Add() to fail, wrong height.")
|
||||
}
|
||||
|
||||
// Attempt to add a commit from val6 at a later round
|
||||
vote = &Vote{Height: height, Round: round + 1, Type: VoteTypeCommit, BlockHash: nil}
|
||||
vote = &block.Vote{Height: height, Round: round + 1, Type: block.VoteTypeCommit, BlockHash: nil}
|
||||
added, _ = signAddVote(privValidators[6], vote, voteSet)
|
||||
if added {
|
||||
t.Errorf("Expected Add() to fail, cannot add future round vote.")
|
||||
}
|
||||
|
||||
// Attempt to add a commit from val6 for currrent height/round.
|
||||
vote = &Vote{Height: height, Round: round, Type: VoteTypeCommit, BlockHash: nil}
|
||||
vote = &block.Vote{Height: height, Round: round, Type: block.VoteTypeCommit, BlockHash: nil}
|
||||
added, err := signAddVote(privValidators[6], vote, voteSet)
|
||||
if added || err == nil {
|
||||
t.Errorf("Expected Add() to fail, only prior round commits can be added.")
|
||||
}
|
||||
|
||||
// Add commit from val6 at a previous round
|
||||
vote = &Vote{Height: height, Round: round - 1, Type: VoteTypeCommit, BlockHash: nil}
|
||||
vote = &block.Vote{Height: height, Round: round - 1, Type: block.VoteTypeCommit, BlockHash: nil}
|
||||
added, err = signAddVote(privValidators[6], vote, voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected Add() to succeed, commit for prior rounds are relevant.")
|
||||
}
|
||||
|
||||
// Also add commit from val7 for previous round.
|
||||
vote = &Vote{Height: height, Round: round - 2, Type: VoteTypeCommit, BlockHash: nil}
|
||||
vote = &block.Vote{Height: height, Round: round - 2, Type: block.VoteTypeCommit, BlockHash: nil}
|
||||
added, err = signAddVote(privValidators[7], vote, voteSet)
|
||||
if !added || err != nil {
|
||||
t.Errorf("Expected Add() to succeed. err: %v", err)
|
||||
@@ -283,10 +283,10 @@ func TestAddCommitsToPrevoteVotes(t *testing.T) {
|
||||
|
||||
func TestMakeValidation(t *testing.T) {
|
||||
height, round := uint(1), uint(0)
|
||||
voteSet, _, privValidators := randVoteSet(height, round, VoteTypeCommit, 10, 1)
|
||||
blockHash, blockParts := CRandBytes(32), PartSetHeader{123, CRandBytes(32)}
|
||||
voteSet, _, privValidators := randVoteSet(height, round, block.VoteTypeCommit, 10, 1)
|
||||
blockHash, blockParts := CRandBytes(32), block.PartSetHeader{123, CRandBytes(32)}
|
||||
|
||||
vote := &Vote{Height: height, Round: round, Type: VoteTypeCommit,
|
||||
vote := &block.Vote{Height: height, Round: round, Type: block.VoteTypeCommit,
|
||||
BlockHash: blockHash, BlockParts: blockParts}
|
||||
|
||||
// 6 out of 10 voted for some block.
|
||||
@@ -300,7 +300,7 @@ func TestMakeValidation(t *testing.T) {
|
||||
// 7th voted for some other block.
|
||||
{
|
||||
vote := withBlockHash(vote, RandBytes(32))
|
||||
vote = withBlockParts(vote, PartSetHeader{123, RandBytes(32)})
|
||||
vote = withBlockParts(vote, block.PartSetHeader{123, RandBytes(32)})
|
||||
signAddVote(privValidators[6], vote, voteSet)
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user