github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/channelconfig/realconfig_test.go (about) 1 /* 2 Copyright IBM Corp. All Rights Reserved. 3 4 SPDX-License-Identifier: Apache-2.0 5 */ 6 7 package channelconfig_test 8 9 import ( 10 "testing" 11 12 "github.com/hyperledger/fabric/bccsp/sw" 13 "github.com/hyperledger/fabric/common/channelconfig" 14 "github.com/hyperledger/fabric/core/config/configtest" 15 "github.com/hyperledger/fabric/internal/configtxgen/encoder" 16 "github.com/hyperledger/fabric/internal/configtxgen/genesisconfig" 17 "github.com/hyperledger/fabric/protoutil" 18 "github.com/stretchr/testify/assert" 19 ) 20 21 func TestWithRealConfigtx(t *testing.T) { 22 conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) 23 24 gb := encoder.New(conf).GenesisBlockForChannel("foo") 25 env := protoutil.ExtractEnvelopeOrPanic(gb, 0) 26 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 27 assert.NoError(t, err) 28 29 _, err = channelconfig.NewBundleFromEnvelope(env, cryptoProvider) 30 assert.NoError(t, err) 31 } 32 33 func TestOrgSpecificOrdererEndpoints(t *testing.T) { 34 t.Run("Without_Capability", func(t *testing.T) { 35 conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) 36 conf.Capabilities = map[string]bool{"V1_3": true} 37 38 cg, err := encoder.NewChannelGroup(conf) 39 assert.NoError(t, err) 40 41 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 42 assert.NoError(t, err) 43 _, err = channelconfig.NewChannelConfig(cg, cryptoProvider) 44 assert.EqualError(t, err, "could not create channel Orderer sub-group config: Orderer Org SampleOrg cannot contain endpoints value until V1_4_2+ capabilities have been enabled") 45 }) 46 47 t.Run("Without_Capability_NoOSNs", func(t *testing.T) { 48 conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) 49 conf.Capabilities = map[string]bool{"V1_3": true} 50 conf.Orderer.Organizations[0].OrdererEndpoints = nil 51 conf.Orderer.Addresses = []string{} 52 53 cg, err := encoder.NewChannelGroup(conf) 54 assert.NoError(t, err) 55 56 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 57 assert.NoError(t, err) 58 _, err = channelconfig.NewChannelConfig(cg, cryptoProvider) 59 assert.EqualError(t, err, "Must set some OrdererAddresses") 60 }) 61 62 t.Run("With_Capability", func(t *testing.T) { 63 conf := genesisconfig.Load(genesisconfig.SampleDevModeSoloProfile, configtest.GetDevConfigDir()) 64 conf.Capabilities = map[string]bool{"V2_0": true} 65 assert.NotEmpty(t, conf.Orderer.Organizations[0].OrdererEndpoints) 66 67 cg, err := encoder.NewChannelGroup(conf) 68 assert.NoError(t, err) 69 70 cryptoProvider, err := sw.NewDefaultSecurityLevelWithKeystore(sw.NewDummyKeyStore()) 71 assert.NoError(t, err) 72 cc, err := channelconfig.NewChannelConfig(cg, cryptoProvider) 73 assert.NoError(t, err) 74 75 err = cc.Validate(cc.Capabilities()) 76 assert.NoError(t, err) 77 78 assert.NotEmpty(t, cc.OrdererConfig().Organizations()["SampleOrg"].Endpoints) 79 }) 80 81 }