From 7b5a73264422dcb2aad2d8e16db3af3584f5e75d Mon Sep 17 00:00:00 2001 From: Marko Date: Thu, 20 May 2021 14:33:46 +0000 Subject: [PATCH] consensus: add test vector for hasvote (#6469) ## Description adds a test vector for hasvote in order to extra sure https://github.com/tendermint/tendermint/pull/6287 isnt breaking --- proto/tendermint/consensus/message_test.go | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 proto/tendermint/consensus/message_test.go diff --git a/proto/tendermint/consensus/message_test.go b/proto/tendermint/consensus/message_test.go new file mode 100644 index 000000000..21c3c4faa --- /dev/null +++ b/proto/tendermint/consensus/message_test.go @@ -0,0 +1,32 @@ +package consensus_test + +import ( + "encoding/hex" + "math" + "testing" + + "github.com/gogo/protobuf/proto" + "github.com/stretchr/testify/require" + + tmcons "github.com/tendermint/tendermint/proto/tendermint/consensus" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" +) + +func TestHasVoteVector(t *testing.T) { + testCases := []struct { + msg tmcons.HasVote + expBytes string + }{ + {tmcons.HasVote{1, 3, tmproto.PrevoteType, 1}, "3a080801100318012001"}, + {tmcons.HasVote{2, 2, tmproto.PrecommitType, 2}, "3a080802100218022002"}, + {tmcons.HasVote{math.MaxInt64, math.MaxInt32, tmproto.ProposalType, math.MaxInt32}, + "3a1808ffffffffffffffff7f10ffffffff07182020ffffffff07"}, + } + + for i, tc := range testCases { + msg := tmcons.Message{&tmcons.Message_HasVote{HasVote: &tc.msg}} + bz, err := proto.Marshal(&msg) + require.NoError(t, err) + require.Equal(t, tc.expBytes, hex.EncodeToString(bz), "test vector failed", i) + } +}