Browse Source

Update to Amino v0.13.0-rc0 (#2687)

* types: test tm2pm on fully populated header

* upgrade for amino v0.13.0-rc0

* fix lint

* comment out final test
pull/2694/head
Ethan Buchman 6 years ago
committed by GitHub
parent
commit
be929acd6a
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 186 additions and 102 deletions
  1. +3
    -3
      Gopkg.lock
  2. +1
    -1
      Gopkg.toml
  3. +13
    -20
      state/state.go
  4. +27
    -5
      types/block.go
  5. +11
    -7
      types/block_test.go
  6. +1
    -1
      types/evidence.go
  7. +1
    -1
      types/evidence_test.go
  8. +32
    -31
      types/proto3/block.pb.go
  9. +6
    -5
      types/proto3/block.proto
  10. +9
    -4
      types/protobuf.go
  11. +67
    -9
      types/protobuf_test.go
  12. +1
    -1
      types/results_test.go
  13. +1
    -1
      types/vote.go
  14. +13
    -13
      types/vote_test.go

+ 3
- 3
Gopkg.lock View File

@ -365,12 +365,12 @@
revision = "e5840949ff4fff0c56f9b6a541e22b63581ea9df"
[[projects]]
digest = "1:e0a2a4be1e20c305badc2b0a7a9ab7fef6da500763bec23ab81df3b5f9eec9ee"
digest = "1:3ff2c9d4def5ec999ab672b9059d0ba41a1351913ea78e63b5402e4ba4ef8da4"
name = "github.com/tendermint/go-amino"
packages = ["."]
pruneopts = "UT"
revision = "a8328986c1608950fa5d3d1c0472cccc4f8fc02c"
version = "v0.12.0-rc0"
revision = "ff047d9e357e66d937d6900d4a2e04501cc62c70"
version = "v0.13.0-rc0"
[[projects]]
digest = "1:72b71e3a29775e5752ed7a8012052a3dee165e27ec18cedddae5288058f09acf"


+ 1
- 1
Gopkg.toml View File

@ -58,7 +58,7 @@
[[constraint]]
name = "github.com/tendermint/go-amino"
version = "v0.12.0-rc0"
version = "v0.13.0-rc0"
[[constraint]]
name = "google.golang.org/grpc"


+ 13
- 20
state/state.go View File

@ -128,7 +128,7 @@ func (state State) IsEmpty() bool {
// MakeBlock builds a block from the current state with the given txs, commit,
// and evidence. Note it also takes a proposerAddress because the state does not
// track rounds, and hence doesn't know the correct proposer. TODO: alleviate this!
// track rounds, and hence does not know the correct proposer. TODO: fix this!
func (state State) MakeBlock(
height int64,
txs []types.Tx,
@ -140,29 +140,22 @@ func (state State) MakeBlock(
// Build base block with block data.
block := types.MakeBlock(height, txs, commit, evidence)
// Fill rest of header with state data.
block.Version = state.Version.Consensus
block.ChainID = state.ChainID
// Set time
// Set time.
var timestamp time.Time
if height == 1 {
block.Time = state.LastBlockTime // genesis time
timestamp = state.LastBlockTime // genesis time
} else {
block.Time = MedianTime(commit, state.LastValidators)
timestamp = MedianTime(commit, state.LastValidators)
}
block.LastBlockID = state.LastBlockID
block.TotalTxs = state.LastBlockTotalTx + block.NumTxs
block.ValidatorsHash = state.Validators.Hash()
block.NextValidatorsHash = state.NextValidators.Hash()
block.ConsensusHash = state.ConsensusParams.Hash()
block.AppHash = state.AppHash
block.LastResultsHash = state.LastResultsHash
// NOTE: we can't use the state.Validators because we don't
// IncrementAccum for rounds there.
block.ProposerAddress = proposerAddress
// Fill rest of header with state data.
block.Header.Populate(
state.Version.Consensus, state.ChainID,
timestamp, state.LastBlockID, state.LastBlockTotalTx+block.NumTxs,
state.Validators.Hash(), state.NextValidators.Hash(),
state.ConsensusParams.Hash(), state.AppHash, state.LastResultsHash,
proposerAddress,
)
return block, block.MakePartSet(types.BlockPartSizeBytes)
}


+ 27
- 5
types/block.go View File

@ -15,7 +15,7 @@ import (
const (
// MaxHeaderBytes is a maximum header size (including amino overhead).
MaxHeaderBytes int64 = 534
MaxHeaderBytes int64 = 537
// MaxAminoOverheadForBlock - maximum amino overhead to encode a block (up to
// MaxBlockSizeBytes in size) not including it's parts except Data.
@ -257,11 +257,11 @@ func MaxDataBytesUnknownEvidence(maxBytes int64, valsCount int) int64 {
//-----------------------------------------------------------------------------
// Header defines the structure of a Tendermint block header
// Header defines the structure of a Tendermint block header.
// NOTE: changes to the Header should be duplicated in:
// - header.Hash()
// - abci.Header
// - /docs/spec/blockchain/blockchain.md
// - header.Hash()
// - abci.Header
// - /docs/spec/blockchain/blockchain.md
type Header struct {
// basic block info
Version version.Consensus `json:"version"`
@ -290,6 +290,28 @@ type Header struct {
ProposerAddress Address `json:"proposer_address"` // original proposer of the block
}
// Populate the Header with state-derived data.
// Call this after MakeBlock to complete the Header.
func (h *Header) Populate(
version version.Consensus, chainID string,
timestamp time.Time, lastBlockID BlockID, totalTxs int64,
valHash, nextValHash []byte,
consensusHash, appHash, lastResultsHash []byte,
proposerAddress Address,
) {
h.Version = version
h.ChainID = chainID
h.Time = timestamp
h.LastBlockID = lastBlockID
h.TotalTxs = totalTxs
h.ValidatorsHash = valHash
h.NextValidatorsHash = nextValHash
h.ConsensusHash = consensusHash
h.AppHash = appHash
h.LastResultsHash = lastResultsHash
h.ProposerAddress = proposerAddress
}
// Hash returns the hash of the header.
// It computes a Merkle tree from the header fields
// ordered as they appear in the Header.


+ 11
- 7
types/block_test.go View File

@ -242,11 +242,15 @@ func TestMaxHeaderBytes(t *testing.T) {
maxChainID += "𠜎"
}
// time is varint encoded so need to pick the max.
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
h := Header{
Version: version.Consensus{math.MaxInt64, math.MaxInt64},
ChainID: maxChainID,
Height: math.MaxInt64,
Time: time.Now().UTC(),
Time: timestamp,
NumTxs: math.MaxInt64,
TotalTxs: math.MaxInt64,
LastBlockID: makeBlockID(make([]byte, tmhash.Size), math.MaxInt64, make([]byte, tmhash.Size)),
@ -288,9 +292,9 @@ func TestBlockMaxDataBytes(t *testing.T) {
}{
0: {-10, 1, 0, true, 0},
1: {10, 1, 0, true, 0},
2: {744, 1, 0, true, 0},
3: {745, 1, 0, false, 0},
4: {746, 1, 0, false, 1},
2: {750, 1, 0, true, 0},
3: {751, 1, 0, false, 0},
4: {752, 1, 0, false, 1},
}
for i, tc := range testCases {
@ -316,9 +320,9 @@ func TestBlockMaxDataBytesUnknownEvidence(t *testing.T) {
}{
0: {-10, 1, true, 0},
1: {10, 1, true, 0},
2: {826, 1, true, 0},
3: {827, 1, false, 0},
4: {828, 1, false, 1},
2: {833, 1, true, 0},
3: {834, 1, false, 0},
4: {835, 1, false, 1},
}
for i, tc := range testCases {


+ 1
- 1
types/evidence.go View File

@ -14,7 +14,7 @@ import (
const (
// MaxEvidenceBytes is a maximum size of any evidence (including amino overhead).
MaxEvidenceBytes int64 = 440
MaxEvidenceBytes int64 = 444
)
// ErrEvidenceInvalid wraps a piece of evidence and the error denoting how or why it is invalid.


+ 1
- 1
types/evidence_test.go View File

@ -61,7 +61,7 @@ func TestEvidence(t *testing.T) {
{vote1, makeVote(val, chainID, 0, 10, 3, 1, blockID2), false}, // wrong round
{vote1, makeVote(val, chainID, 0, 10, 2, 2, blockID2), false}, // wrong step
{vote1, makeVote(val2, chainID, 0, 10, 2, 1, blockID), false}, // wrong validator
{vote1, badVote, false}, // signed by wrong key
{vote1, badVote, false}, // signed by wrong key
}
pubKey := val.GetPubKey()


+ 32
- 31
types/proto3/block.pb.go View File

@ -244,13 +244,14 @@ func (m *Version) GetApp() uint64 {
return 0
}
// Timestamp wraps how amino encodes time. Note that this is different from the protobuf well-known type
// protobuf/timestamp.proto in the sense that there seconds and nanos are varint encoded. See:
// 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
// Also nanos do not get skipped if they are zero in amino.
// NOTE/XXX: nanos do not get skipped if they are zero in amino.
type Timestamp struct {
Seconds int64 `protobuf:"fixed64,1,opt,name=seconds" json:"seconds,omitempty"`
Nanos int32 `protobuf:"fixed32,2,opt,name=nanos" json:"nanos,omitempty"`
Seconds int64 `protobuf:"varint,1,opt,name=seconds" json:"seconds,omitempty"`
Nanos int32 `protobuf:"varint,2,opt,name=nanos" json:"nanos,omitempty"`
}
func (m *Timestamp) Reset() { *m = Timestamp{} }
@ -285,31 +286,31 @@ func init() { proto.RegisterFile("block.proto", fileDescriptor0) }
var fileDescriptor0 = []byte{
// 443 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x53, 0xcd, 0x6a, 0xdb, 0x40,
0x10, 0x46, 0x8d, 0x62, 0xc7, 0x23, 0x3b, 0x76, 0x86, 0xb6, 0x88, 0x9e, 0x8c, 0x68, 0x8b, 0x7b,
0x10, 0x46, 0xb5, 0x6c, 0xc7, 0x23, 0x3b, 0x4e, 0x86, 0xb6, 0x88, 0x9e, 0x8c, 0x68, 0x8b, 0x7b,
0x31, 0x24, 0x39, 0x94, 0xd2, 0x93, 0x6b, 0x17, 0x12, 0x28, 0x21, 0x6c, 0x8d, 0xef, 0x1b, 0x6b,
0xa9, 0x45, 0x2d, 0xad, 0xd0, 0xac, 0x4b, 0xde, 0xb0, 0xaf, 0x55, 0x66, 0x56, 0x52, 0x2d, 0x93,
0x93, 0xf7, 0xfb, 0x99, 0x6f, 0x76, 0xc7, 0x23, 0x88, 0x9e, 0xf6, 0x76, 0xfb, 0x7b, 0x5e, 0x56,
0xd6, 0x59, 0xec, 0xc9, 0xcf, 0x6d, 0xf2, 0x05, 0x46, 0x8f, 0xba, 0x72, 0x3f, 0x8d, 0xbb, 0x33,
0x3a, 0x35, 0x15, 0xbe, 0x86, 0xf3, 0xb5, 0x75, 0x7a, 0x1f, 0x07, 0xd3, 0x60, 0x76, 0xa5, 0x3c,
0x40, 0x84, 0xf0, 0x4e, 0xd3, 0x2e, 0x7e, 0x35, 0x0d, 0x66, 0x43, 0x25, 0xe7, 0x64, 0x03, 0xfd,
0x6f, 0x9c, 0x78, 0xbf, 0x6a, 0xe5, 0xe0, 0xbf, 0x8c, 0x9f, 0x21, 0xe2, 0x64, 0xf2, 0xb9, 0x52,
0x19, 0xdd, 0xbc, 0xf1, 0xed, 0x6f, 0xe7, 0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 0x0a, 0xbe, 0x87, 0xc9, 0xca, 0x16, 0x64, 0x0a, 0x3a, 0x7a, 0xeb, 0x58,
0xac, 0x5d, 0x92, 0xff, 0x81, 0x65, 0x59, 0x8a, 0x3e, 0x11, 0xbd, 0x81, 0x38, 0x87, 0x29, 0xbf,
0x42, 0x19, 0x3a, 0x1e, 0x9c, 0x4f, 0x38, 0x17, 0xc7, 0x29, 0x8d, 0x09, 0x8c, 0xbf, 0xff, 0xc9,
0x52, 0x53, 0xec, 0x8c, 0xd8, 0xa6, 0x62, 0xeb, 0x70, 0x9c, 0xf6, 0x50, 0xd9, 0xd2, 0x92, 0xa9,
0x96, 0x69, 0x5a, 0x19, 0xa2, 0xf8, 0xc2, 0xa7, 0x9d, 0xd0, 0xc9, 0x55, 0xbb, 0x3e, 0xbc, 0xd6,
0x32, 0x69, 0xd9, 0xa3, 0x50, 0x79, 0x80, 0x17, 0xd0, 0x5b, 0x96, 0xa5, 0x2c, 0x4c, 0xa8, 0xf8,
0x98, 0x7c, 0x85, 0x51, 0xbb, 0x00, 0xfc, 0x22, 0x32, 0x3b, 0x5b, 0xa4, 0x24, 0x65, 0x3d, 0xd5,
0x40, 0x8e, 0x2b, 0x74, 0x61, 0x49, 0x4a, 0xfb, 0xca, 0x83, 0xc7, 0xfa, 0xa3, 0xfa, 0x17, 0x00,
0x00, 0xff, 0xff, 0x8f, 0x82, 0xc0, 0x0c, 0x6a, 0x03, 0x00, 0x00,
}

+ 6
- 5
types/proto3/block.proto View File

@ -46,11 +46,12 @@ message Version {
uint64 App = 2;
}
// Timestamp wraps how amino encodes time. Note that this is different from the protobuf well-known type
// protobuf/timestamp.proto in the sense that there seconds and nanos are varint encoded. See:
// 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
// Also nanos do not get skipped if they are zero in amino.
// NOTE/XXX: nanos do not get skipped if they are zero in amino.
message Timestamp {
sfixed64 seconds = 1;
sfixed32 nanos = 2;
int64 seconds = 1;
int32 nanos = 2;
}

+ 9
- 4
types/protobuf.go View File

@ -34,6 +34,10 @@ type tm2pb struct{}
func (tm2pb) Header(header *Header) abci.Header {
return abci.Header{
Version: abci.Version{
Block: header.Version.Block.Uint64(),
App: header.Version.App.Uint64(),
},
ChainID: header.ChainID,
Height: header.Height,
Time: header.Time,
@ -45,10 +49,11 @@ func (tm2pb) Header(header *Header) abci.Header {
LastCommitHash: header.LastCommitHash,
DataHash: header.DataHash,
ValidatorsHash: header.ValidatorsHash,
ConsensusHash: header.ConsensusHash,
AppHash: header.AppHash,
LastResultsHash: header.LastResultsHash,
ValidatorsHash: header.ValidatorsHash,
NextValidatorsHash: header.NextValidatorsHash,
ConsensusHash: header.ConsensusHash,
AppHash: header.AppHash,
LastResultsHash: header.LastResultsHash,
EvidenceHash: header.EvidenceHash,
ProposerAddress: header.ProposerAddress,


+ 67
- 9
types/protobuf_test.go View File

@ -4,12 +4,16 @@ import (
"testing"
"time"
"github.com/golang/protobuf/proto"
"github.com/stretchr/testify/assert"
"github.com/tendermint/go-amino"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/secp256k1"
tmtime "github.com/tendermint/tendermint/types/time"
"github.com/tendermint/tendermint/version"
)
func TestABCIPubKey(t *testing.T) {
@ -67,17 +71,71 @@ func TestABCIConsensusParams(t *testing.T) {
assert.Equal(t, *cp, cp2)
}
func newHeader(
height, numTxs int64,
commitHash, dataHash, evidenceHash []byte,
) *Header {
return &Header{
Height: height,
NumTxs: numTxs,
LastCommitHash: commitHash,
DataHash: dataHash,
EvidenceHash: evidenceHash,
}
}
func TestABCIHeader(t *testing.T) {
header := &Header{
Height: int64(3),
Time: tmtime.Now(),
NumTxs: int64(10),
ProposerAddress: []byte("cloak"),
// build a full header
var height int64 = 5
var numTxs int64 = 3
header := newHeader(
height, numTxs,
[]byte("lastCommitHash"), []byte("dataHash"), []byte("evidenceHash"),
)
protocolVersion := version.Consensus{7, 8}
timestamp := time.Now()
lastBlockID := BlockID{
Hash: []byte("hash"),
PartsHeader: PartSetHeader{
Total: 10,
Hash: []byte("hash"),
},
}
abciHeader := TM2PB.Header(header)
var totalTxs int64 = 100
header.Populate(
protocolVersion, "chainID",
timestamp, lastBlockID, totalTxs,
[]byte("valHash"), []byte("nextValHash"),
[]byte("consHash"), []byte("appHash"), []byte("lastResultsHash"),
[]byte("proposerAddress"),
)
cdc := amino.NewCodec()
headerBz := cdc.MustMarshalBinaryBare(header)
pbHeader := TM2PB.Header(header)
pbHeaderBz, err := proto.Marshal(&pbHeader)
assert.NoError(t, err)
// assert some fields match
assert.EqualValues(t, protocolVersion.Block, pbHeader.Version.Block)
assert.EqualValues(t, protocolVersion.App, pbHeader.Version.App)
assert.EqualValues(t, "chainID", pbHeader.ChainID)
assert.EqualValues(t, height, pbHeader.Height)
assert.EqualValues(t, timestamp, pbHeader.Time)
assert.EqualValues(t, numTxs, pbHeader.NumTxs)
assert.EqualValues(t, totalTxs, pbHeader.TotalTxs)
assert.EqualValues(t, lastBlockID.Hash, pbHeader.LastBlockId.Hash)
assert.EqualValues(t, []byte("lastCommitHash"), pbHeader.LastCommitHash)
assert.Equal(t, []byte("proposerAddress"), pbHeader.ProposerAddress)
// assert the encodings match
// NOTE: they don't yet because Amino encodes
// int64 as zig-zag and we're using non-zigzag in the protobuf.
// See https://github.com/tendermint/tendermint/issues/2682
_, _ = headerBz, pbHeaderBz
// assert.EqualValues(t, headerBz, pbHeaderBz)
assert.Equal(t, int64(3), abciHeader.Height)
assert.Equal(t, []byte("cloak"), abciHeader.ProposerAddress)
}
func TestABCIEvidence(t *testing.T) {


+ 1
- 1
types/results_test.go View File

@ -43,7 +43,7 @@ func TestABCIResults(t *testing.T) {
}
}
func TestABCIBytes(t *testing.T) {
func TestABCIResultsBytes(t *testing.T) {
results := NewResults([]*abci.ResponseDeliverTx{
{Code: 0, Data: []byte{}},
{Code: 0, Data: []byte("one")},


+ 1
- 1
types/vote.go View File

@ -12,7 +12,7 @@ import (
const (
// MaxVoteBytes is a maximum vote size (including amino overhead).
MaxVoteBytes int64 = 200
MaxVoteBytes int64 = 203
)
var (


+ 13
- 13
types/vote_test.go View File

@ -9,7 +9,6 @@ import (
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
"github.com/tendermint/tendermint/crypto/tmhash"
tmtime "github.com/tendermint/tendermint/types/time"
)
func examplePrevote() *Vote {
@ -63,13 +62,13 @@ func TestVoteSignableTestVectors(t *testing.T) {
{
CanonicalizeVote("", &Vote{}),
// NOTE: Height and Round are skipped here. This case needs to be considered while parsing.
[]byte{0xb, 0x22, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
// []byte{0x22, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
[]byte{0x22, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// with proper (fixed size) height and round (PreCommit):
{
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrecommitType}),
[]byte{
0x1f, // total length
0x8, // (field_number << 3) | wire_type
0x2, // PrecommitType
0x11, // (field_number << 3) | wire_type
@ -78,13 +77,12 @@ func TestVoteSignableTestVectors(t *testing.T) {
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
0x22, // (field_number << 3) | wire_type
// remaining fields (timestamp):
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// with proper (fixed size) height and round (PreVote):
{
CanonicalizeVote("", &Vote{Height: 1, Round: 1, Type: PrevoteType}),
[]byte{
0x1f, // total length
0x8, // (field_number << 3) | wire_type
0x1, // PrevoteType
0x11, // (field_number << 3) | wire_type
@ -93,38 +91,36 @@ func TestVoteSignableTestVectors(t *testing.T) {
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
0x22, // (field_number << 3) | wire_type
// remaining fields (timestamp):
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
{
vote,
[]byte{
0x1d, // total length
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
// remaining fields (timestamp):
0x22,
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff},
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1},
},
// containing non-empty chain_id:
{
CanonicalizeVote("test_chain_id", &Vote{Height: 1, Round: 1}),
[]byte{
0x2c, // total length
0x11, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height
0x19, // (field_number << 3) | wire_type
0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // round
// remaining fields:
0x22, // (field_number << 3) | wire_type
0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff, // timestamp
0x22, // (field_number << 3) | wire_type
0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1, // timestamp
0x32, // (field_number << 3) | wire_type
0xd, 0x74, 0x65, 0x73, 0x74, 0x5f, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x5f, 0x69, 0x64}, // chainID
},
}
for i, tc := range tests {
got, err := cdc.MarshalBinary(tc.canonicalVote)
got, err := cdc.MarshalBinaryBare(tc.canonicalVote)
require.NoError(t, err)
require.Equal(t, tc.want, got, "test case #%v: got unexpected sign bytes for Vote.", i)
@ -210,12 +206,16 @@ func TestVoteVerify(t *testing.T) {
}
func TestMaxVoteBytes(t *testing.T) {
// time is varint encoded so need to pick the max.
// year int, month Month, day, hour, min, sec, nsec int, loc *Location
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
vote := &Vote{
ValidatorAddress: tmhash.Sum([]byte("validator_address")),
ValidatorIndex: math.MaxInt64,
Height: math.MaxInt64,
Round: math.MaxInt64,
Timestamp: tmtime.Now(),
Timestamp: timestamp,
Type: PrevoteType,
BlockID: BlockID{
Hash: tmhash.Sum([]byte("blockID_hash")),


Loading…
Cancel
Save