From 82104c93293097a41c32023d9b14e7bd06b46149 Mon Sep 17 00:00:00 2001 From: Liamsi Date: Tue, 12 Jun 2018 23:49:16 -0700 Subject: [PATCH] almost --- types/proto3/block.proto | 44 ++++++++++++++++++++++++++++++ types/proto3_test.go | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 types/proto3/block.proto create mode 100644 types/proto3_test.go diff --git a/types/proto3/block.proto b/types/proto3/block.proto new file mode 100644 index 000000000..d1c5cb928 --- /dev/null +++ b/types/proto3/block.proto @@ -0,0 +1,44 @@ +syntax = "proto3"; + +package proto3; + + +message PartSetHeader { + sint32 Total = 1; + bytes Hash = 2; +} + +message BlockID { + bytes Hash = 1; + PartSetHeader PartsHeader = 2; +} + +message Header { + // basic block info + string ChainID = 1; + sint64 Height = 2; + Timestamp Time = 3; + sint64 NumTxs = 4; + + // prev block info + BlockID LastBlockID = 5; + sint64 TotalTxs = 6; + + // hashes of block data + bytes LastCommitHash = 7; // commit from validators from the last block + bytes DataHash = 8; // transactions + + // hashes from the app output from the prev block + bytes ValidatorsHash = 9; // validators for the current block + bytes ConsensusHash = 10; // consensus params for current block + bytes AppHash = 11; // state after txs from the previous block + bytes LastResultsHash = 12; // root hash of all results from the txs from the previous block + + // consensus info + bytes EvidenceHash = 13; // evidence included in the block +} + +message Timestamp { + sint64 seconds = 1; + sint32 nanos = 2; +} diff --git a/types/proto3_test.go b/types/proto3_test.go new file mode 100644 index 000000000..244551fe2 --- /dev/null +++ b/types/proto3_test.go @@ -0,0 +1,59 @@ +package types + +import ( + "testing" + "github.com/tendermint/tendermint/types/proto3" + "github.com/stretchr/testify/assert" + "github.com/golang/protobuf/proto" + "time" +) + +func TestProto3Compatibility(t *testing.T) { + // TODO(ismail): table tests instead... + tm, err := time.Parse("Mon Jan 2 15:04:05 -0700 MST 2006", "Mon Jan 2 15:04:05 -0700 MST 2006") + assert.NoError(t, err) + + pbHeader := proto3.Header{ + ChainID: "cosmos", + Height:150, + Time: &proto3.Timestamp{Seconds:tm.Unix(), Nanos:int32(tm.Nanosecond())}, + NumTxs: 7, + LastBlockID: &proto3.BlockID{ + Hash: []byte("some serious hashing"), + PartsHeader:&proto3.PartSetHeader{ + Total: 8, + Hash: []byte("some more serious hashing"), + }, + }, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + + } + // TODO(ismail): add another test where parts are missing (to see if default values are treated equiv.) + aminoHeader := Header{ + ChainID: "cosmos", + Height:150, + Time: tm, + NumTxs: 7, + LastBlockID: BlockID{ + Hash: []byte("some serious hashing"), + PartsHeader: PartSetHeader{ + Total: 8, + Hash: []byte("some more serious hashing"), + }, + }, + TotalTxs: 100, + LastCommitHash: []byte("commit hash"), + DataHash: []byte("data hash"), + ValidatorsHash:[]byte("validators hash"), + } + ab, err := cdc.MarshalBinaryBare(aminoHeader) + assert.NoError(t, err, "unexpected error") + + pb, err := proto.Marshal(&pbHeader) + assert.NoError(t, err, "unexpected error") + // This works: + assert.Equal(t, ab, pb, "encoding doesn't match") +}