@@ -56,19 +56,21 @@ func makeConfigPair(id, modificationPolicy string, lastModified uint64, data []b
5656 }
5757}
5858
59- func makeMarshaledConfig (chainID string , configPairs ... * configPair ) [] byte {
59+ func makeConfigUpdateEnvelope (chainID string , configPairs ... * configPair ) * cb. ConfigUpdateEnvelope {
6060 values := make (map [string ]* cb.ConfigValue )
6161 for _ , pair := range configPairs {
6262 values [pair .key ] = pair .value
6363 }
6464
65- config := & cb.Config {
65+ config := & cb.ConfigUpdate {
6666 Header : & cb.ChannelHeader {ChannelId : chainID },
67- Channel : & cb.ConfigGroup {
67+ WriteSet : & cb.ConfigGroup {
6868 Values : values ,
6969 },
7070 }
71- return utils .MarshalOrPanic (config )
71+ return & cb.ConfigUpdateEnvelope {
72+ ConfigUpdate : utils .MarshalOrPanic (config ),
73+ }
7274}
7375
7476func TestCallback (t * testing.T ) {
@@ -78,7 +80,7 @@ func TestCallback(t *testing.T) {
7880 }
7981
8082 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" ))),
8284 }, defaultInitializer (), []func (api.Manager ){callback })
8385
8486 if err != nil {
@@ -93,15 +95,15 @@ func TestCallback(t *testing.T) {
9395// TestDifferentChainID tests that a config update for a different chain ID fails
9496func TestDifferentChainID (t * testing.T ) {
9597 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" ))),
9799 }, defaultInitializer (), nil )
98100
99101 if err != nil {
100102 t .Fatalf ("Error constructing config manager: %s" , err )
101103 }
102104
103105 newConfig := & cb.ConfigEnvelope {
104- Config : makeMarshaledConfig ("wrongChain" , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
106+ LastUpdate : makeConfigUpdateEnvelope ("wrongChain" , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
105107 }
106108
107109 err = cm .Validate (newConfig )
@@ -118,15 +120,15 @@ func TestDifferentChainID(t *testing.T) {
118120// TestOldConfigReplay tests that resubmitting a config for a sequence number which is not newer is ignored
119121func TestOldConfigReplay (t * testing.T ) {
120122 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" ))),
122124 }, defaultInitializer (), nil )
123125
124126 if err != nil {
125127 t .Fatalf ("Error constructing config manager: %s" , err )
126128 }
127129
128130 newConfig := & cb.ConfigEnvelope {
129- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
131+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
130132 }
131133
132134 err = cm .Validate (newConfig )
@@ -143,7 +145,9 @@ func TestOldConfigReplay(t *testing.T) {
143145// TestInvalidInitialConfigByStructure tests to make sure that if the config contains corrupted config that construction results in error
144146func TestInvalidInitialConfigByStructure (t * testing.T ) {
145147 _ , err := NewManagerImpl (& cb.ConfigEnvelope {
146- Config : []byte ("Corrupted" ),
148+ LastUpdate : & cb.ConfigUpdateEnvelope {
149+ ConfigUpdate : []byte ("Corrupted" ),
150+ },
147151 }, defaultInitializer (), nil )
148152
149153 if err == nil {
@@ -154,15 +158,15 @@ func TestInvalidInitialConfigByStructure(t *testing.T) {
154158// TestValidConfigChange tests the happy path of updating a config value with no defaultModificationPolicy
155159func TestValidConfigChange (t * testing.T ) {
156160 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" ))),
158162 }, defaultInitializer (), nil )
159163
160164 if err != nil {
161165 t .Fatalf ("Error constructing config manager: %s" , err )
162166 }
163167
164168 newConfig := & cb.ConfigEnvelope {
165- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
169+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
166170 }
167171
168172 err = cm .Validate (newConfig )
@@ -180,15 +184,15 @@ func TestValidConfigChange(t *testing.T) {
180184// config values while advancing another
181185func TestConfigChangeRegressedSequence (t * testing.T ) {
182186 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" ))),
184188 }, defaultInitializer (), nil )
185189
186190 if err != nil {
187191 t .Fatalf ("Error constructing config manager: %s" , err )
188192 }
189193
190194 newConfig := & cb.ConfigEnvelope {
191- Config : makeMarshaledConfig (
195+ LastUpdate : makeConfigUpdateEnvelope (
192196 defaultChain ,
193197 makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
194198 makeConfigPair ("bar" , "bar" , 2 , []byte ("bar" )),
@@ -210,15 +214,15 @@ func TestConfigChangeRegressedSequence(t *testing.T) {
210214// config values while advancing another
211215func TestConfigChangeOldSequence (t * testing.T ) {
212216 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" ))),
214218 }, defaultInitializer (), nil )
215219
216220 if err != nil {
217221 t .Fatalf ("Error constructing config manager: %s" , err )
218222 }
219223
220224 newConfig := & cb.ConfigEnvelope {
221- Config : makeMarshaledConfig (
225+ LastUpdate : makeConfigUpdateEnvelope (
222226 defaultChain ,
223227 makeConfigPair ("foo" , "foo" , 2 , []byte ("foo" )),
224228 makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
@@ -240,7 +244,7 @@ func TestConfigChangeOldSequence(t *testing.T) {
240244// by omitting them in the new config
241245func TestConfigImplicitDelete (t * testing.T ) {
242246 cm , err := NewManagerImpl (& cb.ConfigEnvelope {
243- Config : makeMarshaledConfig (
247+ LastUpdate : makeConfigUpdateEnvelope (
244248 defaultChain ,
245249 makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
246250 makeConfigPair ("bar" , "bar" , 0 , []byte ("bar" )),
@@ -252,7 +256,7 @@ func TestConfigImplicitDelete(t *testing.T) {
252256 }
253257
254258 newConfig := & cb.ConfigEnvelope {
255- Config : makeMarshaledConfig (
259+ LastUpdate : makeConfigUpdateEnvelope (
256260 defaultChain ,
257261 makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
258262 ),
@@ -272,7 +276,7 @@ func TestConfigImplicitDelete(t *testing.T) {
272276// TestEmptyConfigUpdate tests to make sure that an empty config is rejected as an update
273277func TestEmptyConfigUpdate (t * testing.T ) {
274278 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" ))),
276280 }, defaultInitializer (), nil )
277281
278282 if err != nil {
@@ -297,7 +301,7 @@ func TestEmptyConfigUpdate(t *testing.T) {
297301// increasing the config item's LastModified
298302func TestSilentConfigModification (t * testing.T ) {
299303 cm , err := NewManagerImpl (& cb.ConfigEnvelope {
300- Config : makeMarshaledConfig (
304+ LastUpdate : makeConfigUpdateEnvelope (
301305 defaultChain ,
302306 makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
303307 makeConfigPair ("bar" , "bar" , 0 , []byte ("bar" )),
@@ -309,7 +313,7 @@ func TestSilentConfigModification(t *testing.T) {
309313 }
310314
311315 newConfig := & cb.ConfigEnvelope {
312- Config : makeMarshaledConfig (
316+ LastUpdate : makeConfigUpdateEnvelope (
313317 defaultChain ,
314318 makeConfigPair ("foo" , "foo" , 0 , []byte ("different" )),
315319 makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
@@ -333,7 +337,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
333337 initializer := defaultInitializer ()
334338 initializer .Resources .PolicyManagerVal .Policy .Err = fmt .Errorf ("err" )
335339 _ , err := NewManagerImpl (& cb.ConfigEnvelope {
336- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
340+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
337341 }, initializer , nil )
338342
339343 if err == nil {
@@ -346,7 +350,7 @@ func TestInvalidInitialConfigByPolicy(t *testing.T) {
346350func TestConfigChangeViolatesPolicy (t * testing.T ) {
347351 initializer := defaultInitializer ()
348352 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" ))),
350354 }, initializer , nil )
351355
352356 if err != nil {
@@ -356,7 +360,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
356360 initializer .Resources .PolicyManagerVal .Policy .Err = fmt .Errorf ("err" )
357361
358362 newConfig := & cb.ConfigEnvelope {
359- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
363+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
360364 }
361365
362366 err = cm .Validate (newConfig )
@@ -375,7 +379,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
375379func TestUnchangedConfigViolatesPolicy (t * testing.T ) {
376380 initializer := defaultInitializer ()
377381 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" ))),
379383 }, initializer , nil )
380384
381385 if err != nil {
@@ -387,7 +391,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
387391 initializer .Resources .PolicyManagerVal .PolicyMap ["foo" ] = & mockpolicies.Policy {Err : fmt .Errorf ("err" )}
388392
389393 newConfig := & cb.ConfigEnvelope {
390- Config : makeMarshaledConfig (
394+ LastUpdate : makeConfigUpdateEnvelope (
391395 defaultChain ,
392396 makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
393397 makeConfigPair ("bar" , "bar" , 1 , []byte ("foo" )),
@@ -410,7 +414,7 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
410414func TestInvalidProposal (t * testing.T ) {
411415 initializer := defaultInitializer ()
412416 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" ))),
414418 }, initializer , nil )
415419
416420 if err != nil {
@@ -420,7 +424,7 @@ func TestInvalidProposal(t *testing.T) {
420424 initializer .HandlerVal = & mockconfigtx.Handler {ErrorForProposeConfig : fmt .Errorf ("err" )}
421425
422426 newConfig := & cb.ConfigEnvelope {
423- Config : makeMarshaledConfig (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
427+ LastUpdate : makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ))),
424428 }
425429
426430 err = cm .Validate (newConfig )
@@ -440,7 +444,9 @@ func TestMissingHeader(t *testing.T) {
440444 group .Values ["foo" ] = & cb.ConfigValue {}
441445 data := utils .MarshalOrPanic (& cb.Config {Channel : group })
442446 _ , err := NewManagerImpl (& cb.ConfigEnvelope {
443- Config : data ,
447+ LastUpdate : & cb.ConfigUpdateEnvelope {
448+ ConfigUpdate : data ,
449+ },
444450 }, defaultInitializer (), nil )
445451
446452 if err == nil {
@@ -451,7 +457,7 @@ func TestMissingHeader(t *testing.T) {
451457// TestMissingChainID checks that a config item with a missing chainID causes the config to be rejected
452458func TestMissingChainID (t * testing.T ) {
453459 _ , err := NewManagerImpl (& cb.ConfigEnvelope {
454- Config : makeMarshaledConfig ("" , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
460+ LastUpdate : makeConfigUpdateEnvelope ("" , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ))),
455461 }, defaultInitializer (), nil )
456462
457463 if err == nil {
0 commit comments