mirror of
https://github.com/fluencelabs/tendermint
synced 2025-07-31 04:01:55 +00:00
ValidateBasic tests (#3879)
* Add test for bcBlockRequestMessage ValidateBasic method * Add test for bcNoBlockResponseMessage ValidateBasic method * Add test for bcStatusRequestMessage ValidateBasic method * Add test for bcStatusResponseMessage ValidateBasic method * Add blockchain v1 reactor ValidateBasic tests * Add test for NewRoundStepMessage ValidateBasic method * Add test for NewValidBlockMessage ValidateBasic method * Test BlockParts Size * Import cmn package * Add test for ProposalPOLMessage ValidateBasic method * Add test for BlockPartMessage ValidateBasic method * Add test for HasVoteMessage ValidateBasic method * Add test for VoteSetMaj23Message ValidateBasic method * Add test for VoteSetBitsMessage ValidateBasic method * Fix linter errors * Improve readability * Add test for BaseConfig ValidateBasic method * Add test for RPCConfig ValidateBasic method * Add test for P2PConfig ValidateBasic method * Add test for MempoolConfig ValidateBasic method * Add test for FastSyncConfig ValidateBasic method * Add test for ConsensusConfig ValidateBasic method * Add test for InstrumentationConfig ValidateBasic method * Add test for BlockID ValidateBasic method * Add test for SignedHeader ValidateBasic method * Add test for MockGoodEvidence and MockBadEvidence ValidateBasic methods * Remove debug logging Co-Authored-By: Marko <marbar3778@yahoo.com> * Update MempoolConfig field * Test a single struct field at a time, for maintainability Fixes #2740
This commit is contained in:
committed by
Anton Kaliaev
parent
8a282a5fee
commit
c962567814
@@ -18,6 +18,8 @@ import (
|
||||
"github.com/tendermint/tendermint/abci/example/kvstore"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
cfg "github.com/tendermint/tendermint/config"
|
||||
cstypes "github.com/tendermint/tendermint/consensus/types"
|
||||
cmn "github.com/tendermint/tendermint/libs/common"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
mempl "github.com/tendermint/tendermint/mempool"
|
||||
"github.com/tendermint/tendermint/p2p"
|
||||
@@ -632,3 +634,253 @@ func capture() {
|
||||
count := runtime.Stack(trace, true)
|
||||
fmt.Printf("Stack of %d bytes: %s\n", count, trace)
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------
|
||||
// Ensure basic validation of structs is functioning
|
||||
|
||||
func TestNewRoundStepMessageValidateBasic(t *testing.T) {
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageStep cstypes.RoundStepType
|
||||
messageLastCommitRound int
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, 0x01, 1, false},
|
||||
{"Invalid Message", -1, 0, 0x01, 1, true},
|
||||
{"Invalid Message", 0, -1, 0x01, 1, true},
|
||||
{"Invalid Message", 0, 0, 0x00, 1, true},
|
||||
{"Invalid Message", 0, 0, 0x00, 0, true},
|
||||
{"Invalid Message", 1, 0, 0x01, 0, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := NewRoundStepMessage{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
Step: tc.messageStep,
|
||||
LastCommitRound: tc.messageLastCommitRound,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewValidBlockMessageValidateBasic(t *testing.T) {
|
||||
testBitArray := cmn.NewBitArray(1)
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageBlockParts *cmn.BitArray
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, testBitArray, false},
|
||||
{"Invalid Message", -1, 0, testBitArray, true},
|
||||
{"Invalid Message", 0, -1, testBitArray, true},
|
||||
{"Invalid Message", 0, 0, cmn.NewBitArray(0), true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := NewValidBlockMessage{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
BlockParts: tc.messageBlockParts,
|
||||
}
|
||||
|
||||
message.BlockPartsHeader.Total = 1
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestProposalPOLMessageValidateBasic(t *testing.T) {
|
||||
testBitArray := cmn.NewBitArray(1)
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageProposalPOLRound int
|
||||
messageProposalPOL *cmn.BitArray
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, testBitArray, false},
|
||||
{"Invalid Message", -1, 0, testBitArray, true},
|
||||
{"Invalid Message", 0, -1, testBitArray, true},
|
||||
{"Invalid Message", 0, 0, cmn.NewBitArray(0), true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := ProposalPOLMessage{
|
||||
Height: tc.messageHeight,
|
||||
ProposalPOLRound: tc.messageProposalPOLRound,
|
||||
ProposalPOL: tc.messageProposalPOL,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockPartMessageValidateBasic(t *testing.T) {
|
||||
testPart := new(types.Part)
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messagePart *types.Part
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, testPart, false},
|
||||
{"Invalid Message", -1, 0, testPart, true},
|
||||
{"Invalid Message", 0, -1, testPart, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := BlockPartMessage{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
Part: tc.messagePart,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
|
||||
message := BlockPartMessage{Height: 0, Round: 0, Part: new(types.Part)}
|
||||
message.Part.Index = -1
|
||||
|
||||
assert.Equal(t, true, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
}
|
||||
|
||||
func TestHasVoteMessageValidateBasic(t *testing.T) {
|
||||
const (
|
||||
validSignedMsgType types.SignedMsgType = 0x01
|
||||
invalidSignedMsgType types.SignedMsgType = 0x03
|
||||
)
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageType types.SignedMsgType
|
||||
messageIndex int
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, validSignedMsgType, 0, false},
|
||||
{"Invalid Message", -1, 0, validSignedMsgType, 0, true},
|
||||
{"Invalid Message", 0, -1, validSignedMsgType, 0, true},
|
||||
{"Invalid Message", 0, 0, invalidSignedMsgType, 0, true},
|
||||
{"Invalid Message", 0, 0, validSignedMsgType, -1, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := HasVoteMessage{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
Type: tc.messageType,
|
||||
Index: tc.messageIndex,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVoteSetMaj23MessageValidateBasic(t *testing.T) {
|
||||
const (
|
||||
validSignedMsgType types.SignedMsgType = 0x01
|
||||
invalidSignedMsgType types.SignedMsgType = 0x03
|
||||
)
|
||||
|
||||
validBlockID := types.BlockID{}
|
||||
invalidBlockID := types.BlockID{
|
||||
Hash: cmn.HexBytes{},
|
||||
PartsHeader: types.PartSetHeader{
|
||||
Total: -1,
|
||||
Hash: cmn.HexBytes{},
|
||||
},
|
||||
}
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageType types.SignedMsgType
|
||||
messageBlockID types.BlockID
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, validSignedMsgType, validBlockID, false},
|
||||
{"Invalid Message", -1, 0, validSignedMsgType, validBlockID, true},
|
||||
{"Invalid Message", 0, -1, validSignedMsgType, validBlockID, true},
|
||||
{"Invalid Message", 0, 0, invalidSignedMsgType, validBlockID, true},
|
||||
{"Invalid Message", 0, 0, validSignedMsgType, invalidBlockID, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := VoteSetMaj23Message{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
Type: tc.messageType,
|
||||
BlockID: tc.messageBlockID,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestVoteSetBitsMessageValidateBasic(t *testing.T) {
|
||||
const (
|
||||
validSignedMsgType types.SignedMsgType = 0x01
|
||||
invalidSignedMsgType types.SignedMsgType = 0x03
|
||||
)
|
||||
|
||||
validBlockID := types.BlockID{}
|
||||
invalidBlockID := types.BlockID{
|
||||
Hash: cmn.HexBytes{},
|
||||
PartsHeader: types.PartSetHeader{
|
||||
Total: -1,
|
||||
Hash: cmn.HexBytes{},
|
||||
},
|
||||
}
|
||||
testBitArray := cmn.NewBitArray(1)
|
||||
|
||||
testCases := []struct {
|
||||
testName string
|
||||
messageHeight int64
|
||||
messageRound int
|
||||
messageType types.SignedMsgType
|
||||
messageBlockID types.BlockID
|
||||
messageVotes *cmn.BitArray
|
||||
expectErr bool
|
||||
}{
|
||||
{"Valid Message", 0, 0, validSignedMsgType, validBlockID, testBitArray, false},
|
||||
{"Invalid Message", -1, 0, validSignedMsgType, validBlockID, testBitArray, true},
|
||||
{"Invalid Message", 0, -1, validSignedMsgType, validBlockID, testBitArray, true},
|
||||
{"Invalid Message", 0, 0, invalidSignedMsgType, validBlockID, testBitArray, true},
|
||||
{"Invalid Message", 0, 0, validSignedMsgType, invalidBlockID, testBitArray, true},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.testName, func(t *testing.T) {
|
||||
message := VoteSetBitsMessage{
|
||||
Height: tc.messageHeight,
|
||||
Round: tc.messageRound,
|
||||
Type: tc.messageType,
|
||||
// Votes: tc.messageVotes,
|
||||
BlockID: tc.messageBlockID,
|
||||
}
|
||||
|
||||
assert.Equal(t, tc.expectErr, message.ValidateBasic() != nil, "Validate Basic had an unexpected result")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user