Skip to content

Commit 6765b35

Browse files
author
Luis Sanchez
committed
[FAB-3931] Improve h/f/orderer/multichain coverage
improve hyperledger/fabric/orderer/multichain coverage to 87.6% Change-Id: I165ac95054c9219ef181ff254128a32740986d15 Signed-off-by: Luis Sanchez <[email protected]>
1 parent 77bca87 commit 6765b35

File tree

3 files changed

+415
-1
lines changed

3 files changed

+415
-1
lines changed

orderer/multichain/manager.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func (ml *multiLedger) NewChannelConfig(envConfigUpdate *cb.Envelope) (configtxa
295295
channelGroup.Groups[config.ApplicationGroupKey] = applicationGroup
296296
channelGroup.Values[config.ConsortiumKey] = config.TemplateConsortium(consortium.Name).Values[config.ConsortiumKey]
297297

298-
templateConfig, err := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, configUpdate.ChannelId, ml.signer, &cb.ConfigEnvelope{
298+
templateConfig, _ := utils.CreateSignedEnvelope(cb.HeaderType_CONFIG, configUpdate.ChannelId, ml.signer, &cb.ConfigEnvelope{
299299
Config: &cb.Config{
300300
ChannelGroup: channelGroup,
301301
},

orderer/multichain/manager_test.go

+176
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"github.com/golang/protobuf/proto"
25+
"github.com/hyperledger/fabric/common/config"
2526
"github.com/hyperledger/fabric/common/configtx"
2627
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2728
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
@@ -252,6 +253,181 @@ func TestSignatureFilter(t *testing.T) {
252253
}
253254
*/
254255

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+
255431
// This test brings up the entire system, with the mock consenter, including the broadcasters etc. and creates a new chain
256432
func TestNewChain(t *testing.T) {
257433
expectedLastConfigBlockNumber := uint64(0)

0 commit comments

Comments
 (0)