From 0372dae42ae8b3e7352ab49fd068dffa931067cd Mon Sep 17 00:00:00 2001 From: Jason Yellick Date: Thu, 19 Jan 2017 16:40:42 -0500 Subject: [PATCH] [FAB-1771] Add chain config mock structure https://jira.hyperledger.org/browse/FAB-1771 This changeset adds a mock structure for the chainconfig.Descriptor. It also fixes a bug in the chainconfig.DescriptorImpl as it did not actually implement the interface. Change-Id: Iab2041dc07c6fc19b586485608068f417619cd16 Signed-off-by: Jason Yellick --- common/chainconfig/chainconfig.go | 2 +- common/chainconfig/chainconfig_test.go | 4 ++ common/mocks/chainconfig/chainconfig.go | 48 ++++++++++++++++++++ common/mocks/chainconfig/chainconfig_test.go | 27 +++++++++++ 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 common/mocks/chainconfig/chainconfig.go create mode 100644 common/mocks/chainconfig/chainconfig_test.go diff --git a/common/chainconfig/chainconfig.go b/common/chainconfig/chainconfig.go index 8ebbeed9f9b..ce7bb797e0c 100644 --- a/common/chainconfig/chainconfig.go +++ b/common/chainconfig/chainconfig.go @@ -57,7 +57,7 @@ type Descriptor interface { // BlockDataHashingStructureWidth returns the width to use when constructing the // Merkle tree to compute the BlockData hash - BlockDatahashingStructureWidth() int + BlockDataHashingStructureWidth() uint32 // OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver OrdererAddresses() []string diff --git a/common/chainconfig/chainconfig_test.go b/common/chainconfig/chainconfig_test.go index 8a0a2bf6651..721042dcbc1 100644 --- a/common/chainconfig/chainconfig_test.go +++ b/common/chainconfig/chainconfig_test.go @@ -37,6 +37,10 @@ func makeInvalidConfigItem(key string) *cb.ConfigurationItem { } } +func TestInterface(t *testing.T) { + _ = Descriptor(NewDescriptorImpl()) +} + func TestDoubleBegin(t *testing.T) { defer func() { if err := recover(); err == nil { diff --git a/common/mocks/chainconfig/chainconfig.go b/common/mocks/chainconfig/chainconfig.go new file mode 100644 index 00000000000..8b398c9735b --- /dev/null +++ b/common/mocks/chainconfig/chainconfig.go @@ -0,0 +1,48 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package chainconfig + +import "github.com/hyperledger/fabric/common/util" + +func nearIdentityHash(input []byte) []byte { + return util.ConcatenateBytes([]byte("Hash("), input, []byte("")) +} + +// Descriptor is a mock implementation of sharedconfig.Descriptor +type Descriptor struct { + // HashingAlgorithmVal is returned as the result of HashingAlgorithm() + HashingAlgorithmVal func([]byte) []byte + // BlockDataHashingStructureWidthVal is returned as the result of BlockDataHashingStructureWidth() + BlockDataHashingStructureWidthVal uint32 + // OrdererAddressesVal is returned as the result of OrdererAddresses() + OrdererAddressesVal []string +} + +// HashingAlgorithm returns the HashingAlgorithmVal +func (scm *Descriptor) HashingAlgorithm() func([]byte) []byte { + return scm.HashingAlgorithmVal +} + +// BlockDataHashingStructureWidth returns the BlockDataHashingStructureWidthVal +func (scm *Descriptor) BlockDataHashingStructureWidth() uint32 { + return scm.BlockDataHashingStructureWidthVal +} + +// OrdererAddresses returns the OrdererAddressesVal +func (scm *Descriptor) OrdererAddresses() []string { + return scm.OrdererAddressesVal +} diff --git a/common/mocks/chainconfig/chainconfig_test.go b/common/mocks/chainconfig/chainconfig_test.go new file mode 100644 index 00000000000..ba93bc97e1e --- /dev/null +++ b/common/mocks/chainconfig/chainconfig_test.go @@ -0,0 +1,27 @@ +/* +Copyright IBM Corp. 2016 All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package chainconfig + +import ( + "testing" + + "github.com/hyperledger/fabric/common/chainconfig" +) + +func TestChainConfigInterface(t *testing.T) { + _ = chainconfig.Descriptor(&Descriptor{}) +}