mirror of
https://github.com/tendermint/tendermint.git
synced 2026-07-19 14:32:21 +00:00
Merge remote-tracking branch 'origin/master' into p2p-dialer-store-change
This commit is contained in:
@@ -42,7 +42,7 @@ require (
|
||||
github.com/creachadair/taskgroup v0.3.2
|
||||
github.com/golangci/golangci-lint v1.46.0
|
||||
github.com/google/go-cmp v0.5.8
|
||||
github.com/vektra/mockery/v2 v2.13.0
|
||||
github.com/vektra/mockery/v2 v2.13.1
|
||||
gotest.tools v2.2.0+incompatible
|
||||
)
|
||||
|
||||
|
||||
@@ -1116,8 +1116,8 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
|
||||
github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus=
|
||||
github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8=
|
||||
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
|
||||
github.com/vektra/mockery/v2 v2.13.0 h1:jzHQuiWMbLK52usAz/3wyIf07gZnACOsTJ8/AcHA/2s=
|
||||
github.com/vektra/mockery/v2 v2.13.0/go.mod h1:bnD1T8tExSgPD1ripLkDbr60JA9VtQeu12P3wgLZd7M=
|
||||
github.com/vektra/mockery/v2 v2.13.1 h1:Lqs7aZiC7TwZO76fJ/4Zsb3NaO4F7cuuz0mZLYeNwtQ=
|
||||
github.com/vektra/mockery/v2 v2.13.1/go.mod h1:bnD1T8tExSgPD1ripLkDbr60JA9VtQeu12P3wgLZd7M=
|
||||
github.com/viki-org/dnscache v0.0.0-20130720023526-c70c1f23c5d8/go.mod h1:dniwbG03GafCjFohMDmz6Zc6oCuiqgH6tGNyXTkHzXE=
|
||||
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
|
||||
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
|
||||
|
||||
@@ -455,7 +455,7 @@ func TestRouter_AcceptPeers_Errors(t *testing.T) {
|
||||
// the router from calling Accept again.
|
||||
mockTransport := &mocks.Transport{}
|
||||
mockTransport.On("String").Maybe().Return("mock")
|
||||
mockTransport.On("Accept", mock.Anything).Once().Return(nil, io.EOF)
|
||||
mockTransport.On("Accept", mock.Anything).Once().Return(nil, err)
|
||||
mockTransport.On("Close").Return(nil)
|
||||
mockTransport.On("Listen", mock.Anything).Return(nil)
|
||||
|
||||
|
||||
+13
-6
@@ -13,7 +13,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
nilVoteStr string = "nil-Vote"
|
||||
absentVoteStr string = "Vote{absent}"
|
||||
nilVoteStr string = "nil"
|
||||
|
||||
// The maximum supported number of bytes in a vote extension.
|
||||
MaxVoteExtensionSize int = 1024 * 1024
|
||||
@@ -189,7 +190,7 @@ func (vote *Vote) Copy() *Vote {
|
||||
// 10. timestamp
|
||||
func (vote *Vote) String() string {
|
||||
if vote == nil {
|
||||
return nilVoteStr
|
||||
return absentVoteStr
|
||||
}
|
||||
|
||||
var typeString string
|
||||
@@ -202,16 +203,22 @@ func (vote *Vote) String() string {
|
||||
panic("Unknown vote type")
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Vote{%v:%X %v/%02d/%v(%v) %X %X %X @ %s}",
|
||||
var blockHashString string
|
||||
if len(vote.BlockID.Hash) > 0 {
|
||||
blockHashString = fmt.Sprintf("%X", tmbytes.Fingerprint(vote.BlockID.Hash))
|
||||
} else {
|
||||
blockHashString = nilVoteStr
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Vote{%v:%X %v/%d %s %s %X %d @ %s}",
|
||||
vote.ValidatorIndex,
|
||||
tmbytes.Fingerprint(vote.ValidatorAddress),
|
||||
vote.Height,
|
||||
vote.Round,
|
||||
vote.Type,
|
||||
typeString,
|
||||
tmbytes.Fingerprint(vote.BlockID.Hash),
|
||||
blockHashString,
|
||||
tmbytes.Fingerprint(vote.Signature),
|
||||
tmbytes.Fingerprint(vote.Extension),
|
||||
len(vote.Extension),
|
||||
CanonicalTime(vote.Timestamp),
|
||||
)
|
||||
}
|
||||
|
||||
+2
-2
@@ -505,7 +505,7 @@ func (voteSet *VoteSet) StringIndented(indent string) string {
|
||||
voteStrings := make([]string, len(voteSet.votes))
|
||||
for i, vote := range voteSet.votes {
|
||||
if vote == nil {
|
||||
voteStrings[i] = nilVoteStr
|
||||
voteStrings[i] = absentVoteStr
|
||||
} else {
|
||||
voteStrings[i] = vote.String()
|
||||
}
|
||||
@@ -570,7 +570,7 @@ func (voteSet *VoteSet) voteStrings() []string {
|
||||
voteStrings := make([]string, len(voteSet.votes))
|
||||
for i, vote := range voteSet.votes {
|
||||
if vote == nil {
|
||||
voteStrings[i] = nilVoteStr
|
||||
voteStrings[i] = absentVoteStr
|
||||
} else {
|
||||
voteStrings[i] = vote.String()
|
||||
}
|
||||
|
||||
+52
-8
@@ -2,6 +2,7 @@ package types
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -16,6 +17,22 @@ import (
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
)
|
||||
|
||||
const (
|
||||
//nolint: lll
|
||||
preCommitTestStr = `Vote{56789:6AF1F4111082 12345/2 Precommit 8B01023386C3 000000000000 0 @ 2017-12-25T03:00:01.234Z}`
|
||||
//nolint: lll
|
||||
preVoteTestStr = `Vote{56789:6AF1F4111082 12345/2 Prevote 8B01023386C3 000000000000 0 @ 2017-12-25T03:00:01.234Z}`
|
||||
)
|
||||
|
||||
var (
|
||||
// nolint: lll
|
||||
nilVoteTestStr = fmt.Sprintf(`Vote{56789:6AF1F4111082 12345/2 Precommit %s 000000000000 0 @ 2017-12-25T03:00:01.234Z}`, nilVoteStr)
|
||||
formatNonEmptyVoteExtensionFn = func(voteExtensionLength int) string {
|
||||
// nolint: lll
|
||||
return fmt.Sprintf(`Vote{56789:6AF1F4111082 12345/2 Precommit 8B01023386C3 000000000000 %d @ 2017-12-25T03:00:01.234Z}`, voteExtensionLength)
|
||||
}
|
||||
)
|
||||
|
||||
func examplePrevote(t *testing.T) *Vote {
|
||||
t.Helper()
|
||||
return exampleVote(t, byte(tmproto.PrevoteType))
|
||||
@@ -321,16 +338,43 @@ func TestVoteVerify(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestVoteString(t *testing.T) {
|
||||
str := examplePrecommit(t).String()
|
||||
expected := `Vote{56789:6AF1F4111082 12345/02/SIGNED_MSG_TYPE_PRECOMMIT(Precommit) 8B01023386C3 000000000000 000000000000 @ 2017-12-25T03:00:01.234Z}` //nolint:lll //ignore line length for tests
|
||||
if str != expected {
|
||||
t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str)
|
||||
testcases := map[string]struct {
|
||||
vote *Vote
|
||||
expectedResult string
|
||||
}{
|
||||
"pre-commit": {
|
||||
vote: examplePrecommit(t),
|
||||
expectedResult: preCommitTestStr,
|
||||
},
|
||||
"pre-vote": {
|
||||
vote: examplePrevote(t),
|
||||
expectedResult: preVoteTestStr,
|
||||
},
|
||||
"absent vote": {
|
||||
expectedResult: absentVoteStr,
|
||||
},
|
||||
"nil vote": {
|
||||
vote: func() *Vote {
|
||||
v := examplePrecommit(t)
|
||||
v.BlockID.Hash = nil
|
||||
return v
|
||||
}(),
|
||||
expectedResult: nilVoteTestStr,
|
||||
},
|
||||
"non-empty vote extension": {
|
||||
vote: func() *Vote {
|
||||
v := examplePrecommit(t)
|
||||
v.Extension = []byte{1, 2}
|
||||
return v
|
||||
}(),
|
||||
expectedResult: formatNonEmptyVoteExtensionFn(2),
|
||||
},
|
||||
}
|
||||
|
||||
str2 := examplePrevote(t).String()
|
||||
expected = `Vote{56789:6AF1F4111082 12345/02/SIGNED_MSG_TYPE_PREVOTE(Prevote) 8B01023386C3 000000000000 000000000000 @ 2017-12-25T03:00:01.234Z}` //nolint:lll //ignore line length for tests
|
||||
if str2 != expected {
|
||||
t.Errorf("got unexpected string for Vote. Expected:\n%v\nGot:\n%v", expected, str2)
|
||||
for name, tc := range testcases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
require.Equal(t, tc.expectedResult, tc.vote.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user