Skip to content

Commit

Permalink
Merge "[FAB-16169] CR Comments"
Browse files Browse the repository at this point in the history
  • Loading branch information
manish-sethi authored and Gerrit Code Review committed Nov 20, 2019
2 parents 5c898da + 8a70b67 commit 8aca8e7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 42 deletions.
4 changes: 0 additions & 4 deletions core/tx/endorser/endorsertx_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions core/tx/endorser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var (
type EndorserTx struct {
ComputedTxID string
ChID string
CcID string
CCName string
Creator []byte
Response *peer.Response
Events []byte
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

Expand Down
66 changes: 31 additions & 35 deletions core/tx/endorser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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{
Expand All @@ -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"),
Expand All @@ -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,
Expand Down Expand Up @@ -108,7 +108,7 @@ var _ = Describe("Parser", func() {

var txenvPayloadDataBytes []byte
if payloadData != nil {
txenvPayloadDataBytes = payloadData.msg
txenvPayloadDataBytes = payloadData
} else {
txenvPayloadDataBytes = protoutil.MarshalOrPanic(tx)
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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(
Expand All @@ -221,7 +221,7 @@ var _ = Describe("Parser", func() {
),
},
},
})}
})
})

It("returns an error", func() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 8aca8e7

Please sign in to comment.