@@ -21,7 +21,6 @@ import (
21
21
"testing"
22
22
23
23
cb "github.com/hyperledger/fabric/protos/common"
24
- "github.com/hyperledger/fabric/protos/utils"
25
24
26
25
logging "github.com/op/go-logging"
27
26
)
@@ -30,6 +29,14 @@ func init() {
30
29
logging .SetLevel (logging .DEBUG , "" )
31
30
}
32
31
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
+
33
40
func TestDoubleBegin (t * testing.T ) {
34
41
defer func () {
35
42
if err := recover (); err == nil {
@@ -63,22 +70,10 @@ func TestRollback(t *testing.T) {
63
70
}
64
71
65
72
func 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
+
82
77
m := NewDescriptorImpl ()
83
78
m .BeginConfig ()
84
79
@@ -105,23 +100,10 @@ func TestHashingAlgorithm(t *testing.T) {
105
100
}
106
101
107
102
func 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
+
125
107
m := NewDescriptorImpl ()
126
108
m .BeginConfig ()
127
109
@@ -142,23 +124,14 @@ func TestBlockDataHashingStructure(t *testing.T) {
142
124
143
125
m .CommitConfig ()
144
126
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 )
147
129
}
148
130
}
149
131
150
132
func 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 ()
162
135
m := NewDescriptorImpl ()
163
136
m .BeginConfig ()
164
137
@@ -174,7 +147,7 @@ func TestOrdererAddresses(t *testing.T) {
174
147
175
148
m .CommitConfig ()
176
149
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 )
179
152
}
180
153
}
0 commit comments