Compare commits

...

3 Commits

Author SHA1 Message Date
Anton Kaliaev
54ba7769c2 Merge branch 'master' into tessr/nil-commit 2019-09-04 20:25:54 +04:00
Tess Rinearson
34aac2aee6 remove 2019-09-03 16:09:33 -07:00
Tess Rinearson
9c4cf401b5 types: add test for block commits with votes for the wrong blockID 2019-09-03 16:08:21 -07:00

View File

@@ -15,6 +15,7 @@ import (
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/tmhash"
cmn "github.com/tendermint/tendermint/libs/common"
tmtime "github.com/tendermint/tendermint/types/time"
"github.com/tendermint/tendermint/version"
)
@@ -367,6 +368,104 @@ func TestCommitToVoteSet(t *testing.T) {
}
}
func TestCommitToVoteSetWithBadVotes(t *testing.T) {
lastID := makeBlockIDRandom()
height := int64(3)
round := 1
numValidators := 10
voteSet, valSet, vals := randVoteSet(height-1, 1, PrecommitType, numValidators, 1)
// > 2/3 sign for this block
numBlockValidators := numValidators*2/3 + 1
for i := 0; i < numBlockValidators; i++ {
addr := vals[i].GetPubKey().Address()
vote := &Vote{
ValidatorAddress: addr,
ValidatorIndex: i,
Height: height - 1,
Round: round,
Type: PrecommitType,
BlockID: lastID,
Timestamp: tmtime.Now(),
}
_, err := signAddVote(vals[i], vote, voteSet)
assert.NoError(t, err)
}
// 1/3 vote for a different block
for i := numBlockValidators; i < numValidators; i++ {
addr := vals[i].GetPubKey().Address()
vote := &Vote{
ValidatorAddress: addr,
ValidatorIndex: i,
Height: height - 1,
Round: round,
Type: PrecommitType,
BlockID: makeBlockIDRandom(),
Timestamp: tmtime.Now(),
}
_, err := signAddVote(vals[i], vote, voteSet)
assert.NoError(t, err)
}
commit := voteSet.MakeCommit()
chainID := voteSet.ChainID()
voteSet2 := CommitToVoteSet(chainID, commit, valSet)
assert.NotNil(t, voteSet2)
}
func TestCommitToVoteSetWithNil(t *testing.T) {
lastID := makeBlockIDRandom()
height := int64(3)
round := 1
numValidators := 10
voteSet, valSet, vals := randVoteSet(height-1, 1, PrecommitType, numValidators, 1)
// > 2/3 sign for this block
numBlockValidators := numValidators*2/3 + 1
for i := 0; i < numBlockValidators; i++ {
addr := vals[i].GetPubKey().Address()
vote := &Vote{
ValidatorAddress: addr,
ValidatorIndex: i,
Height: height - 1,
Round: round,
Type: PrecommitType,
BlockID: lastID,
Timestamp: tmtime.Now(),
}
_, err := signAddVote(vals[i], vote, voteSet)
assert.NoError(t, err)
}
// 1/3 vote for a nil block
for i := numBlockValidators; i < numValidators; i++ {
addr := vals[i].GetPubKey().Address()
vote := &Vote{
ValidatorAddress: addr,
ValidatorIndex: i,
Height: height - 1,
Round: round,
Type: PrecommitType,
BlockID: BlockID{}, // "nil"
Timestamp: tmtime.Now(),
}
_, err := signAddVote(vals[i], vote, voteSet)
assert.NoError(t, err)
}
commit := voteSet.MakeCommit()
chainID := voteSet.ChainID()
voteSet2 := CommitToVoteSet(chainID, commit, valSet)
assert.NotNil(t, voteSet2)
}
func TestSignedHeaderValidateBasic(t *testing.T) {
commit := randCommit()
chainID := "𠜎"