Skip to content

Commit

Permalink
Update noop chaincode
Browse files Browse the repository at this point in the history
- 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 <gabor@digitalasset.com>
  • Loading branch information
gaborh-da committed Aug 18, 2016
1 parent 8f468f8 commit 6aec331
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
23 changes: 9 additions & 14 deletions bddtests/syschaincode/noop/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package noop

import (
"bytes"
"errors"

"github.com/golang/protobuf/proto"
Expand Down Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
6 changes: 3 additions & 3 deletions bddtests/syschaincode/noop/chaincode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}

Expand Down

0 comments on commit 6aec331

Please sign in to comment.