@@ -56,19 +56,21 @@ func makeConfigPair(id, modificationPolicy string, lastModified uint64, data []b
56
56
}
57
57
}
58
58
59
- func makeMarshaledConfig (chainID string , configPairs ... * configPair ) [] byte {
59
+ func makeConfigUpdateEnvelope (chainID string , configPairs ... * configPair ) * cb. ConfigUpdateEnvelope {
60
60
values := make (map [string ]* cb.ConfigValue )
61
61
for _ , pair := range configPairs {
62
62
values [pair .key ] = pair .value
63
63
}
64
64
65
- config := & cb.Config {
65
+ config := & cb.ConfigUpdate {
66
66
Header : & cb.ChannelHeader {ChannelId : chainID },
67
- Channel : & cb.ConfigGroup {
67
+ WriteSet : & cb.ConfigGroup {
68
68
Values : values ,
69
69
},
70
70
}
71
- return utils .MarshalOrPanic (config )
71
+ return & cb.ConfigUpdateEnvelope {
72
+ ConfigUpdate : utils .MarshalOrPanic (config ),
73
+ }
72
74
}
73
75
74
76
func TestCallback (t * testing.T ) {
@@ -78,7 +80,7 @@ func TestCallback(t *testing.T) {
78
80
}
79
81
80
82
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
81
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
83
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
82
84
}, defaultInitializer (), []func (api.Manager ){callback })
83
85
84
86
if err != nil {
@@ -93,15 +95,15 @@ func TestCallback(t *testing.T) {
93
95
// TestDifferentChainID tests that a config update for a different chain ID fails
94
96
func TestDifferentChainID (t * testing.T ) {
95
97
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
96
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
98
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
97
99
}, defaultInitializer (), nil )
98
100
99
101
if err != nil {
100
102
t .Fatalf ("Error constructing config manager: %s" , err )
101
103
}
102
104
103
105
newConfig := & cb.ConfigEnvelope {
104
- Config : makeMarshaledConfig ("wrongChain" , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
106
+ LastUpdate : makeConfigUpdateEnvelope ("wrongChain" , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
105
107
}
106
108
107
109
err = cm .Validate (newConfig )
@@ -118,15 +120,15 @@ func TestDifferentChainID(t *testing.T) {
118
120
// TestOldConfigReplay tests that resubmitting a config for a sequence number which is not newer is ignored
119
121
func TestOldConfigReplay (t * testing.T ) {
120
122
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
121
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
123
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
122
124
}, defaultInitializer (), nil )
123
125
124
126
if err != nil {
125
127
t .Fatalf ("Error constructing config manager: %s" , err )
126
128
}
127
129
128
130
newConfig := & cb.ConfigEnvelope {
129
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
131
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
130
132
}
131
133
132
134
err = cm .Validate (newConfig )
@@ -143,7 +145,9 @@ func TestOldConfigReplay(t *testing.T) {
143
145
// TestInvalidInitialConfigByStructure tests to make sure that if the config contains corrupted config that construction results in error
144
146
func TestInvalidInitialConfigByStructure (t * testing.T ) {
145
147
_ , err := NewManagerImpl (& cb.ConfigEnvelope {
146
- Config : []byte ("Corrupted" ),
148
+ LastUpdate : & cb.ConfigUpdateEnvelope {
149
+ ConfigUpdate : []byte ("Corrupted" ),
150
+ },
147
151
}, defaultInitializer (), nil )
148
152
149
153
if err == nil {
@@ -154,15 +158,15 @@ func TestInvalidInitialConfigByStructure(t *testing.T) {
154
158
// TestValidConfigChange tests the happy path of updating a config value with no defaultModificationPolicy
155
159
func TestValidConfigChange (t * testing.T ) {
156
160
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
157
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
161
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
158
162
}, defaultInitializer (), nil )
159
163
160
164
if err != nil {
161
165
t .Fatalf ("Error constructing config manager: %s" , err )
162
166
}
163
167
164
168
newConfig := & cb.ConfigEnvelope {
165
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
169
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
166
170
}
167
171
168
172
err = cm .Validate (newConfig )
@@ -180,15 +184,15 @@ func TestValidConfigChange(t *testing.T) {
180
184
// config values while advancing another
181
185
func TestConfigChangeRegressedSequence (t * testing.T ) {
182
186
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
183
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
187
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
184
188
}, defaultInitializer (), nil )
185
189
186
190
if err != nil {
187
191
t .Fatalf ("Error constructing config manager: %s" , err )
188
192
}
189
193
190
194
newConfig := & cb.ConfigEnvelope {
191
- Config : makeMarshaledConfig (
195
+ LastUpdate : makeConfigUpdateEnvelope (
192
196
defaultChain ,
193
197
makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
194
198
makeConfigPair ("bar" , "bar" , 2 , []byte ("bar" )),
@@ -210,15 +214,15 @@ func TestConfigChangeRegressedSequence(t *testing.T) {
210
214
// config values while advancing another
211
215
func TestConfigChangeOldSequence (t * testing.T ) {
212
216
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
213
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
217
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
214
218
}, defaultInitializer (), nil )
215
219
216
220
if err != nil {
217
221
t .Fatalf ("Error constructing config manager: %s" , err )
218
222
}
219
223
220
224
newConfig := & cb.ConfigEnvelope {
221
- Config : makeMarshaledConfig (
225
+ LastUpdate : makeConfigUpdateEnvelope (
222
226
defaultChain ,
223
227
makeConfigPair ("foo" , "foo" , 2 , []byte ("foo" )),
224
228
makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
@@ -240,7 +244,7 @@ func TestConfigChangeOldSequence(t *testing.T) {
240
244
// by omitting them in the new config
241
245
func TestConfigImplicitDelete (t * testing.T ) {
242
246
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
243
- Config : makeMarshaledConfig (
247
+ LastUpdate : makeConfigUpdateEnvelope (
244
248
defaultChain ,
245
249
makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
246
250
makeConfigPair ("bar" , "bar" , 0 , []byte ("bar" )),
@@ -252,7 +256,7 @@ func TestConfigImplicitDelete(t *testing.T) {
252
256
}
253
257
254
258
newConfig := & cb.ConfigEnvelope {
255
- Config : makeMarshaledConfig (
259
+ LastUpdate : makeConfigUpdateEnvelope (
256
260
defaultChain ,
257
261
makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
258
262
),
@@ -272,7 +276,7 @@ func TestConfigImplicitDelete(t *testing.T) {
272
276
// TestEmptyConfigUpdate tests to make sure that an empty config is rejected as an update
273
277
func TestEmptyConfigUpdate (t * testing.T ) {
274
278
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
275
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
279
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
276
280
}, defaultInitializer (), nil )
277
281
278
282
if err != nil {
@@ -297,7 +301,7 @@ func TestEmptyConfigUpdate(t *testing.T) {
297
301
// increasing the config item's LastModified
298
302
func TestSilentConfigModification (t * testing.T ) {
299
303
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
300
- Config : makeMarshaledConfig (
304
+ LastUpdate : makeConfigUpdateEnvelope (
301
305
defaultChain ,
302
306
makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
303
307
makeConfigPair ("bar" , "bar" , 0 , []byte ("bar" )),
@@ -309,7 +313,7 @@ func TestSilentConfigModification(t *testing.T) {
309
313
}
310
314
311
315
newConfig := & cb.ConfigEnvelope {
312
- Config : makeMarshaledConfig (
316
+ LastUpdate : makeConfigUpdateEnvelope (
313
317
defaultChain ,
314
318
makeConfigPair ("foo" , "foo" , 0 , []byte ("different" )),
315
319
makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
@@ -333,7 +337,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
333
337
initializer := defaultInitializer ()
334
338
initializer .Resources .PolicyManagerVal .Policy .Err = fmt .Errorf ("err" )
335
339
_ , err := NewManagerImpl (& cb.ConfigEnvelope {
336
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
340
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
337
341
}, initializer , nil )
338
342
339
343
if err == nil {
@@ -346,7 +350,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
346
350
func TestConfigChangeViolatesPolicy (t * testing.T ) {
347
351
initializer := defaultInitializer ()
348
352
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
349
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
353
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
350
354
}, initializer , nil )
351
355
352
356
if err != nil {
@@ -356,7 +360,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
356
360
initializer .Resources .PolicyManagerVal .Policy .Err = fmt .Errorf ("err" )
357
361
358
362
newConfig := & cb.ConfigEnvelope {
359
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
363
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
360
364
}
361
365
362
366
err = cm .Validate (newConfig )
@@ -375,7 +379,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
375
379
func TestUnchangedConfigViolatesPolicy (t * testing.T ) {
376
380
initializer := defaultInitializer ()
377
381
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
378
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
382
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
379
383
}, initializer , nil )
380
384
381
385
if err != nil {
@@ -387,7 +391,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
387
391
initializer .Resources .PolicyManagerVal .PolicyMap ["foo" ] = & mockpolicies.Policy {Err : fmt .Errorf ("err" )}
388
392
389
393
newConfig := & cb.ConfigEnvelope {
390
- Config : makeMarshaledConfig (
394
+ LastUpdate : makeConfigUpdateEnvelope (
391
395
defaultChain ,
392
396
makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
393
397
makeConfigPair ("bar" , "bar" , 1 , []byte ("foo" )),
@@ -410,7 +414,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
410
414
func TestInvalidProposal (t * testing.T ) {
411
415
initializer := defaultInitializer ()
412
416
cm , err := NewManagerImpl (& cb.ConfigEnvelope {
413
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
417
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
414
418
}, initializer , nil )
415
419
416
420
if err != nil {
@@ -420,7 +424,7 @@ func TestInvalidProposal(t *testing.T) {
420
424
initializer .HandlerVal = & mockconfigtx.Handler {ErrorForProposeConfig : fmt .Errorf ("err" )}
421
425
422
426
newConfig := & cb.ConfigEnvelope {
423
- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
427
+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
424
428
}
425
429
426
430
err = cm .Validate (newConfig )
@@ -440,7 +444,9 @@ func TestMissingHeader(t *testing.T) {
440
444
group .Values ["foo" ] = & cb.ConfigValue {}
441
445
data := utils .MarshalOrPanic (& cb.Config {Channel : group })
442
446
_ , err := NewManagerImpl (& cb.ConfigEnvelope {
443
- Config : data ,
447
+ LastUpdate : & cb.ConfigUpdateEnvelope {
448
+ ConfigUpdate : data ,
449
+ },
444
450
}, defaultInitializer (), nil )
445
451
446
452
if err == nil {
@@ -451,7 +457,7 @@ func TestMissingHeader(t *testing.T) {
451
457
// TestMissingChainID checks that a config item with a missing chainID causes the config to be rejected
452
458
func TestMissingChainID (t * testing.T ) {
453
459
_ , err := NewManagerImpl (& cb.ConfigEnvelope {
454
- Config : makeMarshaledConfig ("" , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
460
+ LastUpdate : makeConfigUpdateEnvelope ("" , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
455
461
}, defaultInitializer (), nil )
456
462
457
463
if err == nil {
0 commit comments