Skip to content

Commit

Permalink
FABGW-25 Test for system chaincode (#2771)
Browse files Browse the repository at this point in the history
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 <andrew_coleman@uk.ibm.com>
  • Loading branch information
andrew-coleman authored Jul 22, 2021
1 parent 52b12dc commit fa3960b
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
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"},
}},
}))
})
})
})

0 comments on commit fa3960b

Please sign in to comment.