From 8a70b67577684e478765a85e72767ea480a59349 Mon Sep 17 00:00:00 2001 From: Alessandro Sorniotti Date: Fri, 13 Sep 2019 10:11:53 +0200 Subject: [PATCH] [FAB-16169] CR Comments Change-Id: I271d18816bd2358f95a6c338d808f42e5e2f1128 Signed-off-by: Alessandro Sorniotti --- core/tx/endorser/endorsertx_suite_test.go | 4 -- core/tx/endorser/parser.go | 8 +-- core/tx/endorser/parser_test.go | 66 +++++++++++------------ 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/core/tx/endorser/endorsertx_suite_test.go b/core/tx/endorser/endorsertx_suite_test.go index 15f831ec803..8ef1599f9ce 100644 --- a/core/tx/endorser/endorsertx_suite_test.go +++ b/core/tx/endorser/endorsertx_suite_test.go @@ -14,10 +14,6 @@ import ( . "github.com/onsi/gomega" ) -type protomsg struct { - msg []byte -} - func randomLowerAlphaString(size int) string { letters := []rune("abcdefghijklmnopqrstuvwxyz") output := make([]rune, size) diff --git a/core/tx/endorser/parser.go b/core/tx/endorser/parser.go index df1c855eac8..5568a24b7ca 100644 --- a/core/tx/endorser/parser.go +++ b/core/tx/endorser/parser.go @@ -28,7 +28,7 @@ var ( type EndorserTx struct { ComputedTxID string ChID string - CcID string + CCName string Creator []byte Response *peer.Response Events []byte @@ -147,7 +147,9 @@ func NewEndorserTx(txenv *tx.Envelope) (*EndorserTx, error) { return nil, errors.New("empty ProposalResponsePayload") } - proposalResponsePayload, err := protoutil.UnmarshalProposalResponsePayload(ccActionPayload.Action.ProposalResponsePayload) + proposalResponsePayload, err := protoutil.UnmarshalProposalResponsePayload( + ccActionPayload.Action.ProposalResponsePayload, + ) if err != nil { return nil, err } @@ -178,7 +180,7 @@ func NewEndorserTx(txenv *tx.Envelope) (*EndorserTx, error) { Events: ccAction.Events, Results: ccAction.Results, Endorsements: ccActionPayload.Action.Endorsements, - CcID: hdrExt.ChaincodeId.Name, // FIXME: we might have to get the ccid from the CIS + CCName: hdrExt.ChaincodeId.Name, // FIXME: we might have to get the ccid from the CIS }, nil } diff --git a/core/tx/endorser/parser_test.go b/core/tx/endorser/parser_test.go index 34cb6bdeda4..de21c7e206a 100644 --- a/core/tx/endorser/parser_test.go +++ b/core/tx/endorser/parser_test.go @@ -23,10 +23,10 @@ import ( var _ = Describe("Parser", func() { var ( txenv *tx.Envelope - hdrExt *protomsg - payloadData *protomsg - prpExt *protomsg - prp *protomsg + hdrExt []byte + payloadData []byte + prpExt []byte + prp []byte chHeader *common.ChannelHeader sigHeader *common.SignatureHeader ) @@ -48,7 +48,7 @@ var _ = Describe("Parser", func() { JustBeforeEach(func() { var hdrExtBytes []byte if hdrExt != nil { - hdrExtBytes = hdrExt.msg + hdrExtBytes = hdrExt } else { hdrExtBytes = protoutil.MarshalOrPanic( &peer.ChaincodeHeaderExtension{ @@ -63,7 +63,7 @@ var _ = Describe("Parser", func() { var extBytes []byte if prpExt != nil { - extBytes = prpExt.msg + extBytes = prpExt } else { extBytes = protoutil.MarshalOrPanic(&peer.ChaincodeAction{ Results: []byte("results"), @@ -76,7 +76,7 @@ var _ = Describe("Parser", func() { var prpBytes []byte if prp != nil { - prpBytes = prp.msg + prpBytes = prp } else { prpBytes = protoutil.MarshalOrPanic(&peer.ProposalResponsePayload{ Extension: extBytes, @@ -108,7 +108,7 @@ var _ = Describe("Parser", func() { var txenvPayloadDataBytes []byte if payloadData != nil { - txenvPayloadDataBytes = payloadData.msg + txenvPayloadDataBytes = payloadData } else { txenvPayloadDataBytes = protoutil.MarshalOrPanic(tx) } @@ -138,13 +138,13 @@ var _ = Describe("Parser", func() { }, ChID: "my-channel", Creator: []byte("creator"), - CcID: "my-called-cc", + CCName: "my-called-cc", })) }) When("there is no payload data", func() { BeforeEach(func() { - payloadData = &protomsg{} + payloadData = []byte{} }) It("returns an error", func() { @@ -156,7 +156,7 @@ var _ = Describe("Parser", func() { When("there is bad payload data", func() { BeforeEach(func() { - payloadData = &protomsg{msg: []byte("barf")} + payloadData = []byte("barf") }) It("returns an error", func() { @@ -168,9 +168,9 @@ var _ = Describe("Parser", func() { When("there is bad payload data", func() { BeforeEach(func() { - payloadData = &protomsg{msg: protoutil.MarshalOrPanic(&peer.Transaction{ + payloadData = protoutil.MarshalOrPanic(&peer.Transaction{ Actions: []*peer.TransactionAction{{}, {}}, - })} + }) }) It("returns an error", func() { @@ -182,9 +182,9 @@ var _ = Describe("Parser", func() { When("the transaction action has no payload", func() { BeforeEach(func() { - payloadData = &protomsg{msg: protoutil.MarshalOrPanic(&peer.Transaction{ + payloadData = protoutil.MarshalOrPanic(&peer.Transaction{ Actions: []*peer.TransactionAction{{}}, - })} + }) }) It("returns an error", func() { @@ -196,9 +196,9 @@ var _ = Describe("Parser", func() { When("the transaction action has a bad payload", func() { BeforeEach(func() { - payloadData = &protomsg{msg: protoutil.MarshalOrPanic(&peer.Transaction{ + payloadData = protoutil.MarshalOrPanic(&peer.Transaction{ Actions: []*peer.TransactionAction{{Payload: []byte("barf")}}, - })} + }) }) It("returns an error", func() { @@ -210,7 +210,7 @@ var _ = Describe("Parser", func() { When("the transaction action has a bad payload", func() { BeforeEach(func() { - payloadData = &protomsg{msg: protoutil.MarshalOrPanic(&peer.Transaction{ + payloadData = protoutil.MarshalOrPanic(&peer.Transaction{ Actions: []*peer.TransactionAction{ { Payload: protoutil.MarshalOrPanic( @@ -221,7 +221,7 @@ var _ = Describe("Parser", func() { ), }, }, - })} + }) }) It("returns an error", func() { @@ -233,7 +233,7 @@ var _ = Describe("Parser", func() { When("there is no header extension", func() { BeforeEach(func() { - hdrExt = &protomsg{} + hdrExt = []byte{} }) It("returns an error", func() { @@ -245,7 +245,7 @@ var _ = Describe("Parser", func() { When("there is a bad header extension", func() { BeforeEach(func() { - hdrExt = &protomsg{msg: []byte("barf")} + hdrExt = []byte("barf") }) It("returns an error", func() { @@ -257,7 +257,7 @@ var _ = Describe("Parser", func() { When("there is no ProposalResponsePayload", func() { BeforeEach(func() { - prp = &protomsg{} + prp = []byte{} }) It("returns an error", func() { @@ -269,7 +269,7 @@ var _ = Describe("Parser", func() { When("there is a bad ProposalResponsePayload", func() { BeforeEach(func() { - prp = &protomsg{msg: []byte("barf")} + prp = []byte("barf") }) It("returns an error", func() { @@ -281,7 +281,7 @@ var _ = Describe("Parser", func() { When("there is no ProposalResponsePayload", func() { BeforeEach(func() { - prpExt = &protomsg{} + prpExt = []byte{} }) It("returns an error", func() { @@ -293,7 +293,7 @@ var _ = Describe("Parser", func() { When("there is a bad ProposalResponsePayload", func() { BeforeEach(func() { - prpExt = &protomsg{msg: []byte("barf")} + prpExt = []byte("barf") }) It("returns an error", func() { @@ -399,9 +399,7 @@ var _ = Describe("Parser", func() { // return a non-nil struct bytes, err := hex.DecodeString("1a046369616f") Expect(err).To(BeNil()) - hdrExt = &protomsg{ - msg: bytes, - } + hdrExt = bytes }) It("returns an error", func() { @@ -413,13 +411,11 @@ var _ = Describe("Parser", func() { When("there is an empty chaincode name", func() { BeforeEach(func() { - hdrExt = &protomsg{ - msg: protoutil.MarshalOrPanic( - &peer.ChaincodeHeaderExtension{ - ChaincodeId: &peer.ChaincodeID{}, - }, - ), - } + hdrExt = protoutil.MarshalOrPanic( + &peer.ChaincodeHeaderExtension{ + ChaincodeId: &peer.ChaincodeID{}, + }, + ) }) It("returns an error", func() {