|
|
@ -16,11 +16,14 @@ import ( |
|
|
|
) |
|
|
|
|
|
|
|
func TestVoteSet_AddVote_Good(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
val0 := privValidators[0] |
|
|
|
|
|
|
|
val0p, err := val0.GetPubKey(context.Background()) |
|
|
|
val0p, err := val0.GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
val0Addr := val0p.Address() |
|
|
|
|
|
|
@ -38,7 +41,7 @@ func TestVoteSet_AddVote_Good(t *testing.T) { |
|
|
|
Timestamp: tmtime.Now(), |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
_, err = signAddVote(val0, vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, val0, vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
assert.NotNil(t, voteSet.GetByAddress(val0Addr)) |
|
|
@ -48,8 +51,11 @@ func TestVoteSet_AddVote_Good(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
|
|
|
|
voteProto := &Vote{ |
|
|
|
ValidatorAddress: nil, |
|
|
@ -63,11 +69,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
|
|
|
|
// val0 votes for nil.
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[0].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[0].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], vote, voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], vote, voteSet) |
|
|
|
if !added || err != nil { |
|
|
|
t.Errorf("expected VoteSet.Add to succeed") |
|
|
|
} |
|
|
@ -75,11 +81,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
|
|
|
|
// val0 votes again for some block.
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[0].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[0].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
if added || err == nil { |
|
|
|
t.Errorf("expected VoteSet.Add to fail, conflicting vote.") |
|
|
|
} |
|
|
@ -87,11 +93,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
|
|
|
|
// val1 votes on another height
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[1].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[1].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 1) |
|
|
|
added, err := signAddVote(privValidators[1], withHeight(vote, height+1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[1], withHeight(vote, height+1), voteSet) |
|
|
|
if added || err == nil { |
|
|
|
t.Errorf("expected VoteSet.Add to fail, wrong height") |
|
|
|
} |
|
|
@ -99,11 +105,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
|
|
|
|
// val2 votes on another round
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[2].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[2].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 2) |
|
|
|
added, err := signAddVote(privValidators[2], withRound(vote, round+1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[2], withRound(vote, round+1), voteSet) |
|
|
|
if added || err == nil { |
|
|
|
t.Errorf("expected VoteSet.Add to fail, wrong round") |
|
|
|
} |
|
|
@ -111,11 +117,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
|
|
|
|
// val3 votes of another type.
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[3].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[3].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 3) |
|
|
|
added, err := signAddVote(privValidators[3], withType(vote, byte(tmproto.PrecommitType)), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[3], withType(vote, byte(tmproto.PrecommitType)), voteSet) |
|
|
|
if added || err == nil { |
|
|
|
t.Errorf("expected VoteSet.Add to fail, wrong type") |
|
|
|
} |
|
|
@ -123,8 +129,11 @@ func TestVoteSet_AddVote_Bad(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestVoteSet_2_3Majority(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrevoteType, 10, 1) |
|
|
|
|
|
|
|
voteProto := &Vote{ |
|
|
|
ValidatorAddress: nil, // NOTE: must fill in
|
|
|
@ -137,11 +146,11 @@ func TestVoteSet_2_3Majority(t *testing.T) { |
|
|
|
} |
|
|
|
// 6 out of 10 voted for nil.
|
|
|
|
for i := int32(0); i < 6; i++ { |
|
|
|
pubKey, err := privValidators[i].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[i].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, i) |
|
|
|
_, err = signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[i], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
@ -149,11 +158,11 @@ func TestVoteSet_2_3Majority(t *testing.T) { |
|
|
|
|
|
|
|
// 7th validator voted for some blockhash
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[6].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[6].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 6) |
|
|
|
_, err = signAddVote(privValidators[6], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[6], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.False(t, ok || !blockID.IsZero(), "there should be no 2/3 majority") |
|
|
@ -161,11 +170,11 @@ func TestVoteSet_2_3Majority(t *testing.T) { |
|
|
|
|
|
|
|
// 8th validator voted for nil.
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[7].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[7].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 7) |
|
|
|
_, err = signAddVote(privValidators[7], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[7], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.True(t, ok || blockID.IsZero(), "there should be 2/3 majority for nil") |
|
|
@ -173,8 +182,11 @@ func TestVoteSet_2_3Majority(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 100, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrevoteType, 100, 1) |
|
|
|
|
|
|
|
blockHash := crypto.CRandBytes(32) |
|
|
|
blockPartsTotal := uint32(123) |
|
|
@ -192,11 +204,11 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 66 out of 100 voted for nil.
|
|
|
|
for i := int32(0); i < 66; i++ { |
|
|
|
pubKey, err := privValidators[i].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[i].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, i) |
|
|
|
_, err = signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[i], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
blockID, ok := voteSet.TwoThirdsMajority() |
|
|
@ -205,11 +217,11 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 67th validator voted for nil
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[66].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[66].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
adrr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, adrr, 66) |
|
|
|
_, err = signAddVote(privValidators[66], withBlockHash(vote, nil), voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[66], withBlockHash(vote, nil), voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.False(t, ok || !blockID.IsZero(), |
|
|
@ -218,12 +230,12 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 68th validator voted for a different BlockParts PartSetHeader
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[67].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[67].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 67) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal, crypto.CRandBytes(32)} |
|
|
|
_, err = signAddVote(privValidators[67], withBlockPartSetHeader(vote, blockPartsHeader), voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[67], withBlockPartSetHeader(vote, blockPartsHeader), voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.False(t, ok || !blockID.IsZero(), |
|
|
@ -232,12 +244,12 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 69th validator voted for different BlockParts Total
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[68].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[68].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 68) |
|
|
|
blockPartsHeader := PartSetHeader{blockPartsTotal + 1, blockPartSetHeader.Hash} |
|
|
|
_, err = signAddVote(privValidators[68], withBlockPartSetHeader(vote, blockPartsHeader), voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[68], withBlockPartSetHeader(vote, blockPartsHeader), voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.False(t, ok || !blockID.IsZero(), |
|
|
@ -246,11 +258,11 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 70th validator voted for different BlockHash
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[69].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[69].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 69) |
|
|
|
_, err = signAddVote(privValidators[69], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[69], withBlockHash(vote, tmrand.Bytes(32)), voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.False(t, ok || !blockID.IsZero(), |
|
|
@ -259,11 +271,11 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
|
|
|
|
// 71st validator voted for the right BlockHash & BlockPartSetHeader
|
|
|
|
{ |
|
|
|
pubKey, err := privValidators[70].GetPubKey(context.Background()) |
|
|
|
pubKey, err := privValidators[70].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
addr := pubKey.Address() |
|
|
|
vote := withValidator(voteProto, addr, 70) |
|
|
|
_, err = signAddVote(privValidators[70], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[70], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
blockID, ok = voteSet.TwoThirdsMajority() |
|
|
|
assert.True(t, ok && blockID.Equals(BlockID{blockHash, blockPartSetHeader}), |
|
|
@ -272,8 +284,11 @@ func TestVoteSet_2_3MajorityRedux(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrevoteType, 4, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrevoteType, 4, 1) |
|
|
|
blockHash1 := tmrand.Bytes(32) |
|
|
|
blockHash2 := tmrand.Bytes(32) |
|
|
|
|
|
|
@ -287,14 +302,14 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
BlockID: BlockID{nil, PartSetHeader{}}, |
|
|
|
} |
|
|
|
|
|
|
|
val0, err := privValidators[0].GetPubKey(context.Background()) |
|
|
|
val0, err := privValidators[0].GetPubKey(ctx) |
|
|
|
require.NoError(t, err) |
|
|
|
val0Addr := val0.Address() |
|
|
|
|
|
|
|
// val0 votes for nil.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, val0Addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], vote, voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], vote, voteSet) |
|
|
|
if !added || err != nil { |
|
|
|
t.Errorf("expected VoteSet.Add to succeed") |
|
|
|
} |
|
|
@ -303,7 +318,7 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
// val0 votes again for blockHash1.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, val0Addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
assert.False(t, added, "conflicting vote") |
|
|
|
assert.Error(t, err, "conflicting vote") |
|
|
|
} |
|
|
@ -315,7 +330,7 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
// val0 votes again for blockHash1.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, val0Addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
assert.True(t, added, "called SetPeerMaj23()") |
|
|
|
assert.Error(t, err, "conflicting vote") |
|
|
|
} |
|
|
@ -327,18 +342,18 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
// val0 votes again for blockHash1.
|
|
|
|
{ |
|
|
|
vote := withValidator(voteProto, val0Addr, 0) |
|
|
|
added, err := signAddVote(privValidators[0], withBlockHash(vote, blockHash2), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[0], withBlockHash(vote, blockHash2), voteSet) |
|
|
|
assert.False(t, added, "duplicate SetPeerMaj23() from peerA") |
|
|
|
assert.Error(t, err, "conflicting vote") |
|
|
|
} |
|
|
|
|
|
|
|
// val1 votes for blockHash1.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[1].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[1].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 1) |
|
|
|
added, err := signAddVote(privValidators[1], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[1], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
if !added || err != nil { |
|
|
|
t.Errorf("expected VoteSet.Add to succeed") |
|
|
|
} |
|
|
@ -354,11 +369,11 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
|
|
|
|
// val2 votes for blockHash2.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[2].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[2].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 2) |
|
|
|
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash2), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[2], withBlockHash(vote, blockHash2), voteSet) |
|
|
|
if !added || err != nil { |
|
|
|
t.Errorf("expected VoteSet.Add to succeed") |
|
|
|
} |
|
|
@ -378,11 +393,11 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
|
|
|
|
// val2 votes for blockHash1.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[2].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[2].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 2) |
|
|
|
added, err := signAddVote(privValidators[2], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
added, err := signAddVote(ctx, privValidators[2], withBlockHash(vote, blockHash1), voteSet) |
|
|
|
assert.True(t, added) |
|
|
|
assert.Error(t, err, "conflicting vote") |
|
|
|
} |
|
|
@ -401,8 +416,11 @@ func TestVoteSet_Conflicts(t *testing.T) { |
|
|
|
} |
|
|
|
|
|
|
|
func TestVoteSet_MakeCommit(t *testing.T) { |
|
|
|
ctx, cancel := context.WithCancel(context.Background()) |
|
|
|
defer cancel() |
|
|
|
|
|
|
|
height, round := int64(1), int32(0) |
|
|
|
voteSet, _, privValidators := randVoteSet(height, round, tmproto.PrecommitType, 10, 1) |
|
|
|
voteSet, _, privValidators := randVoteSet(ctx, t, height, round, tmproto.PrecommitType, 10, 1) |
|
|
|
blockHash, blockPartSetHeader := crypto.CRandBytes(32), PartSetHeader{123, crypto.CRandBytes(32)} |
|
|
|
|
|
|
|
voteProto := &Vote{ |
|
|
@ -417,11 +435,11 @@ func TestVoteSet_MakeCommit(t *testing.T) { |
|
|
|
|
|
|
|
// 6 out of 10 voted for some block.
|
|
|
|
for i := int32(0); i < 6; i++ { |
|
|
|
pv, err := privValidators[i].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[i].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, i) |
|
|
|
_, err = signAddVote(privValidators[i], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[i], vote, voteSet) |
|
|
|
if err != nil { |
|
|
|
t.Error(err) |
|
|
|
} |
|
|
@ -432,36 +450,36 @@ func TestVoteSet_MakeCommit(t *testing.T) { |
|
|
|
|
|
|
|
// 7th voted for some other block.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[6].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[6].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 6) |
|
|
|
vote = withBlockHash(vote, tmrand.Bytes(32)) |
|
|
|
vote = withBlockPartSetHeader(vote, PartSetHeader{123, tmrand.Bytes(32)}) |
|
|
|
|
|
|
|
_, err = signAddVote(privValidators[6], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[6], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
|
// The 8th voted like everyone else.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[7].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[7].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 7) |
|
|
|
_, err = signAddVote(privValidators[7], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[7], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
|
// The 9th voted for nil.
|
|
|
|
{ |
|
|
|
pv, err := privValidators[8].GetPubKey(context.Background()) |
|
|
|
pv, err := privValidators[8].GetPubKey(ctx) |
|
|
|
assert.NoError(t, err) |
|
|
|
addr := pv.Address() |
|
|
|
vote := withValidator(voteProto, addr, 8) |
|
|
|
vote.BlockID = BlockID{} |
|
|
|
|
|
|
|
_, err = signAddVote(privValidators[8], vote, voteSet) |
|
|
|
_, err = signAddVote(ctx, privValidators[8], vote, voteSet) |
|
|
|
require.NoError(t, err) |
|
|
|
} |
|
|
|
|
|
|
@ -478,13 +496,15 @@ func TestVoteSet_MakeCommit(t *testing.T) { |
|
|
|
|
|
|
|
// NOTE: privValidators are in order
|
|
|
|
func randVoteSet( |
|
|
|
ctx context.Context, |
|
|
|
t testing.TB, |
|
|
|
height int64, |
|
|
|
round int32, |
|
|
|
signedMsgType tmproto.SignedMsgType, |
|
|
|
numValidators int, |
|
|
|
votingPower int64, |
|
|
|
) (*VoteSet, *ValidatorSet, []PrivValidator) { |
|
|
|
valSet, privValidators := randValidatorPrivValSet(numValidators, votingPower) |
|
|
|
valSet, privValidators := randValidatorPrivValSet(ctx, t, numValidators, votingPower) |
|
|
|
return NewVoteSet("test_chain_id", height, round, signedMsgType, valSet), valSet, privValidators |
|
|
|
} |
|
|
|
|
|
|
@ -499,14 +519,15 @@ func deterministicVoteSet( |
|
|
|
return NewVoteSet("test_chain_id", height, round, signedMsgType, valSet), valSet, privValidators |
|
|
|
} |
|
|
|
|
|
|
|
func randValidatorPrivValSet(numValidators int, votingPower int64) (*ValidatorSet, []PrivValidator) { |
|
|
|
func randValidatorPrivValSet(ctx context.Context, t testing.TB, numValidators int, votingPower int64) (*ValidatorSet, []PrivValidator) { |
|
|
|
var ( |
|
|
|
valz = make([]*Validator, numValidators) |
|
|
|
privValidators = make([]PrivValidator, numValidators) |
|
|
|
) |
|
|
|
|
|
|
|
for i := 0; i < numValidators; i++ { |
|
|
|
val, privValidator := randValidator(false, votingPower) |
|
|
|
val, privValidator, err := randValidator(ctx, false, votingPower) |
|
|
|
require.NoError(t, err) |
|
|
|
valz[i] = val |
|
|
|
privValidators[i] = privValidator |
|
|
|
} |
|
|
|