Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FABGW-25 Test for system chaincode #2771

Merged
merged 1 commit into from
Jul 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,10 @@ func (e *Endorser) buildChaincodeInterest(simResult *ledger.TxSimulationResults)

// 3. Add/merge collections from the PrivateReads struct
for ns, entry := range simResult.PrivateReads {
if e.Support.IsSysCC(ns) {
// skip system chaincodes
continue
}
if cc := chaincodes[ns]; cc == nil {
// chaincode either not already in the map, or nil entry - add it
chaincodes[ns] = map[string]bool{}
Expand Down
64 changes: 64 additions & 0 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,5 +1223,69 @@ var _ = Describe("Endorser", func() {
},
)).To(BeTrue())
})

It("ignores system chaincodes", func() {
fakeSupport.IsSysCCStub = func(cc string) bool {
return cc == "_lifecycle"
}
pubSimResults = &rwset.TxReadWriteSet{
DataModel: rwset.TxReadWriteSet_KV,
NsRwset: []*rwset.NsReadWriteSet{
{
Namespace: "myCC",
Rwset: []byte("public RW set"),
},
{
Namespace: "_lifecycle",
Rwset: []byte("should be ignored 1"),
},
},
}

pvtSimResults = &rwset.TxPvtReadWriteSet{
DataModel: rwset.TxReadWriteSet_KV,
NsPvtRwset: []*rwset.NsPvtReadWriteSet{
{
Namespace: "myCC",
CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{
{
CollectionName: "mycollection-1",
Rwset: []byte("private RW set"),
},
},
},
{
Namespace: "_lifecycle",
CollectionPvtRwset: []*rwset.CollectionPvtReadWriteSet{
{
CollectionName: "mycollection-2",
Rwset: []byte("should be ignored 2"),
},
},
},
},
}
privateReads := ledger.PrivateReads{}
privateReads.Add("myCC", "mycollection-1")
privateReads.Add("_lifecycle", "mycollection-1")

fakeTxSimulator.GetTxSimulationResultsReturns(
&ledger.TxSimulationResults{
PubSimulationResults: pubSimResults,
PvtSimulationResults: pvtSimResults,
PrivateReads: privateReads,
},
nil,
)

proposalResponse, err := e.ProcessProposal(context.TODO(), signedProposal)
Expect(err).NotTo(HaveOccurred())
Expect(proposalResponse.Interest).To(Equal(&pb.ChaincodeInterest{
Chaincodes: []*pb.ChaincodeCall{{
Name: "myCC",
CollectionNames: []string{"mycollection-1"},
}},
}))
})
})
})