From 6aec331480ce51e14590ad09745a1a36165ee6c3 Mon Sep 17 00:00:00 2001 From: Gabor Hosszu Date: Wed, 17 Aug 2016 16:29:15 +0200 Subject: [PATCH] Update noop chaincode - no need for function, only one kind of operation is supported by this chaincode - exactly one argument is needed Change-Id: I1700b6fbd1a1c6a5086af075be323c96426da083 Signed-off-by: Gabor Hosszu --- bddtests/syschaincode/noop/chaincode.go | 23 ++++++++------------ bddtests/syschaincode/noop/chaincode_test.go | 6 ++--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/bddtests/syschaincode/noop/chaincode.go b/bddtests/syschaincode/noop/chaincode.go index 6a301312ef9..e4cd3db5d84 100644 --- a/bddtests/syschaincode/noop/chaincode.go +++ b/bddtests/syschaincode/noop/chaincode.go @@ -17,7 +17,6 @@ package noop import ( - "bytes" "errors" "github.com/golang/protobuf/proto" @@ -60,18 +59,11 @@ func (t *SystemChaincode) Init(stub shim.ChaincodeStubInterface, function string // Invoke runs an invocation on the system chaincode func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) { - switch function { - case "execute": - - if len(args) < 1 { - return nil, errors.New("execute operation must include single argument, the base64 encoded form of a byte sequence") - } - logger.Infof("Executing NOOP INVOKE") - return nil, nil - - default: - return nil, errors.New("Unsupported operation") + if len(args) != 1 { + return nil, errors.New("Noop execute operation must have one single argument.") } + logger.Infof("Executing noop invoke.") + return nil, nil } // Query callback representing the query of a chaincode @@ -94,8 +86,11 @@ func (t *SystemChaincode) Query(stub shim.ChaincodeStubInterface, function strin if nil != merr { return nil, merr } - var dataInByteForm = newCCIS.ChaincodeSpec.CtorMsg.Args - return bytes.Join(dataInByteForm, []byte{}), nil + if len(newCCIS.ChaincodeSpec.CtorMsg.Args) < 1 { + return nil, errors.New("The requested transaction is malformed.") + } + var dataInByteForm = newCCIS.ChaincodeSpec.CtorMsg.Args[0] + return dataInByteForm, nil default: return nil, errors.New("Unsupported operation") } diff --git a/bddtests/syschaincode/noop/chaincode_test.go b/bddtests/syschaincode/noop/chaincode_test.go index 7664329a6ac..5b4e80a69d8 100644 --- a/bddtests/syschaincode/noop/chaincode_test.go +++ b/bddtests/syschaincode/noop/chaincode_test.go @@ -61,11 +61,11 @@ func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) { } } -func TestInvokeExecuteMoreArgsReturnsNothing(t *testing.T) { +func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) { var noop = SystemChaincode{mockLedger{}} var res, err = noop.Invoke(nil, "execute", []string{"arg1", "arg2"}) - if res != nil || err != nil { - t.Errorf("Invoke.execute has to return nil with no error.") + if res != nil || err == nil { + t.Errorf("Invoke.execute has to return error when called with more than one arguments.") } }