github.com/ewagmig/fabric@v2.1.1+incompatible/gossip/protoext/compatibility_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package protoext_test 8 9 import ( 10 "encoding/hex" 11 "testing" 12 13 "github.com/golang/protobuf/proto" 14 "github.com/hyperledger/fabric-protos-go/gossip" 15 "github.com/hyperledger/fabric/gossip/protoext" 16 "github.com/stretchr/testify/assert" 17 ) 18 19 var digestMsg = &gossip.GossipMessage{ 20 Channel: []byte("mychannel"), 21 Content: &gossip.GossipMessage_DataDig{ 22 DataDig: &gossip.DataDigest{ 23 Digests: [][]byte{ 24 {255}, 25 {255, 255}, 26 {255, 255, 255}, 27 {255, 255, 255, 255}, 28 []byte("100"), 29 }, 30 }, 31 }, 32 } 33 34 var requestMsg = &gossip.GossipMessage{ 35 Channel: []byte("mychannel"), 36 Content: &gossip.GossipMessage_DataReq{ 37 DataReq: &gossip.DataRequest{ 38 Digests: [][]byte{ 39 {255}, 40 {255, 255}, 41 {255, 255, 255}, 42 {255, 255, 255, 255}, 43 []byte("100"), 44 }, 45 }, 46 }, 47 } 48 49 const ( 50 v12DataDigestBytes = "12096d796368616e6e656c52171201ff1202ffff1203ffffff1204ffffffff1203313030" 51 v12DataRequestBytes = "12096d796368616e6e656c5a171201ff1202ffff1203ffffff1204ffffffff1203313030" 52 ) 53 54 func TestUnmarshalV12Digests(t *testing.T) { 55 // This test ensures that digests of data digest messages and data requests 56 // that originated from fabric v1.3 can be successfully parsed by v1.2 57 for msgBytes, expectedMsg := range map[string]*gossip.GossipMessage{ 58 v12DataDigestBytes: digestMsg, 59 v12DataRequestBytes: requestMsg, 60 } { 61 var err error 62 v13Envelope := &gossip.Envelope{} 63 v13Envelope.Payload, err = hex.DecodeString(msgBytes) 64 assert.NoError(t, err) 65 v13Digest, err := protoext.EnvelopeToGossipMessage(v13Envelope) 66 assert.NoError(t, err) 67 assert.True(t, proto.Equal(expectedMsg, v13Digest.GossipMessage)) 68 } 69 }