Skip to content

Commit

Permalink
Sort chaincode interests in tests (#2966)
Browse files Browse the repository at this point in the history
Signed-off-by: Alessandro Sorniotti <aso@zurich.ibm.com>
  • Loading branch information
ale-linux committed Sep 30, 2021
1 parent 7124587 commit c8a6c43
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package endorser_test
import (
"context"
"fmt"
"sort"

"github.com/golang/protobuf/proto"
cb "github.com/hyperledger/fabric-protos-go/common"
Expand All @@ -28,6 +29,34 @@ import (
"github.com/pkg/errors"
)

type CcInterest pb.ChaincodeInterest

func (a CcInterest) Len() int { return len(a.Chaincodes) }
func (a CcInterest) Swap(i, j int) {
a.Chaincodes[i], a.Chaincodes[j] = a.Chaincodes[j], a.Chaincodes[i]
}

func (a CcInterest) Less(i, j int) bool {
ai := a.Chaincodes[i]
aj := a.Chaincodes[j]

if ai.Name != aj.Name {
return ai.Name < aj.Name
}

if len(ai.CollectionNames) != len(aj.CollectionNames) {
return len(ai.CollectionNames) < len(aj.CollectionNames)
}

for ii := range ai.CollectionNames {
if ai.CollectionNames[ii] != aj.CollectionNames[ii] {
return ai.CollectionNames[ii] < aj.CollectionNames[ii]
}
}

return false
}

var _ = Describe("Endorser", func() {
var (
fakeProposalDuration *metricsfakes.Histogram
Expand Down Expand Up @@ -1108,6 +1137,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{{
Name: "myCC",
Expand Down Expand Up @@ -1144,6 +1174,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{
{
Expand Down Expand Up @@ -1183,6 +1214,7 @@ var _ = Describe("Endorser", func() {

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
sort.Sort(CcInterest(*proposalResponse.Interest))
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{{
Name: "myCC",
Expand Down Expand Up @@ -1221,6 +1253,7 @@ var _ = Describe("Endorser", func() {
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())

sort.Sort(CcInterest(*proposalResponse.Interest))
Expect(proto.Equal(
proposalResponse.Interest,
&pb.ChaincodeInterest{
Expand Down Expand Up @@ -1265,6 +1298,7 @@ var _ = Describe("Endorser", func() {
proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())

sort.Sort(CcInterest(*proposalResponse.Interest))
Expect(proto.Equal(
proposalResponse.Interest,
&pb.ChaincodeInterest{
Expand Down

0 comments on commit c8a6c43

Please sign in to comment.