github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/chaincode/metadata_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package chaincode 8 9 import ( 10 "testing" 11 12 "github.com/hyperledger/fabric-protos-go/gossip" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func TestToChaincodes(t *testing.T) { 17 ccs := MetadataSet{ 18 { 19 Name: "foo", 20 Version: "1.0", 21 }, 22 } 23 assert.Equal(t, []*gossip.Chaincode{ 24 {Name: "foo", Version: "1.0"}, 25 }, ccs.AsChaincodes()) 26 } 27 28 func TestMetadataMapping(t *testing.T) { 29 mm := NewMetadataMapping() 30 md1 := Metadata{ 31 Name: "cc1", 32 Id: []byte{1}, 33 Version: "1.0", 34 Policy: []byte{1, 2, 3}, 35 } 36 mm.Update(md1) 37 res, found := mm.Lookup("cc1") 38 assert.Equal(t, md1, res) 39 assert.True(t, found) 40 res, found = mm.Lookup("cc2") 41 assert.Zero(t, res) 42 assert.False(t, found) 43 md2 := Metadata{ 44 Name: "cc1", 45 Id: []byte{1}, 46 Version: "1.1", 47 Policy: []byte{2, 2, 2}, 48 } 49 mm.Update(md2) 50 res, found = mm.Lookup("cc1") 51 assert.True(t, found) 52 assert.Equal(t, md2, res) 53 54 assert.Equal(t, MetadataSet{md2}, mm.Aggregate()) 55 }