From fa3960b33e83bc82117ba742f4710f8390219fd9 Mon Sep 17 00:00:00 2001 From: Andrew Coleman Date: Thu, 22 Jul 2021 13:51:19 +0100 Subject: [PATCH] FABGW-25 Test for system chaincode (#2771) This commit addresses the closing comments in PR #2767: - Skip systems chaincode in this block as well - Add a test that asserts that the system chaincodes are indeed skipped Signed-off-by: andrew-coleman --- core/endorser/endorser.go | 4 +++ core/endorser/endorser_test.go | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/core/endorser/endorser.go b/core/endorser/endorser.go index e4377761d01..1d5e8db6df2 100644 --- a/core/endorser/endorser.go +++ b/core/endorser/endorser.go @@ -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{} diff --git a/core/endorser/endorser_test.go b/core/endorser/endorser_test.go index 512bd7a1590..6571a63d29d 100644 --- a/core/endorser/endorser_test.go +++ b/core/endorser/endorser_test.go @@ -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"}, + }}, + })) + }) }) })