Browse Source

test: protobuf vectors for reactors (#5221)

## Description

Add test vectors for all reactors

- [x] state-sync
- [x] privval
- [x] mempool
- [x] p2p
- [x] evidence
- [ ] light?

this PR is primarily oriented at testvectors for things going over the wire. should we expand the testvectors into types as well?

Closes: #XXX
pull/5231/head
Marko 4 years ago
committed by GitHub
parent
commit
40bd416d59
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 403 additions and 138 deletions
  1. +12
    -25
      blockchain/msgs_test.go
  2. +15
    -45
      consensus/msgs_test.go
  3. +90
    -0
      evidence/reactor_test.go
  4. +30
    -0
      mempool/reactor_test.go
  5. +26
    -0
      p2p/conn/connection_test.go
  6. +4
    -2
      p2p/pex/pex_reactor.go
  7. +28
    -0
      p2p/pex/pex_reactor_test.go
  8. +0
    -0
      privval/msgs.go
  9. +103
    -0
      privval/msgs_test.go
  10. +1
    -1
      privval/signer_client.go
  11. +2
    -2
      privval/signer_requestHandler.go
  12. +66
    -60
      proto/tendermint/privval/types.pb.go
  13. +1
    -2
      proto/tendermint/privval/types.proto
  14. +1
    -1
      statesync/messages.go
  15. +24
    -0
      statesync/messages_test.go

+ 12
- 25
blockchain/msgs_test.go View File

@ -1,6 +1,7 @@
package blockchain
import (
"encoding/hex"
"math"
"testing"
@ -77,8 +78,8 @@ func TestBcStatusResponseMessageValidateBasic(t *testing.T) {
}
}
// nolint:lll // ignore line length in tests
func TestBlockchainMessageVectors(t *testing.T) {
block := types.MakeBlock(int64(3), []types.Tx{types.Tx("Hello World")}, nil, nil)
bpb, err := block.ToProto()
@ -87,43 +88,29 @@ func TestBlockchainMessageVectors(t *testing.T) {
testCases := []struct {
testName string
bmsg proto.Message
expBytes []byte
expBytes string
}{
{"BlockRequestMessage", &bcproto.Message{Sum: &bcproto.Message_BlockRequest{
BlockRequest: &bcproto.BlockRequest{Height: 1}}}, []byte{0xa, 0x2, 0x8, 0x1}},
BlockRequest: &bcproto.BlockRequest{Height: 1}}}, "0a020801"},
{"BlockRequestMessage", &bcproto.Message{Sum: &bcproto.Message_BlockRequest{
BlockRequest: &bcproto.BlockRequest{Height: math.MaxInt64}}},
[]byte{0xa, 0xa, 0x8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}},
"0a0a08ffffffffffffffff7f"},
{"BlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_BlockResponse{
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, []byte{0x1a, 0xb3, 0x1, 0xa,
0xb0, 0x1, 0xa, 0x59, 0xa, 0x0, 0x18, 0x3, 0x22, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3,
0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, 0x2a, 0x2, 0x12, 0x0, 0x3a, 0x20, 0xc4, 0xda,
0x88, 0xe8, 0x76, 0x6, 0x2a, 0xa1, 0x54, 0x34, 0x0, 0xd5, 0xd, 0xe, 0xaa, 0xd, 0xac,
0x88, 0x9, 0x60, 0x57, 0x94, 0x9c, 0xfb, 0x7b, 0xca, 0x7f, 0x3a, 0x48, 0xc0, 0x4b,
0xf9, 0x6a, 0x20, 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4,
0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4,
0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55, 0x12, 0x2f, 0xa, 0xb, 0x48, 0x65, 0x6c,
0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x12, 0x20, 0xc4, 0xda, 0x88, 0xe8,
0x76, 0x6, 0x2a, 0xa1, 0x54, 0x34, 0x0, 0xd5, 0xd, 0xe, 0xaa, 0xd, 0xac, 0x88, 0x9,
0x60, 0x57, 0x94, 0x9c, 0xfb, 0x7b, 0xca, 0x7f, 0x3a, 0x48, 0xc0, 0x4b, 0xf9, 0x1a,
0x22, 0x12, 0x20, 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4,
0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4,
0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}},
BlockResponse: &bcproto.BlockResponse{Block: bpb}}}, "1ab3010ab0010a590a001803220b088092b8c398feffffff012a0212003a20c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf96a20e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855122f0a0b48656c6c6f20576f726c641220c4da88e876062aa1543400d50d0eaa0dac88096057949cfb7bca7f3a48c04bf91a221220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, []byte{0x12, 0x2, 0x8, 0x1}},
NoBlockResponse: &bcproto.NoBlockResponse{Height: 1}}}, "12020801"},
{"NoBlockResponseMessage", &bcproto.Message{Sum: &bcproto.Message_NoBlockResponse{
NoBlockResponse: &bcproto.NoBlockResponse{Height: math.MaxInt64}}},
[]byte{0x12, 0xa, 0x8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}},
"120a08ffffffffffffffff7f"},
{"StatusRequestMessage", &bcproto.Message{Sum: &bcproto.Message_StatusRequest{
StatusRequest: &bcproto.StatusRequest{}}},
[]byte{0x22, 0x0}},
"2200"},
{"StatusResponseMessage", &bcproto.Message{Sum: &bcproto.Message_StatusResponse{
StatusResponse: &bcproto.StatusResponse{Height: 1, Base: 2}}},
[]byte{0x2a, 0x4, 0x8, 0x1, 0x10, 0x2}},
"2a0408011002"},
{"StatusResponseMessage", &bcproto.Message{Sum: &bcproto.Message_StatusResponse{
StatusResponse: &bcproto.StatusResponse{Height: math.MaxInt64, Base: math.MaxInt64}}},
[]byte{0x2a, 0x14, 0x8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x10,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}},
"2a1408ffffffffffffffff7f10ffffffffffffffff7f"},
}
for _, tc := range testCases {
@ -131,7 +118,7 @@ func TestBlockchainMessageVectors(t *testing.T) {
t.Run(tc.testName, func(t *testing.T) {
bz, _ := proto.Marshal(tc.bmsg)
require.Equal(t, tc.expBytes, bz)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz))
})
}
}

+ 15
- 45
consensus/msgs_test.go View File

@ -1,6 +1,7 @@
package consensus
import (
"encoding/hex"
"math"
"testing"
"time"
@ -313,6 +314,7 @@ func TestWALMsgProto(t *testing.T) {
}
}
// nolint:lll //ignore line length for tests
func TestConsMsgsVectors(t *testing.T) {
date := time.Date(2018, 8, 30, 12, 0, 0, 0, time.UTC)
psh := types.PartSetHeader{
@ -367,7 +369,7 @@ func TestConsMsgsVectors(t *testing.T) {
testCases := []struct {
testName string
cMsg proto.Message
expBytes []byte
expBytes string
}{
{"NewRoundStep", &tmcons.Message{Sum: &tmcons.Message_NewRoundStep{NewRoundStep: &tmcons.NewRoundStep{
Height: 1,
@ -375,74 +377,42 @@ func TestConsMsgsVectors(t *testing.T) {
Step: 1,
SecondsSinceStartTime: 1,
LastCommitRound: 1,
}}}, []byte{0xa, 0xa, 0x8, 0x1, 0x10, 0x1, 0x18, 0x1, 0x20, 0x1, 0x28, 0x1}},
}}}, "0a0a08011001180120012801"},
{"NewRoundStep Max", &tmcons.Message{Sum: &tmcons.Message_NewRoundStep{NewRoundStep: &tmcons.NewRoundStep{
Height: math.MaxInt64,
Round: math.MaxInt32,
Step: math.MaxUint32,
SecondsSinceStartTime: math.MaxInt64,
LastCommitRound: math.MaxInt32,
}}}, []byte{0xa, 0x26, 0x8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x10, 0xff,
0xff, 0xff, 0xff, 0x7, 0x18, 0xff, 0xff, 0xff, 0xff, 0xf, 0x20, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0x7f, 0x28, 0xff, 0xff, 0xff, 0xff, 0x7}},
}}}, "0a2608ffffffffffffffff7f10ffffffff0718ffffffff0f20ffffffffffffffff7f28ffffffff07"},
{"NewValidBlock", &tmcons.Message{Sum: &tmcons.Message_NewValidBlock{
NewValidBlock: &tmcons.NewValidBlock{
Height: 1, Round: 1, BlockPartSetHeader: pbPsh, BlockParts: pbBits, IsCommit: false}}},
[]byte{0x12, 0x31, 0x8, 0x1, 0x10, 0x1, 0x1a, 0x24, 0x8, 0x1, 0x12, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d,
0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d,
0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x22, 0x5, 0x8, 0x1, 0x12, 0x1, 0x0}},
"1231080110011a24080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d22050801120100"},
{"Proposal", &tmcons.Message{Sum: &tmcons.Message_Proposal{Proposal: &tmcons.Proposal{Proposal: *pbProposal}}},
[]byte{0x1a, 0x72, 0xa, 0x70, 0x8, 0x20, 0x10, 0x1, 0x18, 0x1, 0x20, 0x1, 0x2a, 0x48, 0xa, 0x20, 0x61,
0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x12, 0x24, 0x8,
0x1, 0x12, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61,
0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65,
0x2d, 0x32, 0x6, 0x8, 0xc0, 0xb8, 0x9f, 0xdc, 0x5, 0x3a, 0x14, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72,
0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e}},
"1a720a7008201001180120012a480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d320608c0b89fdc053a146164645f6d6f72655f6578636c616d6174696f6e"},
{"ProposalPol", &tmcons.Message{Sum: &tmcons.Message_ProposalPol{
ProposalPol: &tmcons.ProposalPOL{Height: 1, ProposalPolRound: 1}}},
[]byte{0x22, 0x6, 0x8, 0x1, 0x10, 0x1, 0x1a, 0x0}},
"2206080110011a00"},
{"BlockPart", &tmcons.Message{Sum: &tmcons.Message_BlockPart{
BlockPart: &tmcons.BlockPart{Height: 1, Round: 1, Part: *pbParts}}},
[]byte{0x2a, 0x36, 0x8, 0x1, 0x10, 0x1, 0x1a, 0x30, 0x8, 0x1, 0x12, 0x4,
0x74, 0x65, 0x73, 0x74, 0x1a, 0x26, 0x8, 0x1, 0x10, 0x1, 0x1a, 0x20, 0x61,
0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61,
0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63,
0x6f, 0x64, 0x65, 0x2d}},
"2a36080110011a3008011204746573741a26080110011a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d"},
{"Vote", &tmcons.Message{Sum: &tmcons.Message_Vote{
Vote: &tmcons.Vote{Vote: vpb}}},
[]byte{0x32, 0x70, 0xa, 0x6e, 0x8, 0x2, 0x10, 0x1, 0x22, 0x48, 0xa, 0x20, 0x61, 0x64, 0x64,
0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x12,
0x24, 0x8, 0x1, 0x12, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78,
0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f,
0x63, 0x6f, 0x64, 0x65, 0x2d, 0x2a, 0x6, 0x8, 0xc0, 0xb8, 0x9f, 0xdc, 0x5, 0x32, 0x14, 0x61, 0x64,
0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x38, 0x1}},
"32700a6e0802100122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a0608c0b89fdc0532146164645f6d6f72655f6578636c616d6174696f6e3801"},
{"HasVote", &tmcons.Message{Sum: &tmcons.Message_HasVote{
HasVote: &tmcons.HasVote{Height: 1, Round: 1, Type: tmproto.PrevoteType, Index: 1}}},
[]byte{0x3a, 0x8, 0x8, 0x1, 0x10, 0x1, 0x18, 0x1, 0x20, 0x1}},
"3a080801100118012001"},
{"HasVote", &tmcons.Message{Sum: &tmcons.Message_HasVote{
HasVote: &tmcons.HasVote{Height: math.MaxInt64, Round: math.MaxInt32,
Type: tmproto.PrevoteType, Index: math.MaxInt32}}},
[]byte{0x3a, 0x18, 0x8, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x7f, 0x10, 0xff, 0xff, 0xff, 0xff, 0x7, 0x18, 0x1, 0x20, 0xff, 0xff, 0xff, 0xff, 0x7}},
"3a1808ffffffffffffffff7f10ffffffff07180120ffffffff07"},
{"VoteSetMaj23", &tmcons.Message{Sum: &tmcons.Message_VoteSetMaj23{
VoteSetMaj23: &tmcons.VoteSetMaj23{Height: 1, Round: 1, Type: tmproto.PrevoteType, BlockID: pbBi}}},
[]byte{0x42, 0x50, 0x8, 0x1, 0x10, 0x1, 0x18, 0x1, 0x22, 0x48, 0xa, 0x20, 0x61, 0x64, 0x64, 0x5f,
0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x12, 0x24, 0x8, 0x1,
0x12, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72, 0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61,
0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73, 0x5f, 0x63, 0x6f, 0x64,
0x65, 0x2d}},
"425008011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d"},
{"VoteSetBits", &tmcons.Message{Sum: &tmcons.Message_VoteSetBits{
VoteSetBits: &tmcons.VoteSetBits{Height: 1, Round: 1, Type: tmproto.PrevoteType, BlockID: pbBi, Votes: *pbBits}}},
[]byte{0x4a, 0x57, 0x8, 0x1, 0x10, 0x1, 0x18, 0x1, 0x22, 0x48, 0xa, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72,
0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73,
0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x12, 0x24, 0x8, 0x1, 0x12, 0x20, 0x61, 0x64, 0x64, 0x5f, 0x6d, 0x6f, 0x72,
0x65, 0x5f, 0x65, 0x78, 0x63, 0x6c, 0x61, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6d, 0x61, 0x72, 0x6b, 0x73,
0x5f, 0x63, 0x6f, 0x64, 0x65, 0x2d, 0x2a, 0x5, 0x8, 0x1, 0x12, 0x1, 0x0}},
"4a5708011001180122480a206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d1224080112206164645f6d6f72655f6578636c616d6174696f6e5f6d61726b735f636f64652d2a050801120100"},
}
for _, tc := range testCases {
@ -451,7 +421,7 @@ func TestConsMsgsVectors(t *testing.T) {
bz, err := proto.Marshal(tc.cMsg)
require.NoError(t, err)
require.Equal(t, tc.expBytes, bz)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz))
})
}
}

+ 90
- 0
evidence/reactor_test.go View File

@ -1,6 +1,7 @@
package evidence
import (
"encoding/hex"
"fmt"
"sync"
"testing"
@ -14,9 +15,14 @@ import (
dbm "github.com/tendermint/tm-db"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/tmhash"
"github.com/tendermint/tendermint/evidence/mocks"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p"
ep "github.com/tendermint/tendermint/proto/tendermint/evidence"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/types"
)
@ -208,3 +214,87 @@ func TestReactorSelectiveBroadcast(t *testing.T) {
peers := reactors[1].Switch.Peers().List()
assert.Equal(t, 1, len(peers))
}
func exampleVote(t byte) *types.Vote {
var stamp, err = time.Parse(types.TimeFormat, "2017-12-25T03:00:01.234Z")
if err != nil {
panic(err)
}
return &types.Vote{
Type: tmproto.SignedMsgType(t),
Height: 3,
Round: 2,
Timestamp: stamp,
BlockID: types.BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
PartSetHeader: types.PartSetHeader{
Total: 1000000,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
ValidatorIndex: 56789,
}
}
func exampleHeader() *types.Header {
blockID := types.BlockID{Hash: []byte{0}, PartSetHeader: types.PartSetHeader{Total: 123, Hash: []byte{0}}}
h := &types.Header{
Version: version.Consensus{Block: 1, App: 2},
ChainID: "chainId",
Height: 3,
Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC),
LastBlockID: blockID,
LastCommitHash: tmhash.Sum([]byte("last_commit_hash")),
DataHash: tmhash.Sum([]byte("data_hash")),
ValidatorsHash: tmhash.Sum([]byte("validators_hash")),
NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")),
ConsensusHash: tmhash.Sum([]byte("consensus_hash")),
AppHash: tmhash.Sum([]byte("app_hash")),
LastResultsHash: tmhash.Sum([]byte("last_results_hash")),
EvidenceHash: tmhash.Sum([]byte("evidence_hash")),
ProposerAddress: crypto.AddressHash([]byte("proposer_address")),
}
return h
}
// nolint:lll //ignore line length for tests
func TestEvidenceVectors(t *testing.T) {
dupl := types.NewDuplicateVoteEvidence(exampleVote(1), exampleVote(2), time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC))
lve := types.NewLunaticValidatorEvidence(exampleHeader(), exampleVote(1), "Datahash", time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC))
testCases := []struct {
testName string
evidenceList []types.Evidence
expBytes string
}{
{"DuplicateVoteEvidence", []types.Evidence{dupl}, "0a81020afe010a79080210031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0b08b1d381d20510809dca6f32146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb031279080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0b08b1d381d20510809dca6f32146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb031a0608f49a8ded05"},
{"LunaticValidatorEvidence", []types.Evidence{lve}, "0ade031adb030acb020a04080110021207636861696e49641803220608f49a8ded052a0a0a01001205087b1201003220e7aad01a1af897b05bcf78c7563b5d1adc2939d543dac949a5c8712156d19bf83a206d6e28b8b98b5327042ea50a57dd46e6cc851c72e528bdeaa6efdeeefe66a0b84220db5d0767f57d844ba68132eaf74f6b8b83df6c03810a6a4378c2a6b2caf93e8d4a201eef9748a3c48ff996033757d73200886e7b2b4e9d9df07b19a34a44bae3e2c85220e5e566c41ed57e3ff8cc10f184178788b8faa602b07cf1f425217bd8179f1f245a2041cafae31cc70f5801fa1016a2dd54a9bcb8201b5b389919fe9976762532c5166220092e058630247ed6009863a12eee117d26cd9d08b5adcaab37f2ab35db475a376a2073865db08f49d58428905d389ab4ca4b96e45a3206c7a69d43a5dc7372e60714721427834082c131975497cdebfbdce6c8e5196a13541279080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0b08b1d381d20510809dca6f32146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb031a084461746168617368220608f49a8ded05"},
}
for _, tc := range testCases {
tc := tc
evi := make([]*tmproto.Evidence, len(tc.evidenceList))
for i := 0; i < len(tc.evidenceList); i++ {
ev, err := types.EvidenceToProto(tc.evidenceList[i])
require.NoError(t, err, tc.testName)
evi[i] = ev
}
epl := ep.List{
Evidence: evi,
}
bz, err := epl.Marshal()
require.NoError(t, err, tc.testName)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

+ 30
- 0
mempool/reactor_test.go View File

@ -1,6 +1,7 @@
package mempool
import (
"encoding/hex"
"errors"
"net"
"sync"
@ -10,12 +11,14 @@ import (
"github.com/fortytw2/leaktest"
"github.com/go-kit/kit/log/term"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/abci/example/kvstore"
cfg "github.com/tendermint/tendermint/config"
"github.com/tendermint/tendermint/libs/log"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p/mock"
memproto "github.com/tendermint/tendermint/proto/tendermint/mempool"
"github.com/tendermint/tendermint/proxy"
"github.com/tendermint/tendermint/types"
)
@ -246,3 +249,30 @@ func ensureNoTxs(t *testing.T, reactor *Reactor, timeout time.Duration) {
time.Sleep(timeout) // wait for the txs in all mempools
assert.Zero(t, reactor.mempool.Size())
}
func TestMempoolVectors(t *testing.T) {
testCases := []struct {
testName string
tx []byte
expBytes string
}{
{"tx 1", []byte{123}, "0a030a017b"},
{"tx 2", []byte("proto encoding in mempool"), "0a1b0a1970726f746f20656e636f64696e6720696e206d656d706f6f6c"},
}
for _, tc := range testCases {
tc := tc
msg := memproto.Message{
Sum: &memproto.Message_Tx{
Tx: &memproto.Tx{Tx: tc.tx},
},
}
bz, err := msg.Marshal()
require.NoError(t, err, tc.testName)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

+ 26
- 0
p2p/conn/connection_test.go View File

@ -1,11 +1,13 @@
package conn
import (
"encoding/hex"
"net"
"testing"
"time"
"github.com/fortytw2/leaktest"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -561,3 +563,27 @@ func TestMConnectionTrySend(t *testing.T) {
assert.False(t, mconn.TrySend(0x01, msg))
assert.Equal(t, "TrySend", <-resultCh)
}
// nolint:lll //ignore line length for tests
func TestConnVectors(t *testing.T) {
testCases := []struct {
testName string
msg proto.Message
expBytes string
}{
{"PacketPing", &tmp2p.PacketPing{}, "0a00"},
{"PacketPong", &tmp2p.PacketPong{}, "1200"},
{"PacketMsg", &tmp2p.PacketMsg{ChannelID: 1, EOF: false, Data: []byte("data transmitted over the wire")}, "1a2208011a1e64617461207472616e736d6974746564206f766572207468652077697265"},
}
for _, tc := range testCases {
tc := tc
pm := mustWrapPacket(tc.msg)
bz, err := pm.Marshal()
require.NoError(t, err, tc.testName)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

+ 4
- 2
p2p/pex/pex_reactor.go View File

@ -779,7 +779,7 @@ func mustEncode(pb proto.Message) []byte {
panic(fmt.Sprintf("Unknown message type %T", pb))
}
bz, err := proto.Marshal(&msg)
bz, err := msg.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal %T: %w", pb, err))
}
@ -788,10 +788,12 @@ func mustEncode(pb proto.Message) []byte {
func decodeMsg(bz []byte) (proto.Message, error) {
pb := &tmp2p.Message{}
err := proto.Unmarshal(bz, pb)
err := pb.Unmarshal(bz)
if err != nil {
return nil, err
}
switch msg := pb.Sum.(type) {
case *tmp2p.Message_PexRequest:
return msg.PexRequest, nil


+ 28
- 0
p2p/pex/pex_reactor_test.go View File

@ -1,6 +1,7 @@
package pex
import (
"encoding/hex"
"fmt"
"io/ioutil"
"os"
@ -8,6 +9,7 @@ import (
"testing"
"time"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -673,3 +675,29 @@ func createSwitchAndAddReactors(reactors ...p2p.Reactor) *p2p.Switch {
}
return sw
}
func TestPexVectors(t *testing.T) {
addr := tmp2p.NetAddress{
ID: "1",
IP: "127.0.0.1",
Port: 9090,
}
testCases := []struct {
testName string
msg proto.Message
expBytes string
}{
{"PexRequest", &tmp2p.PexRequest{}, "0a00"},
{"PexAddrs", &tmp2p.PexAddrs{Addrs: []tmp2p.NetAddress{addr}}, "12130a110a013112093132372e302e302e31188247"},
}
for _, tc := range testCases {
tc := tc
bz := mustEncode(tc.msg)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

privval/messages.go → privval/msgs.go View File


+ 103
- 0
privval/msgs_test.go View File

@ -0,0 +1,103 @@
package privval
import (
"encoding/hex"
"testing"
"time"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
cryptoenc "github.com/tendermint/tendermint/crypto/encoding"
"github.com/tendermint/tendermint/crypto/tmhash"
privproto "github.com/tendermint/tendermint/proto/tendermint/privval"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
"github.com/tendermint/tendermint/types"
)
var stamp = time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC)
func exampleVote() *types.Vote {
return &types.Vote{
Type: tmproto.SignedMsgType(1),
Height: 3,
Round: 2,
Timestamp: stamp,
BlockID: types.BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
PartSetHeader: types.PartSetHeader{
Total: 1000000,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
ValidatorAddress: crypto.AddressHash([]byte("validator_address")),
ValidatorIndex: 56789,
}
}
func exampleProposal() *types.Proposal {
return &types.Proposal{
Type: tmproto.SignedMsgType(1),
Height: 3,
Round: 2,
Timestamp: stamp,
POLRound: 2,
Signature: []byte("it's a signature"),
BlockID: types.BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),
PartSetHeader: types.PartSetHeader{
Total: 1000000,
Hash: tmhash.Sum([]byte("blockID_part_set_header_hash")),
},
},
}
}
// nolint:lll // ignore line length for tests
func TestPrivvalVectors(t *testing.T) {
pk := ed25519.GenPrivKeyFromSecret([]byte("it's a secret")).PubKey()
ppk, err := cryptoenc.PubKeyToProto(pk)
require.NoError(t, err)
// Generate a simple vote
vote := exampleVote()
votepb := vote.ToProto()
// Generate a simple proposal
proposal := exampleProposal()
proposalpb := proposal.ToProto()
// Create a Reuseable remote error
remoteError := &privproto.RemoteSignerError{Code: 1, Description: "it's a error"}
testCases := []struct {
testName string
msg proto.Message
expBytes string
}{
{"ping request", &privproto.PingRequest{}, ""},
{"ping response", &privproto.PingResponse{}, ""},
{"pubKey request", &privproto.PubKeyRequest{}, "0a00"},
{"pubKey response", &privproto.PubKeyResponse{PubKey: &ppk, Error: nil}, "12240a220a20556a436f1218d30942efe798420f51dc9b6a311b929c578257457d05c5fcf230"},
{"pubKey response with error", &privproto.PubKeyResponse{PubKey: nil, Error: remoteError}, "121212100801120c697427732061206572726f72"},
{"Vote Request", &privproto.SignVoteRequest{Vote: votepb}, "1a760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"},
{"Vote Response", &privproto.SignedVoteResponse{Vote: votepb, Error: nil}, "22760a74080110031802224a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a2a0608f49a8ded0532146af1f4111082efb388211bc72c55bcd61e9ac3d538d5bb03"},
{"Vote Response with error", &privproto.SignedVoteResponse{Vote: nil, Error: remoteError}, "221212100801120c697427732061206572726f72"},
{"Proposal Request", &privproto.SignProposalRequest{Proposal: proposalpb}, "2a700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"},
{"Proposal Response", &privproto.SignedProposalResponse{Proposal: proposalpb, Error: nil}, "32700a6e08011003180220022a4a0a208b01023386c371778ecb6368573e539afc3cc860ec3a2f614e54fe5652f4fc80122608c0843d122072db3d959635dff1bb567bedaa70573392c5159666a3f8caf11e413aac52207a320608f49a8ded053a10697427732061207369676e6174757265"},
{"Proposal Response with error", &privproto.SignedProposalResponse{Proposal: nil, Error: remoteError}, "321212100801120c697427732061206572726f72"},
}
for _, tc := range testCases {
tc := tc
pm := mustWrapMsg(tc.msg)
bz, err := pm.Marshal()
require.NoError(t, err, tc.testName)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

+ 1
- 1
privval/signer_client.go View File

@ -111,7 +111,7 @@ func (sc *SignerClient) SignVote(chainID string, vote *tmproto.Vote) error {
// SignProposal requests a remote signer to sign a proposal
func (sc *SignerClient) SignProposal(chainID string, proposal *tmproto.Proposal) error {
response, err := sc.endpoint.SendRequest(mustWrapMsg(&privvalproto.SignProposalRequest{Proposal: *proposal}))
response, err := sc.endpoint.SendRequest(mustWrapMsg(&privvalproto.SignProposalRequest{Proposal: proposal}))
if err != nil {
return err
}


+ 2
- 2
privval/signer_requestHandler.go View File

@ -49,12 +49,12 @@ func DefaultValidationRequestHandler(
case *privvalproto.Message_SignProposalRequest:
proposal := r.SignProposalRequest.Proposal
err = privVal.SignProposal(chainID, &proposal)
err = privVal.SignProposal(chainID, proposal)
if err != nil {
res = mustWrapMsg(&privvalproto.SignedProposalResponse{
Proposal: nil, Error: &privvalproto.RemoteSignerError{Code: 0, Description: err.Error()}})
} else {
res = mustWrapMsg(&privvalproto.SignedProposalResponse{Proposal: &proposal, Error: nil})
res = mustWrapMsg(&privvalproto.SignedProposalResponse{Proposal: proposal, Error: nil})
}
case *privvalproto.Message_PingRequest:
err, res = nil, mustWrapMsg(&privvalproto.PingResponse{})


+ 66
- 60
proto/tendermint/privval/types.pb.go View File

@ -304,7 +304,7 @@ func (m *SignedVoteResponse) GetError() *RemoteSignerError {
// SignProposalRequest is a request to sign a proposal
type SignProposalRequest struct {
Proposal types.Proposal `protobuf:"bytes,1,opt,name=proposal,proto3" json:"proposal"`
Proposal *types.Proposal `protobuf:"bytes,1,opt,name=proposal,proto3" json:"proposal,omitempty"`
}
func (m *SignProposalRequest) Reset() { *m = SignProposalRequest{} }
@ -340,11 +340,11 @@ func (m *SignProposalRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_SignProposalRequest proto.InternalMessageInfo
func (m *SignProposalRequest) GetProposal() types.Proposal {
func (m *SignProposalRequest) GetProposal() *types.Proposal {
if m != nil {
return m.Proposal
}
return types.Proposal{}
return nil
}
// SignedProposalResponse is response containing a signed proposal or an error
@ -654,53 +654,52 @@ func init() {
func init() { proto.RegisterFile("tendermint/privval/types.proto", fileDescriptor_cb4e437a5328cf9c) }
var fileDescriptor_cb4e437a5328cf9c = []byte{
// 721 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0xcf, 0x4e, 0xdb, 0x4a,
0x14, 0xc6, 0x6d, 0x48, 0x02, 0xf7, 0x84, 0xfc, 0x61, 0xe0, 0x72, 0x73, 0x23, 0xae, 0xc9, 0x75,
0xd5, 0x16, 0xb1, 0x48, 0x24, 0xaa, 0x56, 0xaa, 0xda, 0x2e, 0x0a, 0x58, 0x4d, 0x84, 0x70, 0xd2,
0x49, 0x28, 0x15, 0x52, 0x15, 0x91, 0x64, 0xea, 0x5a, 0x10, 0xcf, 0xd4, 0xe3, 0x20, 0x65, 0xd1,
0x5d, 0xb7, 0x95, 0xfa, 0x18, 0x5d, 0xf7, 0x29, 0x58, 0xb2, 0xec, 0xaa, 0xaa, 0xe0, 0x45, 0x2a,
0x8f, 0x27, 0xb6, 0xc9, 0x9f, 0x4a, 0x88, 0x9d, 0xe7, 0x7c, 0x33, 0xbf, 0xf3, 0x1d, 0xcf, 0x27,
0x0d, 0x68, 0x1e, 0x71, 0x7a, 0xc4, 0xed, 0x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0x84,
0x4a, 0x72, 0xa7, 0x79, 0x71, 0xa5, 0xa9, 0x97, 0x57, 0x9a, 0xfa, 0xeb, 0x4a, 0x53, 0xbf, 0x5e,
0x6b, 0xca, 0xe5, 0xb5, 0xa6, 0xfc, 0xb8, 0xd6, 0x94, 0xe3, 0xa7, 0x96, 0xed, 0x7d, 0x18, 0x74,
0xca, 0x5d, 0xda, 0xaf, 0xc4, 0xdf, 0x91, 0xf8, 0xd3, 0xe5, 0xbf, 0x46, 0x93, 0x6f, 0x59, 0x27,
0x25, 0x94, 0x47, 0xbf, 0x03, 0x00, 0x00, 0xff, 0xff, 0x98, 0xd1, 0x49, 0xc8, 0xe8, 0x06, 0x00,
0x00,
// 711 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xa4, 0x95, 0xcf, 0x6e, 0xd3, 0x4a,
0x14, 0xc6, 0xed, 0x36, 0x49, 0x7b, 0x4f, 0x9a, 0x3f, 0x9d, 0xf6, 0xf6, 0xe6, 0x46, 0xbd, 0xbe,
0xc1, 0x08, 0xa8, 0xba, 0x48, 0xa4, 0x22, 0x90, 0x10, 0x62, 0x41, 0x5b, 0x8b, 0x44, 0x55, 0xed,
0x30, 0x49, 0x29, 0xaa, 0x84, 0xac, 0x26, 0x19, 0x8c, 0xd5, 0xc6, 0x33, 0x78, 0x9c, 0x4a, 0x59,
0xb0, 0x63, 0x8b, 0xc4, 0x63, 0xb0, 0xe6, 0x29, 0x58, 0x76, 0xc9, 0x12, 0xb5, 0x2f, 0x82, 0x3c,
0x9e, 0x38, 0x6e, 0xfe, 0x20, 0x41, 0x77, 0x9e, 0xf3, 0xcd, 0xfc, 0xce, 0x77, 0x3c, 0x9f, 0x34,
0xa0, 0x05, 0xc4, 0xeb, 0x11, 0xbf, 0xef, 0x7a, 0x41, 0x8d, 0xf9, 0xee, 0xc5, 0xc5, 0xe9, 0x79,
0x2d, 0x18, 0x32, 0xc2,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xd7, 0x9a, 0x72, 0xf2,
0xc4, 0x71, 0x83, 0x77, 0x83, 0x4e, 0xb5, 0x4b, 0xfb, 0xb5, 0xe4, 0x0b, 0x92, 0x7c, 0xb4, 0xc2,
0x77, 0x68, 0xfa, 0x15, 0xeb, 0x64, 0x84, 0xf2, 0xf0, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, 0xbe,
0xc8, 0xae, 0x83, 0xe2, 0x06, 0x00, 0x00,
}
func (m *RemoteSignerError) Marshal() (dAtA []byte, err error) {
@ -910,16 +909,18 @@ func (m *SignProposalRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
_ = i
var l int
_ = l
{
size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
if m.Proposal != nil {
{
size, err := m.Proposal.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarintTypes(dAtA, i, uint64(size))
}
i -= size
i = encodeVarintTypes(dAtA, i, uint64(size))
i--
dAtA[i] = 0xa
}
i--
dAtA[i] = 0xa
return len(dAtA) - i, nil
}
@ -1305,8 +1306,10 @@ func (m *SignProposalRequest) Size() (n int) {
}
var l int
_ = l
l = m.Proposal.Size()
n += 1 + l + sovTypes(uint64(l))
if m.Proposal != nil {
l = m.Proposal.Size()
n += 1 + l + sovTypes(uint64(l))
}
return n
}
@ -2014,6 +2017,9 @@ func (m *SignProposalRequest) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if m.Proposal == nil {
m.Proposal = &types.Proposal{}
}
if err := m.Proposal.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}


+ 1
- 2
proto/tendermint/privval/types.proto View File

@ -43,7 +43,7 @@ message SignedVoteResponse {
// SignProposalRequest is a request to sign a proposal
message SignProposalRequest {
tendermint.types.Proposal proposal = 1 [(gogoproto.nullable) = false];
tendermint.types.Proposal proposal = 1;
}
// SignedProposalResponse is response containing a signed proposal or an error
@ -70,4 +70,3 @@ message Message {
PingResponse ping_response = 8;
}
}

+ 1
- 1
statesync/messages.go View File

@ -31,7 +31,7 @@ func mustEncodeMsg(pb proto.Message) []byte {
default:
panic(fmt.Errorf("unknown message type %T", pb))
}
bz, err := proto.Marshal(&msg)
bz, err := msg.Marshal()
if err != nil {
panic(fmt.Errorf("unable to marshal %T: %w", pb, err))
}


+ 24
- 0
statesync/messages_test.go View File

@ -1,6 +1,7 @@
package statesync
import (
"encoding/hex"
"testing"
"github.com/gogo/protobuf/proto"
@ -81,3 +82,26 @@ func TestValidateMsg(t *testing.T) {
})
}
}
//nolint:lll // ignore line length
func TestStateSyncVectors(t *testing.T) {
testCases := []struct {
testName string
msg proto.Message
expBytes string
}{
{"SnapshotsRequest", &ssproto.SnapshotsRequest{}, "0a00"},
{"SnapshotsResponse", &ssproto.SnapshotsResponse{Height: 1, Format: 2, Chunks: 3, Hash: []byte("chuck hash"), Metadata: []byte("snapshot metadata")}, "1225080110021803220a636875636b20686173682a11736e617073686f74206d65746164617461"},
{"ChunkRequest", &ssproto.ChunkRequest{Height: 1, Format: 2, Index: 3}, "1a06080110021803"},
{"ChunkResponse", &ssproto.ChunkResponse{Height: 1, Format: 2, Index: 3, Chunk: []byte("it's a chunk")}, "2214080110021803220c697427732061206368756e6b"},
}
for _, tc := range testCases {
tc := tc
bz := mustEncodeMsg(tc.msg)
require.Equal(t, tc.expBytes, hex.EncodeToString(bz), tc.testName)
}
}

Loading…
Cancel
Save