Skip to content

Commit 6aec331

Browse files
committed
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 <[email protected]>
1 parent 8f468f8 commit 6aec331

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

bddtests/syschaincode/noop/chaincode.go

+9-14
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package noop
1818

1919
import (
20-
"bytes"
2120
"errors"
2221

2322
"github.com/golang/protobuf/proto"
@@ -60,18 +59,11 @@ func (t *SystemChaincode) Init(stub shim.ChaincodeStubInterface, function string
6059

6160
// Invoke runs an invocation on the system chaincode
6261
func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
63-
switch function {
64-
case "execute":
65-
66-
if len(args) < 1 {
67-
return nil, errors.New("execute operation must include single argument, the base64 encoded form of a byte sequence")
68-
}
69-
logger.Infof("Executing NOOP INVOKE")
70-
return nil, nil
71-
72-
default:
73-
return nil, errors.New("Unsupported operation")
62+
if len(args) != 1 {
63+
return nil, errors.New("Noop execute operation must have one single argument.")
7464
}
65+
logger.Infof("Executing noop invoke.")
66+
return nil, nil
7567
}
7668

7769
// Query callback representing the query of a chaincode
@@ -94,8 +86,11 @@ func (t *SystemChaincode) Query(stub shim.ChaincodeStubInterface, function strin
9486
if nil != merr {
9587
return nil, merr
9688
}
97-
var dataInByteForm = newCCIS.ChaincodeSpec.CtorMsg.Args
98-
return bytes.Join(dataInByteForm, []byte{}), nil
89+
if len(newCCIS.ChaincodeSpec.CtorMsg.Args) < 1 {
90+
return nil, errors.New("The requested transaction is malformed.")
91+
}
92+
var dataInByteForm = newCCIS.ChaincodeSpec.CtorMsg.Args[0]
93+
return dataInByteForm, nil
9994
default:
10095
return nil, errors.New("Unsupported operation")
10196
}

bddtests/syschaincode/noop/chaincode_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) {
6161
}
6262
}
6363

64-
func TestInvokeExecuteMoreArgsReturnsNothing(t *testing.T) {
64+
func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) {
6565
var noop = SystemChaincode{mockLedger{}}
6666
var res, err = noop.Invoke(nil, "execute", []string{"arg1", "arg2"})
67-
if res != nil || err != nil {
68-
t.Errorf("Invoke.execute has to return nil with no error.")
67+
if res != nil || err == nil {
68+
t.Errorf("Invoke.execute has to return error when called with more than one arguments.")
6969
}
7070
}
7171

0 commit comments

Comments
 (0)