@@ -21,7 +21,6 @@ import (
2121 "testing"
2222
2323 cb "github.com/hyperledger/fabric/protos/common"
24- "github.com/hyperledger/fabric/protos/utils"
2524
2625 logging "github.com/op/go-logging"
2726)
@@ -30,6 +29,14 @@ func init() {
3029 logging .SetLevel (logging .DEBUG , "" )
3130}
3231
32+ func makeInvalidConfigItem (key string ) * cb.ConfigurationItem {
33+ return & cb.ConfigurationItem {
34+ Type : cb .ConfigurationItem_Chain ,
35+ Key : key ,
36+ Value : []byte ("Garbage Data" ),
37+ }
38+ }
39+
3340func TestDoubleBegin (t * testing.T ) {
3441 defer func () {
3542 if err := recover (); err == nil {
@@ -63,22 +70,10 @@ func TestRollback(t *testing.T) {
6370}
6471
6572func TestHashingAlgorithm (t * testing.T ) {
66- invalidMessage :=
67- & cb.ConfigurationItem {
68- Type : cb .ConfigurationItem_Chain ,
69- Key : HashingAlgorithmKey ,
70- Value : []byte ("Garbage Data" ),
71- }
72- invalidAlgorithm := & cb.ConfigurationItem {
73- Type : cb .ConfigurationItem_Chain ,
74- Key : HashingAlgorithmKey ,
75- Value : utils .MarshalOrPanic (& cb.HashingAlgorithm {Name : "MD5" }),
76- }
77- validAlgorithm := & cb.ConfigurationItem {
78- Type : cb .ConfigurationItem_Chain ,
79- Key : HashingAlgorithmKey ,
80- Value : utils .MarshalOrPanic (& cb.HashingAlgorithm {Name : SHA3Shake256 }),
81- }
73+ invalidMessage := makeInvalidConfigItem (HashingAlgorithmKey )
74+ invalidAlgorithm := TemplateHashingAlgorithm ("MD5" )
75+ validAlgorithm := DefaultHashingAlgorithm ()
76+
8277 m := NewDescriptorImpl ()
8378 m .BeginConfig ()
8479
@@ -105,23 +100,10 @@ func TestHashingAlgorithm(t *testing.T) {
105100}
106101
107102func TestBlockDataHashingStructure (t * testing.T ) {
108- expectedWidth := uint32 (7 )
109- invalidMessage :=
110- & cb.ConfigurationItem {
111- Type : cb .ConfigurationItem_Chain ,
112- Key : BlockDataHashingStructureKey ,
113- Value : []byte ("Garbage Data" ),
114- }
115- invalidWidth := & cb.ConfigurationItem {
116- Type : cb .ConfigurationItem_Chain ,
117- Key : BlockDataHashingStructureKey ,
118- Value : utils .MarshalOrPanic (& cb.BlockDataHashingStructure {Width : 0 }),
119- }
120- validWidth := & cb.ConfigurationItem {
121- Type : cb .ConfigurationItem_Chain ,
122- Key : BlockDataHashingStructureKey ,
123- Value : utils .MarshalOrPanic (& cb.BlockDataHashingStructure {Width : expectedWidth }),
124- }
103+ invalidMessage := makeInvalidConfigItem (BlockDataHashingStructureKey )
104+ invalidWidth := TemplateBlockDataHashingStructure (0 )
105+ validWidth := DefaultBlockDataHashingStructure ()
106+
125107 m := NewDescriptorImpl ()
126108 m .BeginConfig ()
127109
@@ -142,23 +124,14 @@ func TestBlockDataHashingStructure(t *testing.T) {
142124
143125 m .CommitConfig ()
144126
145- if newWidth := m .BlockDataHashingStructureWidth (); newWidth != expectedWidth {
146- t .Fatalf ("Unexpected width, got %d expected %d" , newWidth , expectedWidth )
127+ if newWidth := m .BlockDataHashingStructureWidth (); newWidth != defaultBlockDataHashingStructureWidth {
128+ t .Fatalf ("Unexpected width, got %d expected %d" , newWidth , defaultBlockDataHashingStructureWidth )
147129 }
148130}
149131
150132func TestOrdererAddresses (t * testing.T ) {
151- expectedResult := []string {"foo" , "bar:1234" }
152- invalidMessage := & cb.ConfigurationItem {
153- Type : cb .ConfigurationItem_Chain ,
154- Key : BlockDataHashingStructureKey ,
155- Value : []byte ("Garbage Data" ),
156- }
157- validMessage := & cb.ConfigurationItem {
158- Type : cb .ConfigurationItem_Chain ,
159- Key : OrdererAddressesKey ,
160- Value : utils .MarshalOrPanic (& cb.OrdererAddresses {Addresses : expectedResult }),
161- }
133+ invalidMessage := makeInvalidConfigItem (OrdererAddressesKey )
134+ validMessage := DefaultOrdererAddresses ()
162135 m := NewDescriptorImpl ()
163136 m .BeginConfig ()
164137
@@ -174,7 +147,7 @@ func TestOrdererAddresses(t *testing.T) {
174147
175148 m .CommitConfig ()
176149
177- if newAddrs := m .OrdererAddresses (); ! reflect .DeepEqual (newAddrs , expectedResult ) {
178- t .Fatalf ("Unexpected width, got %s expected %s" , newAddrs , expectedResult )
150+ if newAddrs := m .OrdererAddresses (); ! reflect .DeepEqual (newAddrs , defaultOrdererAddresses ) {
151+ t .Fatalf ("Unexpected width, got %s expected %s" , newAddrs , defaultOrdererAddresses )
179152 }
180153}
0 commit comments