@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"github.com/golang/protobuf/proto"
25
+ "github.com/hyperledger/fabric/common/config"
25
26
"github.com/hyperledger/fabric/common/configtx"
26
27
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
27
28
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
@@ -252,6 +253,181 @@ func TestSignatureFilter(t *testing.T) {
252
253
}
253
254
*/
254
255
256
+ func TestNewChannelConfig (t * testing.T ) {
257
+
258
+ lf , _ := NewRAMLedgerAndFactory (3 )
259
+
260
+ consenters := make (map [string ]Consenter )
261
+ consenters [conf .Orderer .OrdererType ] = & mockConsenter {}
262
+ manager := NewManagerImpl (lf , consenters , mockCrypto ())
263
+
264
+ t .Run ("BadPayload" , func (t * testing.T ) {
265
+ _ , err := manager .NewChannelConfig (& cb.Envelope {Payload : []byte ("bad payload" )})
266
+ assert .Error (t , err , "Should bot be able to create new channel config from bad payload." )
267
+ })
268
+
269
+ for _ , tc := range []struct {
270
+ name string
271
+ payload * cb.Payload
272
+ regex string
273
+ }{
274
+ {
275
+ "BadPayloadData" ,
276
+ & cb.Payload {
277
+ Data : []byte ("bad payload data" ),
278
+ },
279
+ "^Failing initial channel config creation because of config update envelope unmarshaling error:" ,
280
+ },
281
+ {
282
+ "BadConfigUpdate" ,
283
+ & cb.Payload {
284
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
285
+ ConfigUpdate : []byte ("bad config update envelope data" ),
286
+ }),
287
+ },
288
+ "^Failing initial channel config creation because of config update unmarshaling error:" ,
289
+ },
290
+ {
291
+ "EmptyConfigUpdateWriteSet" ,
292
+ & cb.Payload {
293
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
294
+ ConfigUpdate : utils .MarshalOrPanic (
295
+ & cb.ConfigUpdate {},
296
+ ),
297
+ }),
298
+ },
299
+ "^Config update has an empty writeset$" ,
300
+ },
301
+ {
302
+ "WriteSetNoGroups" ,
303
+ & cb.Payload {
304
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
305
+ ConfigUpdate : utils .MarshalOrPanic (
306
+ & cb.ConfigUpdate {
307
+ WriteSet : & cb.ConfigGroup {},
308
+ },
309
+ ),
310
+ }),
311
+ },
312
+ "^Config update has missing application group$" ,
313
+ },
314
+ {
315
+ "WriteSetNoApplicationGroup" ,
316
+ & cb.Payload {
317
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
318
+ ConfigUpdate : utils .MarshalOrPanic (
319
+ & cb.ConfigUpdate {
320
+ WriteSet : & cb.ConfigGroup {
321
+ Groups : map [string ]* cb.ConfigGroup {},
322
+ },
323
+ },
324
+ ),
325
+ }),
326
+ },
327
+ "^Config update has missing application group$" ,
328
+ },
329
+ {
330
+ "BadWriteSetApplicationGroupVersion" ,
331
+ & cb.Payload {
332
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
333
+ ConfigUpdate : utils .MarshalOrPanic (
334
+ & cb.ConfigUpdate {
335
+ WriteSet : & cb.ConfigGroup {
336
+ Groups : map [string ]* cb.ConfigGroup {
337
+ config .ApplicationGroupKey : & cb.ConfigGroup {
338
+ Version : 100 ,
339
+ },
340
+ },
341
+ },
342
+ },
343
+ ),
344
+ }),
345
+ },
346
+ "^Config update for channel creation does not set application group version to 1," ,
347
+ },
348
+ {
349
+ "MissingWriteSetConsortiumValue" ,
350
+ & cb.Payload {
351
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
352
+ ConfigUpdate : utils .MarshalOrPanic (
353
+ & cb.ConfigUpdate {
354
+ WriteSet : & cb.ConfigGroup {
355
+ Groups : map [string ]* cb.ConfigGroup {
356
+ config .ApplicationGroupKey : & cb.ConfigGroup {
357
+ Version : 1 ,
358
+ },
359
+ },
360
+ Values : map [string ]* cb.ConfigValue {},
361
+ },
362
+ },
363
+ ),
364
+ }),
365
+ },
366
+ "^Consortium config value missing$" ,
367
+ },
368
+ {
369
+ "BadWriteSetConsortiumValueValue" ,
370
+ & cb.Payload {
371
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
372
+ ConfigUpdate : utils .MarshalOrPanic (
373
+ & cb.ConfigUpdate {
374
+ WriteSet : & cb.ConfigGroup {
375
+ Groups : map [string ]* cb.ConfigGroup {
376
+ config .ApplicationGroupKey : & cb.ConfigGroup {
377
+ Version : 1 ,
378
+ },
379
+ },
380
+ Values : map [string ]* cb.ConfigValue {
381
+ config .ConsortiumKey : & cb.ConfigValue {
382
+ Value : []byte ("bad consortium value" ),
383
+ },
384
+ },
385
+ },
386
+ },
387
+ ),
388
+ }),
389
+ },
390
+ "^Error reading unmarshaling consortium name:" ,
391
+ },
392
+ {
393
+ "UnknownConsortiumName" ,
394
+ & cb.Payload {
395
+ Data : utils .MarshalOrPanic (& cb.ConfigUpdateEnvelope {
396
+ ConfigUpdate : utils .MarshalOrPanic (
397
+ & cb.ConfigUpdate {
398
+ WriteSet : & cb.ConfigGroup {
399
+ Groups : map [string ]* cb.ConfigGroup {
400
+ config .ApplicationGroupKey : & cb.ConfigGroup {
401
+ Version : 1 ,
402
+ },
403
+ },
404
+ Values : map [string ]* cb.ConfigValue {
405
+ config .ConsortiumKey : & cb.ConfigValue {
406
+ Value : utils .MarshalOrPanic (
407
+ & cb.Consortium {
408
+ Name : "NotTheNameYouAreLookingFor" ,
409
+ },
410
+ ),
411
+ },
412
+ },
413
+ },
414
+ },
415
+ ),
416
+ }),
417
+ },
418
+ "^Unknown consortium name:" ,
419
+ },
420
+ } {
421
+ t .Run (tc .name , func (t * testing.T ) {
422
+ _ , err := manager .NewChannelConfig (& cb.Envelope {Payload : utils .MarshalOrPanic (tc .payload )})
423
+ if assert .Error (t , err ) {
424
+ assert .Regexp (t , tc .regex , err .Error ())
425
+ }
426
+ })
427
+ }
428
+ // SampleConsortium
429
+ }
430
+
255
431
// This test brings up the entire system, with the mock consenter, including the broadcasters etc. and creates a new chain
256
432
func TestNewChain (t * testing.T ) {
257
433
expectedLastConfigBlockNumber := uint64 (0 )
0 commit comments