Skip to content

Commit

Permalink
Merge "FAB-16437 Remove common/mocks from protoutil"
Browse files Browse the repository at this point in the history
  • Loading branch information
mastersingh24 authored and Gerrit Code Review committed Nov 11, 2019
2 parents 7254385 + 6617030 commit 03710df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
3 changes: 1 addition & 2 deletions protoutil/commonutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ import (
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/common/crypto"
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/hyperledger/fabric/protoutil/fakes"
"github.com/stretchr/testify/assert"
)

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

type signerSerializer interface {
identity.SignerSerializer
Signer
}

func TestNonceRandomness(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions protoutil/txutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-protos-go/common"
"github.com/hyperledger/fabric-protos-go/peer"
"github.com/hyperledger/fabric/internal/pkg/identity"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -62,7 +61,7 @@ func GetEnvelopeFromBlock(data []byte) (*common.Envelope, error) {
func CreateSignedEnvelope(
txType common.HeaderType,
channelID string,
signer identity.SignerSerializer,
signer Signer,
dataMsg proto.Message,
msgVersion int32,
epoch uint64,
Expand All @@ -76,7 +75,7 @@ func CreateSignedEnvelope(
func CreateSignedEnvelopeWithTLSBinding(
txType common.HeaderType,
channelID string,
signer identity.SignerSerializer,
signer Signer,
dataMsg proto.Message,
msgVersion int32,
epoch uint64,
Expand Down Expand Up @@ -245,7 +244,7 @@ func CreateProposalResponse(
results []byte,
events []byte,
ccid *peer.ChaincodeID,
signingEndorser identity.SignerSerializer,
signingEndorser Signer,
) (*peer.ProposalResponse, error) {
hdr, err := UnmarshalHeader(hdrbytes)
if err != nil {
Expand Down Expand Up @@ -334,7 +333,7 @@ func CreateProposalResponseFailure(

// GetSignedProposal returns a signed proposal given a Proposal message and a
// signing identity
func GetSignedProposal(prop *peer.Proposal, signer identity.SignerSerializer) (*peer.SignedProposal, error) {
func GetSignedProposal(prop *peer.Proposal, signer Signer) (*peer.SignedProposal, error) {
// check for nil argument
if prop == nil || signer == nil {
return nil, errors.New("nil arguments")
Expand Down Expand Up @@ -381,7 +380,7 @@ func MockSignedEndorserProposalOrPanic(
func MockSignedEndorserProposal2OrPanic(
channelID string,
cs *peer.ChaincodeSpec,
signer identity.SignerSerializer,
signer Signer,
) (*peer.SignedProposal, *peer.Proposal) {
serializedSigner, err := signer.Serialize()
if err != nil {
Expand Down
24 changes: 13 additions & 11 deletions protoutil/txutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
pb "github.com/hyperledger/fabric-protos-go/peer"
mockmsp "github.com/hyperledger/fabric/common/mocks/msp"

"github.com/hyperledger/fabric/protoutil"
"github.com/hyperledger/fabric/protoutil/fakes"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -121,8 +121,8 @@ func TestCreateSignedTx(t *testing.T) {
var err error
prop := &pb.Proposal{}

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

Expand Down Expand Up @@ -240,8 +240,8 @@ func TestCreateSignedTxStatus(t *testing.T) {
})
assert.NoError(t, err)

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

signID, err := mockmsp.NewNoopMsp().GetDefaultSigningIdentity()
assert.NoError(t, err, "Unexpected error getting signing identity")
sig := []byte("signature")

signID := &fakes.SignerSerializer{}
signID.SignReturns(sig, nil)

prop := &pb.Proposal{}
propBytes, _ := proto.Marshal(prop)
signedProp, err = protoutil.GetSignedProposal(prop, signID)
assert.NoError(t, err, "Unexpected error getting signed proposal")
assert.Equal(t, propBytes, signedProp.ProposalBytes,
"Proposal bytes did not match expected value")
assert.Equal(t, []byte("signature"), signedProp.Signature,
assert.Equal(t, sig, signedProp.Signature,
"Signature did not match expected value")

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

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

0 comments on commit 03710df

Please sign in to comment.