From 309a6772d7d04f1a2072191e030b86acf08c49ae Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Sun, 5 Aug 2018 16:29:01 -0400 Subject: [PATCH] types: fix formatting when printing signatures - use cmn.Fingerprint and %X --- types/proposal.go | 7 +++++-- types/proposal_test.go | 2 +- types/vote.go | 21 +++++++++++---------- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/types/proposal.go b/types/proposal.go index d5ae54926..81a5e2c33 100644 --- a/types/proposal.go +++ b/types/proposal.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" "time" + + cmn "github.com/tendermint/tendermint/libs/common" ) var ( @@ -41,9 +43,10 @@ func NewProposal(height int64, round int, blockPartsHeader PartSetHeader, polRou // String returns a string representation of the Proposal. func (p *Proposal) String() string { - return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %v @ %s}", + return fmt.Sprintf("Proposal{%v/%v %v (%v,%v) %X @ %s}", p.Height, p.Round, p.BlockPartsHeader, p.POLRound, - p.POLBlockID, p.Signature, CanonicalTime(p.Timestamp)) + p.POLBlockID, + cmn.Fingerprint(p.Signature), CanonicalTime(p.Timestamp)) } // SignBytes returns the Proposal bytes for signing diff --git a/types/proposal_test.go b/types/proposal_test.go index b5c6bdced..7396fb767 100644 --- a/types/proposal_test.go +++ b/types/proposal_test.go @@ -39,7 +39,7 @@ func TestProposalSignable(t *testing.T) { func TestProposalString(t *testing.T) { str := testProposal.String() - expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) [] @ 2018-02-11T07:09:22.765Z}` + expected := `Proposal{12345/23456 111:626C6F636B70 (-1,:0:000000000000) 000000000000 @ 2018-02-11T07:09:22.765Z}` if str != expected { t.Errorf("Got unexpected string for Proposal. Expected:\n%v\nGot:\n%v", expected, str) } diff --git a/types/vote.go b/types/vote.go index a586615dd..9a6180d75 100644 --- a/types/vote.go +++ b/types/vote.go @@ -61,14 +61,14 @@ type Address = cmn.HexBytes // Represents a prevote, precommit, or commit vote from validators for consensus. type Vote struct { - ValidatorAddress Address `json:"validator_address"` - ValidatorIndex int `json:"validator_index"` - Height int64 `json:"height"` - Round int `json:"round"` - Timestamp time.Time `json:"timestamp"` - Type byte `json:"type"` - BlockID BlockID `json:"block_id"` // zero if vote is nil. - Signature []byte `json:"signature"` + ValidatorAddress Address `json:"validator_address"` + ValidatorIndex int `json:"validator_index"` + Height int64 `json:"height"` + Round int `json:"round"` + Timestamp time.Time `json:"timestamp"` + Type byte `json:"type"` + BlockID BlockID `json:"block_id"` // zero if vote is nil. + Signature []byte `json:"signature"` } func (vote *Vote) SignBytes(chainID string) []byte { @@ -98,10 +98,11 @@ func (vote *Vote) String() string { cmn.PanicSanity("Unknown vote type") } - return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %v @ %s}", + return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X @ %s}", vote.ValidatorIndex, cmn.Fingerprint(vote.ValidatorAddress), vote.Height, vote.Round, vote.Type, typeString, - cmn.Fingerprint(vote.BlockID.Hash), vote.Signature, + cmn.Fingerprint(vote.BlockID.Hash), + cmn.Fingerprint(vote.Signature), CanonicalTime(vote.Timestamp)) }