Skip to content

Commit 6617030

Browse files
committed
FAB-16437 Remove common/mocks from protoutil
Change-Id: I6e22164004f7df3bcc0219ac0ced9665980e30c2 Signed-off-by: Gari Singh <[email protected]>
1 parent 6aa4978 commit 6617030

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

protoutil/commonutils_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ import (
1515
cb "github.com/hyperledger/fabric-protos-go/common"
1616
pb "github.com/hyperledger/fabric-protos-go/peer"
1717
"github.com/hyperledger/fabric/common/crypto"
18-
"github.com/hyperledger/fabric/internal/pkg/identity"
1918
"github.com/hyperledger/fabric/protoutil/fakes"
2019
"github.com/stretchr/testify/assert"
2120
)
2221

2322
//go:generate counterfeiter -o fakes/signer_serializer.go --fake-name SignerSerializer . signerSerializer
2423

2524
type signerSerializer interface {
26-
identity.SignerSerializer
25+
Signer
2726
}
2827

2928
func TestNonceRandomness(t *testing.T) {

protoutil/txutils.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/golang/protobuf/proto"
1414
"github.com/hyperledger/fabric-protos-go/common"
1515
"github.com/hyperledger/fabric-protos-go/peer"
16-
"github.com/hyperledger/fabric/internal/pkg/identity"
1716
"github.com/pkg/errors"
1817
)
1918

@@ -62,7 +61,7 @@ func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
6261
func CreateSignedEnvelope(
6362
txType common.HeaderType,
6463
channelID string,
65-
signer identity.SignerSerializer,
64+
signer Signer,
6665
dataMsg proto.Message,
6766
msgVersion int32,
6867
epoch uint64,
@@ -76,7 +75,7 @@ func CreateSignedEnvelope(
7675
func CreateSignedEnvelopeWithTLSBinding(
7776
txType common.HeaderType,
7877
channelID string,
79-
signer identity.SignerSerializer,
78+
signer Signer,
8079
dataMsg proto.Message,
8180
msgVersion int32,
8281
epoch uint64,
@@ -245,7 +244,7 @@ func CreateProposalResponse(
245244
results []byte,
246245
events []byte,
247246
ccid *peer.ChaincodeID,
248-
signingEndorser identity.SignerSerializer,
247+
signingEndorser Signer,
249248
) (*peer.ProposalResponse, error) {
250249
hdr, err := UnmarshalHeader(hdrbytes)
251250
if err != nil {
@@ -334,7 +333,7 @@ func CreateProposalResponseFailure(
334333

335334
// GetSignedProposal returns a signed proposal given a Proposal message and a
336335
// signing identity
337-
func GetSignedProposal(prop *peer.Proposal, signer identity.SignerSerializer) (*peer.SignedProposal, error) {
336+
func GetSignedProposal(prop *peer.Proposal, signer Signer) (*peer.SignedProposal, error) {
338337
// check for nil argument
339338
if prop == nil || signer == nil {
340339
return nil, errors.New("nil arguments")
@@ -381,7 +380,7 @@ func MockSignedEndorserProposalOrPanic(
381380
func MockSignedEndorserProposal2OrPanic(
382381
channelID string,
383382
cs *peer.ChaincodeSpec,
384-
signer identity.SignerSerializer,
383+
signer Signer,
385384
) (*peer.SignedProposal, *peer.Proposal) {
386385
serializedSigner, err := signer.Serialize()
387386
if err != nil {

protoutil/txutils_test.go

+13-11
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/golang/protobuf/proto"
1616
cb "github.com/hyperledger/fabric-protos-go/common"
1717
pb "github.com/hyperledger/fabric-protos-go/peer"
18-
mockmsp "github.com/hyperledger/fabric/common/mocks/msp"
18+
1919
"github.com/hyperledger/fabric/protoutil"
2020
"github.com/hyperledger/fabric/protoutil/fakes"
2121
"github.com/stretchr/testify/assert"
@@ -121,8 +121,8 @@ func TestCreateSignedTx(t *testing.T) {
121121
var err error
122122
prop := &pb.Proposal{}
123123

124-
signID, err := mockmsp.NewNoopMsp().GetDefaultSigningIdentity()
125-
assert.NoError(t, err, "Unexpected error getting signing identity")
124+
signID := &fakes.SignerSerializer{}
125+
signID.SerializeReturns([]byte("signer"), nil)
126126
signerBytes, err := signID.Serialize()
127127
assert.NoError(t, err, "Unexpected error serializing signing identity")
128128

@@ -240,8 +240,8 @@ func TestCreateSignedTxStatus(t *testing.T) {
240240
})
241241
assert.NoError(t, err)
242242

243-
signingID, err := mockmsp.NewNoopMsp().GetDefaultSigningIdentity()
244-
assert.NoError(t, err)
243+
signingID := &fakes.SignerSerializer{}
244+
signingID.SerializeReturns([]byte("signer"), nil)
245245
serializedSigningID, err := signingID.Serialize()
246246
assert.NoError(t, err)
247247
serializedSignatureHeader, err := proto.Marshal(&cb.SignatureHeader{
@@ -343,16 +343,18 @@ func TestGetSignedProposal(t *testing.T) {
343343
var signedProp *pb.SignedProposal
344344
var err error
345345

346-
signID, err := mockmsp.NewNoopMsp().GetDefaultSigningIdentity()
347-
assert.NoError(t, err, "Unexpected error getting signing identity")
346+
sig := []byte("signature")
347+
348+
signID := &fakes.SignerSerializer{}
349+
signID.SignReturns(sig, nil)
348350

349351
prop := &pb.Proposal{}
350352
propBytes, _ := proto.Marshal(prop)
351353
signedProp, err = protoutil.GetSignedProposal(prop, signID)
352354
assert.NoError(t, err, "Unexpected error getting signed proposal")
353355
assert.Equal(t, propBytes, signedProp.ProposalBytes,
354356
"Proposal bytes did not match expected value")
355-
assert.Equal(t, []byte("signature"), signedProp.Signature,
357+
assert.Equal(t, sig, signedProp.Signature,
356358
"Signature did not match expected value")
357359

358360
_, err = protoutil.GetSignedProposal(nil, signID)
@@ -400,8 +402,8 @@ func TestMockSignedEndorserProposal2OrPanic(t *testing.T) {
400402
cis := &pb.ChaincodeInvocationSpec{}
401403
chainID := "testchannelid"
402404
sig := []byte("signature")
403-
signID, err := mockmsp.NewNoopMsp().GetDefaultSigningIdentity()
404-
assert.NoError(t, err, "Unexpected error getting signing identity")
405+
signID := &fakes.SignerSerializer{}
406+
signID.SignReturns(sig, nil)
405407

406408
signedProp, prop = protoutil.MockSignedEndorserProposal2OrPanic(chainID,
407409
&pb.ChaincodeSpec{}, signID)
@@ -410,7 +412,7 @@ func TestMockSignedEndorserProposal2OrPanic(t *testing.T) {
410412
propBytes, _ := proto.Marshal(prop)
411413
assert.Equal(t, propBytes, signedProp.ProposalBytes,
412414
"Proposal bytes do not match expected value")
413-
err = proto.Unmarshal(prop.Payload, ccProposal)
415+
err := proto.Unmarshal(prop.Payload, ccProposal)
414416
assert.NoError(t, err, "Expected ChaincodeProposalPayload")
415417
err = proto.Unmarshal(ccProposal.Input, cis)
416418
assert.NoError(t, err, "Expected ChaincodeInvocationSpec")

0 commit comments

Comments
 (0)