github.com/yacovm/fabric@v2.0.0-alpha.0.20191128145320-c5d4087dc723+incompatible/common/mocks/config/channel.go (about) 1 /* 2 Copyright IBM Corp. 2016 All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package config 18 19 import ( 20 "github.com/hyperledger/fabric/common/channelconfig" 21 "github.com/hyperledger/fabric/common/util" 22 "github.com/hyperledger/fabric/msp" 23 ) 24 25 func nearIdentityHash(input []byte) []byte { 26 return util.ConcatenateBytes([]byte("FakeHash("), input, []byte("")) 27 } 28 29 // Channel is a mock implementation of config.Channel 30 type Channel struct { 31 // HashingAlgorithmVal is returned as the result of HashingAlgorithm() if set 32 HashingAlgorithmVal func([]byte) []byte 33 // BlockDataHashingStructureWidthVal is returned as the result of BlockDataHashingStructureWidth() 34 BlockDataHashingStructureWidthVal uint32 35 // OrdererAddressesVal is returned as the result of OrdererAddresses() 36 OrdererAddressesVal []string 37 // CapabilitiesVal is returned as the result of Capabilities() 38 CapabilitiesVal channelconfig.ChannelCapabilities 39 } 40 41 // HashingAlgorithm returns the HashingAlgorithmVal if set, otherwise a fake simple hash function 42 func (scm *Channel) HashingAlgorithm() func([]byte) []byte { 43 if scm.HashingAlgorithmVal == nil { 44 return nearIdentityHash 45 } 46 return scm.HashingAlgorithmVal 47 } 48 49 // BlockDataHashingStructureWidth returns the BlockDataHashingStructureWidthVal 50 func (scm *Channel) BlockDataHashingStructureWidth() uint32 { 51 return scm.BlockDataHashingStructureWidthVal 52 } 53 54 // OrdererAddresses returns the OrdererAddressesVal 55 func (scm *Channel) OrdererAddresses() []string { 56 return scm.OrdererAddressesVal 57 } 58 59 // Capabilities returns CapabilitiesVal 60 func (scm *Channel) Capabilities() channelconfig.ChannelCapabilities { 61 return scm.CapabilitiesVal 62 } 63 64 // ChannelCapabilities mocks the channelconfig.ChannelCapabilities interface 65 type ChannelCapabilities struct { 66 // SupportedErr is returned by Supported() 67 SupportedErr error 68 69 // MSPVersionVal is returned by MSPVersion() 70 MSPVersionVal msp.MSPVersion 71 72 ConsensusTypeMigrationVal bool 73 } 74 75 func (cc *ChannelCapabilities) OrgSpecificOrdererEndpoints() bool { 76 // refusing to extend this bespoke mock 77 // If you want to override this return value, generate your own mock.. 78 return false 79 } 80 81 // Supported returns SupportedErr 82 func (cc *ChannelCapabilities) Supported() error { 83 return cc.SupportedErr 84 } 85 86 // MSPVersion returns MSPVersionVal 87 func (cc *ChannelCapabilities) MSPVersion() msp.MSPVersion { 88 return cc.MSPVersionVal 89 } 90 91 // ConsensusTypeMigration returns ConsensusTypeMigrationVal 92 func (cc *ChannelCapabilities) ConsensusTypeMigration() bool { 93 return cc.ConsensusTypeMigrationVal 94 }