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
This commit is contained in:
Ethan Buchman
2018-10-23 13:21:47 -04:00
committed by GitHub
parent fe1d59ab7b
commit be929acd6a
14 changed files with 187 additions and 103 deletions

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 TestABCIHeader(t *testing.T) {
header := &Header{
Height: int64(3),
Time: tmtime.Now(),
NumTxs: int64(10),
ProposerAddress: []byte("cloak"),
func newHeader(
height, numTxs int64,
commitHash, dataHash, evidenceHash []byte,
) *Header {
return &Header{
Height: height,
NumTxs: numTxs,
LastCommitHash: commitHash,
DataHash: dataHash,
EvidenceHash: evidenceHash,
}
abciHeader := TM2PB.Header(header)
}
func TestABCIHeader(t *testing.T) {
// 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"),
},
}
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) {