Skip to content

Commit 0372dae

Browse files
author
Jason Yellick
committed
[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 <[email protected]>
1 parent 8c6fe20 commit 0372dae

File tree

4 files changed

+80
-1
lines changed

4 files changed

+80
-1
lines changed

common/chainconfig/chainconfig.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ type Descriptor interface {
5757

5858
// BlockDataHashingStructureWidth returns the width to use when constructing the
5959
// Merkle tree to compute the BlockData hash
60-
BlockDatahashingStructureWidth() int
60+
BlockDataHashingStructureWidth() uint32
6161

6262
// OrdererAddresses returns the list of valid orderer addresses to connect to to invoke Broadcast/Deliver
6363
OrdererAddresses() []string

common/chainconfig/chainconfig_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ func makeInvalidConfigItem(key string) *cb.ConfigurationItem {
3737
}
3838
}
3939

40+
func TestInterface(t *testing.T) {
41+
_ = Descriptor(NewDescriptorImpl())
42+
}
43+
4044
func TestDoubleBegin(t *testing.T) {
4145
defer func() {
4246
if err := recover(); err == nil {
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 chainconfig
18+
19+
import "github.com/hyperledger/fabric/common/util"
20+
21+
func nearIdentityHash(input []byte) []byte {
22+
return util.ConcatenateBytes([]byte("Hash("), input, []byte(""))
23+
}
24+
25+
// Descriptor is a mock implementation of sharedconfig.Descriptor
26+
type Descriptor struct {
27+
// HashingAlgorithmVal is returned as the result of HashingAlgorithm()
28+
HashingAlgorithmVal func([]byte) []byte
29+
// BlockDataHashingStructureWidthVal is returned as the result of BlockDataHashingStructureWidth()
30+
BlockDataHashingStructureWidthVal uint32
31+
// OrdererAddressesVal is returned as the result of OrdererAddresses()
32+
OrdererAddressesVal []string
33+
}
34+
35+
// HashingAlgorithm returns the HashingAlgorithmVal
36+
func (scm *Descriptor) HashingAlgorithm() func([]byte) []byte {
37+
return scm.HashingAlgorithmVal
38+
}
39+
40+
// BlockDataHashingStructureWidth returns the BlockDataHashingStructureWidthVal
41+
func (scm *Descriptor) BlockDataHashingStructureWidth() uint32 {
42+
return scm.BlockDataHashingStructureWidthVal
43+
}
44+
45+
// OrdererAddresses returns the OrdererAddressesVal
46+
func (scm *Descriptor) OrdererAddresses() []string {
47+
return scm.OrdererAddressesVal
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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 chainconfig
18+
19+
import (
20+
"testing"
21+
22+
"github.com/hyperledger/fabric/common/chainconfig"
23+
)
24+
25+
func TestChainConfigInterface(t *testing.T) {
26+
_ = chainconfig.Descriptor(&Descriptor{})
27+
}

0 commit comments

Comments
 (0)