MCPcopy
hub / github.com/hyperledger/fabric / TestCreateSignedEnvelope

Function TestCreateSignedEnvelope

protoutil/txutils_test.go:338–363  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

336}
337
338func TestCreateSignedEnvelope(t *testing.T) {
339 var env *cb.Envelope
340 channelID := "mychannelID"
341 msg := &cb.ConfigEnvelope{}
342
343 id := &fakes.SignerSerializer{}
344 id.SignReturnsOnCall(0, []byte("goodsig"), nil)
345 id.SignReturnsOnCall(1, nil, errors.New("bad signature"))
346 env, err := protoutil.CreateSignedEnvelope(cb.HeaderType_CONFIG, channelID,
347 id, msg, int32(1), uint64(1))
348 require.NoError(t, err, "Unexpected error creating signed envelope")
349 require.NotNil(t, env, "Envelope should not be nil")
350 // mock sign returns the bytes to be signed
351 require.Equal(t, []byte("goodsig"), env.Signature, "Unexpected signature returned")
352 payload := &cb.Payload{}
353 err = proto.Unmarshal(env.Payload, payload)
354 require.NoError(t, err, "Failed to unmarshal payload")
355 data := &cb.ConfigEnvelope{}
356 err = proto.Unmarshal(payload.Data, data)
357 require.NoError(t, err, "Expected payload data to be a config envelope")
358 require.True(t, proto.Equal(msg, data), "Payload data does not match expected value")
359
360 _, err = protoutil.CreateSignedEnvelope(cb.HeaderType_CONFIG, channelID,
361 id, &cb.ConfigEnvelope{}, int32(1), uint64(1))
362 require.Error(t, err, "Expected sign error")
363}
364
365func TestCreateSignedEnvelopeNilSigner(t *testing.T) {
366 var env *cb.Envelope

Callers

nothing calls this directly

Calls 6

SignReturnsOnCallMethod · 0.95
CreateSignedEnvelopeFunction · 0.92
NewMethod · 0.65
UnmarshalMethod · 0.65
ErrorMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected