diff --git a/types/vote_test.go b/types/vote_test.go index e4bf658bc..af8a9625b 100644 --- a/types/vote_test.go +++ b/types/vote_test.go @@ -67,23 +67,23 @@ func TestVoteSignable(t *testing.T) { require.Equal(t, expected, signBytes, "Got unexpected sign bytes for Vote.") } -func TestVoteSignableTestVectors(t *testing.T) { - vote := CanonicalizeVote("", &Vote{Height: 1, Round: 1}) +func TestVoteSignBytesTestVectors(t *testing.T) { tests := []struct { - canonicalVote CanonicalVote - want []byte + chainID string + vote *Vote + want []byte }{ - { - CanonicalizeVote("", &Vote{}), + 0: { + "", &Vote{}, // NOTE: Height and Round are skipped here. This case needs to be considered while parsing. - // []byte{0x2a, 0x9, 0x9, 0x0, 0x9, 0x6e, 0x88, 0xf1, 0xff, 0xff, 0xff}, - []byte{0x2a, 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, + []byte{0xd, 0x2a, 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}), + 1: { + "", &Vote{Height: 1, Round: 1, Type: PrecommitType}, []byte{ + 0x21, // length 0x8, // (field_number << 3) | wire_type 0x2, // PrecommitType 0x11, // (field_number << 3) | wire_type @@ -95,9 +95,10 @@ func TestVoteSignableTestVectors(t *testing.T) { 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}), + 2: { + "", &Vote{Height: 1, Round: 1, Type: PrevoteType}, []byte{ + 0x21, // length 0x8, // (field_number << 3) | wire_type 0x1, // PrevoteType 0x11, // (field_number << 3) | wire_type @@ -108,9 +109,10 @@ func TestVoteSignableTestVectors(t *testing.T) { // remaining fields (timestamp): 0xb, 0x8, 0x80, 0x92, 0xb8, 0xc3, 0x98, 0xfe, 0xff, 0xff, 0xff, 0x1}, }, - { - vote, + 3: { + "", &Vote{Height: 1, Round: 1}, []byte{ + 0x1f, // length 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height 0x19, // (field_number << 3) | wire_type @@ -120,9 +122,10 @@ func TestVoteSignableTestVectors(t *testing.T) { 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}), + 4: { + "test_chain_id", &Vote{Height: 1, Round: 1}, []byte{ + 0x2e, // length 0x11, // (field_number << 3) | wire_type 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, // height 0x19, // (field_number << 3) | wire_type @@ -135,9 +138,7 @@ func TestVoteSignableTestVectors(t *testing.T) { }, } for i, tc := range tests { - got, err := cdc.MarshalBinaryBare(tc.canonicalVote) - require.NoError(t, err) - + got := tc.vote.SignBytes(tc.chainID) require.Equal(t, tc.want, got, "test case #%v: got unexpected sign bytes for Vote.", i) } }