|
|
@ -126,7 +126,10 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
// 6 out of 10 voted for nil.
|
|
|
|
for i := 0; i < 6; i++ { |
|
|
|
vote := withValidator(voteProto, privValidators[i].GetAddress(), i) |
|
|
|
signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[i], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
@ -136,7 +139,10 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
// 7th validator voted for some blockhash
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[6].GetAddress(), 6) |
|
|
|
signAddVote(privValidators[6], withBlockHash(vote, cmn.RandBytes(32)), voteSet) |
|
|
|
_, err := signAddVote(privValidators[6], withBlockHash(vote, cmn.RandBytes(32)), voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority") |
|
|
@ -146,7 +152,10 @@ func Test2_3Majority(t *testing.T) { |
|
|
|
// 8th validator voted for nil.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[7].GetAddress(), 7) |
|
|
|
signAddVote(privValidators[7], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[7], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if !ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be 2/3 majority for nil") |
|
|
@ -174,7 +183,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
// 66 out of 100 voted for nil.
|
|
|
|
for i := 0; i < 66; i++ { |
|
|
|
vote := withValidator(voteProto, privValidators[i].GetAddress(), i) |
|
|
|
signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[i], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
@ -184,7 +196,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
// 67th validator voted for nil
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[66].GetAddress(), 66) |
|
|
|
signAddVote(privValidators[66], withBlockHash(vote, nil), voteSet) |
|
|
|
_, err := signAddVote(privValidators[66], withBlockHash(vote, nil), voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added was nil") |
|
|
@ -195,7 +210,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[67].GetAddress(), 67) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)} |
|
|
|
signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
_, err := signAddVote(privValidators[67], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Hash") |
|
|
@ -206,7 +224,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[68].GetAddress(), 68) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartsHeader.Hash} |
|
|
|
signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
_, err := signAddVote(privValidators[68], withBlockPartsHeader(vote, blockPartsHeader), voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different PartSetHeader Total") |
|
|
@ -216,7 +237,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
// 70th validator voted for different BlockHash
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[69].GetAddress(), 69) |
|
|
|
signAddVote(privValidators[69], withBlockHash(vote, cmn.RandBytes(32)), voteSet) |
|
|
|
_, err := signAddVote(privValidators[69], withBlockHash(vote, cmn.RandBytes(32)), voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if ok || !blockID.IsZero() { |
|
|
|
t.Errorf("There should be no 2/3 majority: last vote added had different BlockHash") |
|
|
@ -226,7 +250,10 @@ func Test2_3MajorityRedux(t *testing.T) { |
|
|
|
// 71st validator voted for the right BlockHash & BlockPartsHeader
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[70].GetAddress(), 70) |
|
|
|
signAddVote(privValidators[70], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[70], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
if !ok || !blockID.Equals(BlockID{blockHash, blockPartsHeader}) { |
|
|
|
t.Errorf("There should be 2/3 majority") |
|
|
@ -439,7 +466,10 @@ func TestMakeCommit(t *testing.T) { |
|
|
|
// 6 out of 10 voted for some block.
|
|
|
|
for i := 0; i < 6; i++ { |
|
|
|
vote := withValidator(voteProto, privValidators[i].GetAddress(), i) |
|
|
|
signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[i], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// MakeCommit should fail.
|
|
|
@ -450,13 +480,20 @@ func TestMakeCommit(t *testing.T) { |
|
|
|
vote := withValidator(voteProto, privValidators[6].GetAddress(), 6) |
|
|
|
vote = withBlockHash(vote, cmn.RandBytes(32)) |
|
|
|
vote = withBlockPartsHeader(vote, PartSetHeader{123, cmn.RandBytes(32)}) |
|
|
|
signAddVote(privValidators[6], vote, voteSet) |
|
|
|
|
|
|
|
_, err := signAddVote(privValidators[6], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// The 8th voted like everyone else.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, privValidators[7].GetAddress(), 7) |
|
|
|
signAddVote(privValidators[7], vote, voteSet) |
|
|
|
_, err := signAddVote(privValidators[7], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
commit := voteSet.MakeCommit() |
|
|
|