From 5f853da7bb5c84090c3a3f985ec4689b4b9b1448 Mon Sep 17 00:00:00 2001 From: Srinivasan Muralidharan Date: Wed, 23 Aug 2017 23:39:25 -0400 Subject: [PATCH] [FAB-5899] unable to use signed install package The check for detecting if a chaincode lifecycle operation (install instantiate or upgrade) was on a Java chaincode was expecting a ChaincodeDeploymentSpec (currently only form supported by SDKs). This prevented signed packages installed from CLI from working. This is good to get working in anticipation of full future adoption by SDKs. Change-Id: Iead28f60e13e16048cd01464bd471e9c4d6e4d05 Signed-off-by: Srinivasan Muralidharan (cherry picked from commit 6ffdc30c7eca469bf1f9df9acc4f8975dd402ffe) Signed-off-by: Gari Singh --- core/endorser/endorser.go | 4 +++- core/endorser/endorser_test.go | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/endorser/endorser.go b/core/endorser/endorser.go index 0cd4c778a3d..302029c85c5 100644 --- a/core/endorser/endorser.go +++ b/core/endorser/endorser.go @@ -190,11 +190,13 @@ func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvoc } //the inner dep spec will contain the type - cds, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[argNo]) + ccpack, err := ccprovider.GetCCPackage(cis.ChaincodeSpec.Input.Args[argNo]) if err != nil { return err } + cds := ccpack.GetDepSpec() + //finally, if JAVA error out if cds.ChaincodeSpec.Type == pb.ChaincodeSpec_JAVA { return fmt.Errorf("Java chaincode is work-in-progress and disabled") diff --git a/core/endorser/endorser_test.go b/core/endorser/endorser_test.go index 88f0f3944f1..55364f3de1b 100644 --- a/core/endorser/endorser_test.go +++ b/core/endorser/endorser_test.go @@ -368,6 +368,29 @@ func TestJavaDeploy(t *testing.T) { chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec}) } +func TestJavaCheckWithDifferentPackageTypes(t *testing.T) { + //try SignedChaincodeDeploymentSpec with go chaincode (type 1) + spec := &pb.ChaincodeSpec{Type: 1, ChaincodeId: &pb.ChaincodeID{Name: "gocc", Path: "path/to/cc", Version: "0"}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("someargs")}}} + cds := &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec, CodePackage: []byte("some code")} + env := &common.Envelope{Payload: pbutils.MarshalOrPanic(&common.Payload{Data: pbutils.MarshalOrPanic(&pb.SignedChaincodeDeploymentSpec{ChaincodeDeploymentSpec: pbutils.MarshalOrPanic(cds)})})} + //wrap the package in an invocation spec to lscc... + b := pbutils.MarshalOrPanic(env) + + lsccCID := &pb.ChaincodeID{Name: "lscc", Version: util.GetSysCCVersion()} + lsccSpec := &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: lsccCID, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("install"), b}}}} + + e := &Endorser{} + err := e.disableJavaCCInst(lsccCID, lsccSpec) + assert.Nil(t, err) + + //now try plain ChaincodeDeploymentSpec...should succeed (go chaincode) + b = pbutils.MarshalOrPanic(cds) + + lsccSpec = &pb.ChaincodeInvocationSpec{ChaincodeSpec: &pb.ChaincodeSpec{Type: pb.ChaincodeSpec_GOLANG, ChaincodeId: lsccCID, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("install"), b}}}} + err = e.disableJavaCCInst(lsccCID, lsccSpec) + assert.Nil(t, err) +} + //TestRedeploy - deploy two times, second time should fail but example02 should remain deployed func TestRedeploy(t *testing.T) { chainID := util.GetTestChainID()