Browse Source

proto: remove amino proto tests (#4982)

## Description

These tests were made to test the compatibility of amino and protobuf. Since we are moving to protobuf they are not needed anymore.

The proto3 directory was created to be used only in these tests

Closes: #XXX
pull/4968/head
Marko 4 years ago
committed by GitHub
parent
commit
dcc67642fa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 0 additions and 2101 deletions
  1. +0
    -1870
      types/proto3/block.pb.go
  2. +0
    -55
      types/proto3/block.proto
  3. +0
    -74
      types/proto3/result.go
  4. +0
    -102
      types/proto3_test.go

+ 0
- 1870
types/proto3/block.pb.go
File diff suppressed because it is too large
View File


+ 0
- 55
types/proto3/block.proto View File

@ -1,55 +0,0 @@
syntax = "proto3";
package tendermint.types.proto3;
option go_package = "github.com/tendermint/tendermint/types/proto3";
message PartSetHeader {
int32 Total = 1;
bytes Hash = 2;
}
message BlockID {
bytes Hash = 1;
PartSetHeader PartsHeader = 2;
}
message Header {
// basic block info
Version Version = 1;
string ChainID = 2;
int64 Height = 3;
Timestamp Time = 4;
// prev block info
BlockID LastBlockID = 5;
// hashes of block data
bytes LastCommitHash = 6; // commit from validators from the last block
bytes DataHash = 7; // transactions
// hashes from the app output from the prev block
bytes ValidatorsHash = 8; // validators for the current block
bytes NextValidatorsHash = 9; // validators for the next 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
bytes ProposerAddress = 14; // original proposer of the block
}
message Version {
uint64 Block = 1;
uint64 App = 2;
}
// Timestamp wraps how amino encodes time.
// This is the protobuf well-known type protobuf/timestamp.proto
// See:
// https://github.com/google/protobuf/blob/d2980062c859649523d5fd51d6b55ab310e47482/src/google/protobuf/timestamp.proto#L123-L135
// NOTE/XXX: nanos do not get skipped if they are zero in amino.
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
}

+ 0
- 74
types/proto3/result.go View File

@ -1,74 +0,0 @@
package proto3
import (
"bytes"
"encoding/json"
"github.com/gogo/protobuf/jsonpb"
)
//---------------------------------------------------------------------------
// override JSON marshalling so we emit defaults (ie. disable omitempty)
var (
jsonpbMarshaller = jsonpb.Marshaler{
EnumsAsInts: true,
EmitDefaults: true,
}
jsonpbUnmarshaller = jsonpb.Unmarshaler{}
)
func (r *PartSetHeader) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *PartSetHeader) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Header) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Header) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Version) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Version) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
func (r *Timestamp) MarshalJSON() ([]byte, error) {
s, err := jsonpbMarshaller.MarshalToString(r)
return []byte(s), err
}
func (r *Timestamp) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r)
}
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*PartSetHeader)(nil)
var _ jsonRoundTripper = (*Header)(nil)
var _ jsonRoundTripper = (*Version)(nil)
var _ jsonRoundTripper = (*Timestamp)(nil)

+ 0
- 102
types/proto3_test.go View File

@ -1,102 +0,0 @@
package types
import (
"testing"
"time"
"github.com/gogo/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/types/proto3"
)
func TestProto3Compatibility(t *testing.T) {
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)
// add some nanos, otherwise protobuf will skip over this while amino (still) won't!
tm = tm.Add(50000 * time.Nanosecond)
seconds := tm.Unix()
nanos := int32(tm.Nanosecond())
t.Log("seconds", seconds)
t.Log("nanos", nanos)
pbHeader := proto3.Header{
ChainID: "cosmos",
Height: 150,
Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos},
LastBlockID: &proto3.BlockID{
Hash: []byte("some serious hashing"),
PartsHeader: &proto3.PartSetHeader{
Total: 8,
Hash: []byte("some more serious hashing"),
},
},
LastCommitHash: []byte("commit hash"),
DataHash: []byte("data hash"),
ValidatorsHash: []byte("validators hash"),
}
aminoHeader := Header{
ChainID: "cosmos",
Height: 150,
Time: tm,
LastBlockID: BlockID{
Hash: []byte("some serious hashing"),
PartsHeader: PartSetHeader{
Total: 8,
Hash: []byte("some more serious hashing"),
},
},
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")
emptyLastBlockPb := proto3.Header{
ChainID: "cosmos",
Height: 150,
Time: &proto3.Timestamp{Seconds: seconds, Nanos: nanos},
LastCommitHash: []byte("commit hash"),
DataHash: []byte("data hash"),
ValidatorsHash: []byte("validators hash"),
}
emptyLastBlockAm := Header{
ChainID: "cosmos",
Height: 150,
Time: tm,
LastCommitHash: []byte("commit hash"),
DataHash: []byte("data hash"),
ValidatorsHash: []byte("validators hash"),
}
ab, err = cdc.MarshalBinaryBare(emptyLastBlockAm)
assert.NoError(t, err, "unexpected error")
pb, err = proto.Marshal(&emptyLastBlockPb)
assert.NoError(t, err, "unexpected error")
// This works:
assert.Equal(t, ab, pb, "encoding doesn't match")
pb, err = proto.Marshal(&proto3.Header{})
assert.NoError(t, err, "unexpected error")
t.Log(pb)
// While in protobuf Header{} encodes to an empty byte slice it does not in amino:
ab, err = cdc.MarshalBinaryBare(Header{})
assert.NoError(t, err, "unexpected error")
t.Log(ab)
pb, err = proto.Marshal(&proto3.Timestamp{})
assert.NoError(t, err, "unexpected error")
t.Log(pb)
ab, err = cdc.MarshalBinaryBare(time.Time{})
assert.NoError(t, err, "unexpected error")
t.Log(ab)
}

Loading…
Cancel
Save