Skip to content

Commit

Permalink
Merge "[FAB-3850] disable java chaincode as its WIP"
Browse files Browse the repository at this point in the history
  • Loading branch information
christo4ferris authored and Gerrit Code Review committed May 12, 2017
2 parents a3ee54f + 29e0c40 commit 32bb152
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
49 changes: 49 additions & 0 deletions core/endorser/endorser.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,50 @@ func (e *Endorser) callChaincode(ctxt context.Context, chainID string, version s
return res, ccevent, err
}

//TO BE REMOVED WHEN JAVA CC IS ENABLED
//disableJavaCCInst if trying to install, instantiate or upgrade Java CC
func (e *Endorser) disableJavaCCInst(cid *pb.ChaincodeID, cis *pb.ChaincodeInvocationSpec) error {
//if not lscc we don't care
if cid.Name != "lscc" {
return nil
}

//non-nil spec ? leave it to callers to handle error if this is an error
if cis.ChaincodeSpec == nil || cis.ChaincodeSpec.Input == nil {
return nil
}

//should at least have a command arg, leave it to callers if this is an error
if len(cis.ChaincodeSpec.Input.Args) < 1 {
return nil
}

var argNo int
switch string(cis.ChaincodeSpec.Input.Args[0]) {
case "install":
argNo = 1
case "deploy", "upgrade":
argNo = 2
default:
//what else can it be ? leave it caller to handle it if error
return nil
}

//the inner dep spec will contain the type
cds, err := putils.GetChaincodeDeploymentSpec(cis.ChaincodeSpec.Input.Args[argNo])
if err != nil {
return err
}

//finally, if JAVA error out
if cds.ChaincodeSpec.Type == pb.ChaincodeSpec_JAVA {
return fmt.Errorf("Java chaincode is work-in-progress and disabled")
}

//not a java install, instantiate or upgrade op
return nil
}

//simulate the proposal by calling the chaincode
func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid string, signedProp *pb.SignedProposal, prop *pb.Proposal, cid *pb.ChaincodeID, txsim ledger.TxSimulator) (*ccprovider.ChaincodeData, *pb.Response, []byte, *pb.ChaincodeEvent, error) {
//we do expect the payload to be a ChaincodeInvocationSpec
Expand All @@ -164,6 +208,11 @@ func (e *Endorser) simulateProposal(ctx context.Context, chainID string, txid st
return nil, nil, nil, nil, err
}

//disable Java install,instantiate,upgrade for now
if err = e.disableJavaCCInst(cid, cis); err != nil {
return nil, nil, nil, nil, err
}

//---1. check ESCC and VSCC for the chaincode
if err = e.checkEsccAndVscc(prop); err != nil {
return nil, nil, nil, nil, err
Expand Down
19 changes: 19 additions & 0 deletions core/endorser/endorser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,25 @@ func TestDeploy(t *testing.T) {
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}

//REMOVE WHEN JAVA CC IS ENABLED
func TestJavaDeploy(t *testing.T) {
chainID := util.GetTestChainID()
//pretend this is a java CC (type 4)
spec := &pb.ChaincodeSpec{Type: 4, ChaincodeId: &pb.ChaincodeID{Name: "javacc", Path: "../../examples/chaincode/java/chaincode_example02", Version: "0"}, Input: &pb.ChaincodeInput{Args: [][]byte{[]byte("init"), []byte("a"), []byte("100"), []byte("b"), []byte("200")}}}
defer deleteChaincodeOnDisk("javacc.0")

cccid := ccprovider.NewCCContext(chainID, "javacc", "0", "", false, nil, nil)

_, _, err := deploy(endorserServer, chainID, spec, nil)
if err == nil {
t.Fail()
t.Logf("expected java CC deploy to fail")
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
return
}
chaincode.GetChain().Stop(context.Background(), cccid, &pb.ChaincodeDeploymentSpec{ChaincodeSpec: spec})
}

//TestRedeploy - deploy two times, second time should fail but example02 should remain deployed
func TestRedeploy(t *testing.T) {
chainID := util.GetTestChainID()
Expand Down
3 changes: 3 additions & 0 deletions peer/chaincode/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func getChaincodeSpec(cmd *cobra.Command) (*pb.ChaincodeSpec, error) {
}

chaincodeLang = strings.ToUpper(chaincodeLang)
if pb.ChaincodeSpec_Type_value[chaincodeLang] == int32(pb.ChaincodeSpec_JAVA) {
return nil, fmt.Errorf("Java chaincode is work-in-progress and disabled")
}
spec = &pb.ChaincodeSpec{
Type: pb.ChaincodeSpec_Type(pb.ChaincodeSpec_Type_value[chaincodeLang]),
ChaincodeId: &pb.ChaincodeID{Path: chaincodePath, Name: chaincodeName, Version: chaincodeVersion},
Expand Down

0 comments on commit 32bb152

Please sign in to comment.