mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-16 21:01:59 +00:00
Compare commits
3 Commits
master
...
tessr/nil-
Author | SHA1 | Date | |
---|---|---|---|
|
54ba7769c2 | ||
|
34aac2aee6 | ||
|
9c4cf401b5 |
@@ -15,6 +15,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/crypto/tmhash"
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
||||||
cmn "github.com/tendermint/tendermint/libs/common"
|
cmn "github.com/tendermint/tendermint/libs/common"
|
||||||
|
tmtime "github.com/tendermint/tendermint/types/time"
|
||||||
"github.com/tendermint/tendermint/version"
|
"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) {
|
func TestSignedHeaderValidateBasic(t *testing.T) {
|
||||||
commit := randCommit()
|
commit := randCommit()
|
||||||
chainID := "𠜎"
|
chainID := "𠜎"
|
||||||
|
Reference in New Issue
Block a user