Skip to content

Commit

Permalink
[FAB-1771] Add chain config mock structure
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jan 20, 2017
1 parent 8c6fe20 commit 0372dae
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion common/chainconfig/chainconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions common/chainconfig/chainconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
48 changes: 48 additions & 0 deletions common/mocks/chainconfig/chainconfig.go
Original file line number Diff line number Diff line change
@@ -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
}
27 changes: 27 additions & 0 deletions common/mocks/chainconfig/chainconfig_test.go
Original file line number Diff line number Diff line change
@@ -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{})
}

0 comments on commit 0372dae

Please sign in to comment.