@@ -25,6 +25,8 @@ import (
25
25
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
26
26
cb "github.com/hyperledger/fabric/protos/common"
27
27
"github.com/hyperledger/fabric/protos/utils"
28
+
29
+ "github.com/stretchr/testify/assert"
28
30
)
29
31
30
32
var defaultChain = "DefaultChainID"
@@ -62,9 +64,9 @@ func makeConfigPair(id, modificationPolicy string, lastModified uint64, data []b
62
64
}
63
65
64
66
func makeEnvelopeConfig (channelID string , configPairs ... * configPair ) * cb.Envelope {
65
- values := make ( map [ string ] * cb.ConfigValue )
67
+ channelGroup := cb .NewConfigGroup ( )
66
68
for _ , pair := range configPairs {
67
- values [pair .key ] = pair .value
69
+ channelGroup . Values [pair .key ] = pair .value
68
70
}
69
71
70
72
return & cb.Envelope {
@@ -77,27 +79,22 @@ func makeEnvelopeConfig(channelID string, configPairs ...*configPair) *cb.Envelo
77
79
},
78
80
Data : utils .MarshalOrPanic (& cb.ConfigEnvelope {
79
81
Config : & cb.Config {
80
- ChannelGroup : & cb.ConfigGroup {
81
- Values : values ,
82
- },
82
+ ChannelGroup : channelGroup ,
83
83
},
84
84
}),
85
85
}),
86
86
}
87
87
}
88
88
89
- func makeConfigUpdateEnvelope ( chainID string , configPairs ... * configPair ) * cb.Envelope {
90
- values := make ( map [ string ] * cb.ConfigValue )
89
+ func makeConfigSet ( configPairs ... * configPair ) * cb.ConfigGroup {
90
+ result := cb .NewConfigGroup ( )
91
91
for _ , pair := range configPairs {
92
- values [pair .key ] = pair .value
92
+ result . Values [pair .key ] = pair .value
93
93
}
94
+ return result
95
+ }
94
96
95
- config := & cb.ConfigUpdate {
96
- ChannelId : chainID ,
97
- WriteSet : & cb.ConfigGroup {
98
- Values : values ,
99
- },
100
- }
97
+ func makeConfigUpdateEnvelope (chainID string , readSet , writeSet * cb.ConfigGroup ) * cb.Envelope {
101
98
return & cb.Envelope {
102
99
Payload : utils .MarshalOrPanic (& cb.Payload {
103
100
Header : & cb.Header {
@@ -106,7 +103,11 @@ func makeConfigUpdateEnvelope(chainID string, configPairs ...*configPair) *cb.En
106
103
}),
107
104
},
108
105
Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
109
- ConfigUpdate : utils .MarshalOrPanic (config ),
106
+ ConfigUpdate : utils .MarshalOrPanic (& cb.ConfigUpdate {
107
+ ChannelId : chainID ,
108
+ ReadSet : readSet ,
109
+ WriteSet : writeSet ,
110
+ }),
110
111
}),
111
112
}),
112
113
}
@@ -141,7 +142,7 @@ func TestDifferentChainID(t *testing.T) {
141
142
t .Fatalf ("Error constructing config manager: %s" , err )
142
143
}
143
144
144
- newConfig := makeConfigUpdateEnvelope ("wrongChain" , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" )))
145
+ newConfig := makeConfigUpdateEnvelope ("wrongChain" , makeConfigSet (), makeConfigSet ( makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ) )))
145
146
146
147
_ , err = cm .ProposeConfigUpdate (newConfig )
147
148
if err == nil {
@@ -159,7 +160,7 @@ func TestOldConfigReplay(t *testing.T) {
159
160
t .Fatalf ("Error constructing config manager: %s" , err )
160
161
}
161
162
162
- newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )))
163
+ newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigSet (), makeConfigSet ( makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ) )))
163
164
164
165
_ , err = cm .ProposeConfigUpdate (newConfig )
165
166
if err == nil {
@@ -177,7 +178,7 @@ func TestValidConfigChange(t *testing.T) {
177
178
t .Fatalf ("Error constructing config manager: %s" , err )
178
179
}
179
180
180
- newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" )))
181
+ newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigSet (), makeConfigSet ( makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ) )))
181
182
182
183
configEnv , err := cm .ProposeConfigUpdate (newConfig )
183
184
if err != nil {
@@ -208,8 +209,8 @@ func TestConfigChangeRegressedSequence(t *testing.T) {
208
209
209
210
newConfig := makeConfigUpdateEnvelope (
210
211
defaultChain ,
211
- makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
212
- makeConfigPair ("bar" , "bar" , 2 , []byte ("bar" )),
212
+ makeConfigSet ( makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ) )),
213
+ makeConfigSet ( makeConfigPair ("bar" , "bar" , 2 , []byte ("bar" ) )),
213
214
)
214
215
215
216
_ , err = cm .ProposeConfigUpdate (newConfig )
@@ -231,8 +232,11 @@ func TestConfigChangeOldSequence(t *testing.T) {
231
232
232
233
newConfig := makeConfigUpdateEnvelope (
233
234
defaultChain ,
234
- makeConfigPair ("foo" , "foo" , 2 , []byte ("foo" )),
235
- makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
235
+ makeConfigSet (),
236
+ makeConfigSet (
237
+ makeConfigPair ("foo" , "foo" , 2 , []byte ("foo" )),
238
+ makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
239
+ ),
236
240
)
237
241
238
242
_ , err = cm .ProposeConfigUpdate (newConfig )
@@ -241,9 +245,9 @@ func TestConfigChangeOldSequence(t *testing.T) {
241
245
}
242
246
}
243
247
244
- // TestConfigImplicitDelete tests to make sure that a new config does not implicitly delete config items
245
- // by omitting them in the new config
246
- func TestConfigImplicitDelete (t * testing.T ) {
248
+ // TestConfigPartialUpdate tests to make sure that a new config can set only part
249
+ // of the config and still be accepted
250
+ func TestConfigPartialUpdate (t * testing.T ) {
247
251
cm , err := NewManagerImpl (
248
252
makeEnvelopeConfig (
249
253
defaultChain ,
@@ -258,13 +262,12 @@ func TestConfigImplicitDelete(t *testing.T) {
258
262
259
263
newConfig := makeConfigUpdateEnvelope (
260
264
defaultChain ,
261
- makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
265
+ makeConfigSet (),
266
+ makeConfigSet (makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" ))),
262
267
)
263
268
264
269
_ , err = cm .ProposeConfigUpdate (newConfig )
265
- if err == nil {
266
- t .Error ("Should have errored proposing config because foo was implicitly deleted" )
267
- }
270
+ assert .NoError (t , err , "Should have allowed partial update" )
268
271
}
269
272
270
273
// TestEmptyConfigUpdate tests to make sure that an empty config is rejected as an update
@@ -303,8 +306,11 @@ func TestSilentConfigModification(t *testing.T) {
303
306
304
307
newConfig := makeConfigUpdateEnvelope (
305
308
defaultChain ,
306
- makeConfigPair ("foo" , "foo" , 0 , []byte ("different" )),
307
- makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
309
+ makeConfigSet (),
310
+ makeConfigSet (
311
+ makeConfigPair ("foo" , "foo" , 0 , []byte ("different" )),
312
+ makeConfigPair ("bar" , "bar" , 1 , []byte ("bar" )),
313
+ ),
308
314
)
309
315
310
316
_ , err = cm .ProposeConfigUpdate (newConfig )
@@ -327,7 +333,7 @@ func TestConfigChangeViolatesPolicy(t *testing.T) {
327
333
// Set the mock policy to error
328
334
initializer .Resources .PolicyManagerVal .Policy .Err = fmt .Errorf ("err" )
329
335
330
- newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" )))
336
+ newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigSet (), makeConfigSet ( makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ) )))
331
337
332
338
_ , err = cm .ProposeConfigUpdate (newConfig )
333
339
if err == nil {
@@ -353,8 +359,8 @@ func TestUnchangedConfigViolatesPolicy(t *testing.T) {
353
359
354
360
newConfig := makeConfigUpdateEnvelope (
355
361
defaultChain ,
356
- makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" )),
357
- makeConfigPair ("bar" , "bar" , 1 , []byte ("foo" )),
362
+ makeConfigSet ( makeConfigPair ("foo" , "foo" , 0 , []byte ("foo" ) )),
363
+ makeConfigSet ( makeConfigPair ("bar" , "bar" , 0 , []byte ("foo" ) )),
358
364
)
359
365
360
366
configEnv , err := cm .ProposeConfigUpdate (newConfig )
@@ -387,7 +393,7 @@ func TestInvalidProposal(t *testing.T) {
387
393
388
394
initializer .ValueProposerVal = & mockconfigtx.ValueProposer {ErrorForProposeConfig : fmt .Errorf ("err" )}
389
395
390
- newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" )))
396
+ newConfig := makeConfigUpdateEnvelope (defaultChain , makeConfigSet (), makeConfigSet ( makeConfigPair ("foo" , "foo" , 1 , []byte ("foo" ) )))
391
397
392
398
_ , err = cm .ProposeConfigUpdate (newConfig )
393
399
if err == nil {
0 commit comments