From 546360b7068183ee989520f40f6089612991b9ff Mon Sep 17 00:00:00 2001 From: Gari Singh Date: Sun, 26 Aug 2018 18:26:13 -0400 Subject: [PATCH] Improve error message when private data is disabled FAB-11712 #done Change-Id: I0d69f7ff05033d2d2cbb2642725a48ba2c86f328 Signed-off-by: Gari Singh --- core/scc/lscc/errors.go | 7 +++++++ core/scc/lscc/lscc.go | 6 ++++-- core/scc/lscc/lscc_test.go | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/scc/lscc/errors.go b/core/scc/lscc/errors.go index 703c5e40647..0698aaaf5d2 100644 --- a/core/scc/lscc/errors.go +++ b/core/scc/lscc/errors.go @@ -133,3 +133,10 @@ type CollectionsConfigUpgradesNotAllowed string func (f CollectionsConfigUpgradesNotAllowed) Error() string { return "as V1_2 capability is not enabled, collection upgrades are not allowed" } + +// PrivateChannelDataNotAvailable when V1_2 or later capability is not enabled +type PrivateChannelDataNotAvailable string + +func (f PrivateChannelDataNotAvailable) Error() string { + return "as V1_2 or later capability is not enabled, private channel collections and data are not available" +} diff --git a/core/scc/lscc/lscc.go b/core/scc/lscc/lscc.go index 12c216b82d5..d9896849136 100644 --- a/core/scc/lscc/lscc.go +++ b/core/scc/lscc/lscc.go @@ -855,8 +855,10 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response } // the maximum number of arguments depends on the capability of the channel - if (!ac.Capabilities().PrivateChannelData() && len(args) > 6) || - (ac.Capabilities().PrivateChannelData() && len(args) > 7) { + if !ac.Capabilities().PrivateChannelData() && len(args) > 6 { + return shim.Error(PrivateChannelDataNotAvailable("").Error()) + } + if ac.Capabilities().PrivateChannelData() && len(args) > 7 { return shim.Error(InvalidArgsLenErr(len(args)).Error()) } diff --git a/core/scc/lscc/lscc_test.go b/core/scc/lscc/lscc_test.go index d0c98cb2fc0..e30db648360 100644 --- a/core/scc/lscc/lscc_test.go +++ b/core/scc/lscc/lscc_test.go @@ -244,7 +244,7 @@ func TestDeploy(t *testing.T) { // As the PrivateChannelData is disabled, the following error message is expected due to the presence of // collectionConfigBytes in the stub.args errMessage := InvalidArgsLenErr(7).Error() - testDeploy(t, "example02", "1.0", path, false, false, true, InvalidArgsLenErr(7).Error(), scc, stub, []byte("collections")) + testDeploy(t, "example02", "1.0", path, false, false, true, PrivateChannelDataNotAvailable("").Error(), scc, stub, []byte("collections")) // Enable PrivateChannelData mocksccProvider := (&mscc.MocksccProviderFactory{