@ -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"
)
)
@ -372,6 +373,63 @@ func TestCommitToVoteSet(t *testing.T) {
}
}
}
}
func TestCommitToVoteSetWithVotesForAnotherBlockOrNilBlock ( t * testing . T ) {
blockID := makeBlockID ( [ ] byte ( "blockhash" ) , 1000 , [ ] byte ( "partshash" ) )
blockID2 := makeBlockID ( [ ] byte ( "blockhash2" ) , 1000 , [ ] byte ( "partshash" ) )
blockID3 := makeBlockID ( [ ] byte ( "blockhash3" ) , 10000 , [ ] byte ( "partshash" ) )
height := int64 ( 3 )
round := 1
type commitVoteTest struct {
blockIDs [ ] BlockID
numVotes [ ] int // must sum to numValidators
numValidators int
valid bool
}
testCases := [ ] commitVoteTest {
{ [ ] BlockID { blockID , blockID2 , blockID3 } , [ ] int { 8 , 1 , 1 } , 10 , true } ,
{ [ ] BlockID { blockID , blockID2 , blockID3 } , [ ] int { 67 , 20 , 13 } , 100 , true } ,
{ [ ] BlockID { blockID , blockID2 , blockID3 } , [ ] int { 1 , 1 , 1 } , 3 , false } ,
{ [ ] BlockID { blockID , blockID2 , blockID3 } , [ ] int { 3 , 1 , 1 } , 5 , false } ,
{ [ ] BlockID { blockID , { } } , [ ] int { 67 , 33 } , 100 , true } ,
{ [ ] BlockID { blockID , blockID2 , { } } , [ ] int { 10 , 5 , 5 } , 20 , false } ,
}
for _ , tc := range testCases {
voteSet , valSet , vals := randVoteSet ( height - 1 , 1 , PrecommitType , tc . numValidators , 1 )
vi := 0
for n := range tc . blockIDs {
for i := 0 ; i < tc . numVotes [ n ] ; i ++ {
addr := vals [ vi ] . GetPubKey ( ) . Address ( )
vote := & Vote {
ValidatorAddress : addr ,
ValidatorIndex : vi ,
Height : height - 1 ,
Round : round ,
Type : PrecommitType ,
BlockID : tc . blockIDs [ n ] ,
Timestamp : tmtime . Now ( ) ,
}
_ , err := signAddVote ( vals [ vi ] , vote , voteSet )
assert . NoError ( t , err )
vi ++
}
}
if tc . valid {
commit := voteSet . MakeCommit ( ) // panics without > 2/3 valid votes
assert . NotNil ( t , commit )
err := valSet . VerifyCommit ( voteSet . ChainID ( ) , blockID , height - 1 , commit )
assert . Nil ( t , err )
} else {
assert . Panics ( t , func ( ) { voteSet . MakeCommit ( ) } )
}
}
}
func TestSignedHeaderValidateBasic ( t * testing . T ) {
func TestSignedHeaderValidateBasic ( t * testing . T ) {
commit := randCommit ( )
commit := randCommit ( )
chainID := "𠜎"
chainID := "𠜎"