@@ -18,9 +18,11 @@ package config
18
18
19
19
import (
20
20
"math"
21
+ "reflect"
21
22
"testing"
22
23
23
24
"github.com/hyperledger/fabric/bccsp"
25
+ "github.com/hyperledger/fabric/common/util"
24
26
cb "github.com/hyperledger/fabric/protos/common"
25
27
26
28
logging "github.com/op/go-logging"
@@ -35,6 +37,55 @@ func TestInterface(t *testing.T) {
35
37
_ = Channel (NewChannelGroup (nil ))
36
38
}
37
39
40
+ func TestChannelGroup (t * testing.T ) {
41
+ cg := NewChannelGroup (nil )
42
+ assert .NotNil (t , cg , "ChannelGroup should not be nil" )
43
+ assert .Nil (t , cg .OrdererConfig (), "OrdererConfig should be nil" )
44
+ assert .Nil (t , cg .ApplicationConfig (), "ApplicationConfig should be nil" )
45
+ assert .Nil (t , cg .ConsortiumsConfig (), "ConsortiumsConfig should be nil" )
46
+
47
+ _ , err := cg .NewGroup (ApplicationGroupKey )
48
+ assert .NoError (t , err , "Unexpected error for ApplicationGroupKey" )
49
+ _ , err = cg .NewGroup (OrdererGroupKey )
50
+ assert .NoError (t , err , "Unexpected error for OrdererGroupKey" )
51
+ _ , err = cg .NewGroup (ConsortiumsGroupKey )
52
+ assert .NoError (t , err , "Unexpected error for ConsortiumsGroupKey" )
53
+ _ , err = cg .NewGroup ("BadGroupKey" )
54
+ assert .Error (t , err , "Should have returned error for BadGroupKey" )
55
+
56
+ }
57
+
58
+ func TestChannelConfig (t * testing.T ) {
59
+ cc := NewChannelConfig ()
60
+ assert .NotNil (t , cc , "ChannelConfig should not be nil" )
61
+
62
+ cc .protos = & ChannelProtos {
63
+ HashingAlgorithm : & cb.HashingAlgorithm {Name : bccsp .SHA256 },
64
+ BlockDataHashingStructure : & cb.BlockDataHashingStructure {Width : math .MaxUint32 },
65
+ OrdererAddresses : & cb.OrdererAddresses {Addresses : []string {"127.0.0.1:7050" }},
66
+ }
67
+
68
+ ag := NewApplicationGroup (nil )
69
+ og := NewOrdererGroup (nil )
70
+ csg := NewConsortiumsGroup ()
71
+ good := make (map [string ]ValueProposer )
72
+ good [ApplicationGroupKey ] = ag
73
+ good [OrdererGroupKey ] = og
74
+ good [ConsortiumsGroupKey ] = csg
75
+
76
+ err := cc .Validate (nil , good )
77
+ assert .NoError (t , err , "Unexpected error validating good config groups" )
78
+ err = cc .Validate (nil , map [string ]ValueProposer {ApplicationGroupKey : NewConsortiumsGroup ()})
79
+ assert .Error (t , err , "Expected error validating bad config group" )
80
+ err = cc .Validate (nil , map [string ]ValueProposer {OrdererGroupKey : NewConsortiumsGroup ()})
81
+ assert .Error (t , err , "Expected error validating bad config group" )
82
+ err = cc .Validate (nil , map [string ]ValueProposer {ConsortiumsGroupKey : NewOrdererGroup (nil )})
83
+ assert .Error (t , err , "Expected error validating bad config group" )
84
+ err = cc .Validate (nil , map [string ]ValueProposer {ConsortiumKey : NewConsortiumGroup (nil )})
85
+ assert .Error (t , err , "Expected error validating bad config group" )
86
+
87
+ }
88
+
38
89
func TestHashingAlgorithm (t * testing.T ) {
39
90
cc := & ChannelConfig {protos : & ChannelProtos {HashingAlgorithm : & cb.HashingAlgorithm {}}}
40
91
assert .Error (t , cc .validateHashingAlgorithm (), "Must supply hashing algorithm" )
@@ -43,7 +94,16 @@ func TestHashingAlgorithm(t *testing.T) {
43
94
assert .Error (t , cc .validateHashingAlgorithm (), "Bad hashing algorithm supplied" )
44
95
45
96
cc = & ChannelConfig {protos : & ChannelProtos {HashingAlgorithm : & cb.HashingAlgorithm {Name : bccsp .SHA256 }}}
46
- assert .NoError (t , cc .validateHashingAlgorithm (), "Allowed hashing algorith supplied" )
97
+ assert .NoError (t , cc .validateHashingAlgorithm (), "Allowed hashing algorith SHA256 supplied" )
98
+
99
+ assert .Equal (t , reflect .ValueOf (util .ComputeSHA256 ).Pointer (), reflect .ValueOf (cc .HashingAlgorithm ()).Pointer (),
100
+ "Unexpected hashing algorithm returned" )
101
+
102
+ cc = & ChannelConfig {protos : & ChannelProtos {HashingAlgorithm : & cb.HashingAlgorithm {Name : bccsp .SHA3_256 }}}
103
+ assert .NoError (t , cc .validateHashingAlgorithm (), "Allowed hashing algorith SHA3_256 supplied" )
104
+
105
+ assert .Equal (t , reflect .ValueOf (util .ComputeSHA3256 ).Pointer (), reflect .ValueOf (cc .HashingAlgorithm ()).Pointer (),
106
+ "Unexpected hashing algorithm returned" )
47
107
}
48
108
49
109
func TestBlockDataHashingStructure (t * testing.T ) {
@@ -53,14 +113,34 @@ func TestBlockDataHashingStructure(t *testing.T) {
53
113
cc = & ChannelConfig {protos : & ChannelProtos {BlockDataHashingStructure : & cb.BlockDataHashingStructure {Width : 7 }}}
54
114
assert .Error (t , cc .validateBlockDataHashingStructure (), "Invalid Merkle tree width supplied" )
55
115
56
- cc = & ChannelConfig {protos : & ChannelProtos {BlockDataHashingStructure : & cb.BlockDataHashingStructure {Width : math .MaxUint32 }}}
116
+ var width uint32
117
+ width = math .MaxUint32
118
+ cc = & ChannelConfig {protos : & ChannelProtos {BlockDataHashingStructure : & cb.BlockDataHashingStructure {Width : width }}}
57
119
assert .NoError (t , cc .validateBlockDataHashingStructure (), "Valid Merkle tree width supplied" )
120
+
121
+ assert .Equal (t , width , cc .BlockDataHashingStructureWidth (), "Unexpected width returned" )
58
122
}
59
123
60
124
func TestOrdererAddresses (t * testing.T ) {
61
125
cc := & ChannelConfig {protos : & ChannelProtos {OrdererAddresses : & cb.OrdererAddresses {}}}
62
126
assert .Error (t , cc .validateOrdererAddresses (), "Must supply orderer addresses" )
63
127
64
128
cc = & ChannelConfig {protos : & ChannelProtos {OrdererAddresses : & cb.OrdererAddresses {Addresses : []string {"127.0.0.1:7050" }}}}
65
- assert .NoError (t , cc .validateOrdererAddresses (), "Invalid Merkle tree width supplied" )
129
+ assert .NoError (t , cc .validateOrdererAddresses (), "Invalid orderer address supplied" )
130
+
131
+ assert .Equal (t , "127.0.0.1:7050" , cc .OrdererAddresses ()[0 ], "Unexpected orderer address returned" )
132
+ }
133
+
134
+ func TestConsortiumName (t * testing.T ) {
135
+ cc := & ChannelConfig {protos : & ChannelProtos {Consortium : & cb.Consortium {Name : "TestConsortium" }}}
136
+ assert .Equal (t , "TestConsortium" , cc .ConsortiumName (), "Unexpected consortium name returned" )
137
+ }
138
+
139
+ func TestChannelUtils (t * testing.T ) {
140
+ // these functions all panic if marshaling fails so just executing them is sufficient
141
+ _ = TemplateConsortium ("test" )
142
+ _ = DefaultHashingAlgorithm ()
143
+ _ = DefaultBlockDataHashingStructure ()
144
+ _ = DefaultOrdererAddresses ()
145
+
66
146
}
0 commit comments