Skip to content

Commit 34ef640

Browse files
committed
Fix noop chaincode argument handling
As currently (for backward compatibility) the 0th element of args is passed as a function, Noop chaincode needs to threat this is its only argument. Change-Id: I5049db0210502355a3f11154e4bfaf04f9b2b17b Signed-off-by: Gabor Hosszu <[email protected]>
1 parent 0289230 commit 34ef640

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

bddtests/syschaincode/noop/chaincode.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (t *SystemChaincode) Init(stub shim.ChaincodeStubInterface, function string
5959

6060
// Invoke runs an invocation on the system chaincode
6161
func (t *SystemChaincode) Invoke(stub shim.ChaincodeStubInterface, function string, args []string) ([]byte, error) {
62-
if len(args) != 1 {
62+
if len(args) != 0 || function == "" {
6363
return nil, errors.New("Noop execute operation must have one single argument.")
6464
}
6565
logger.Infof("Executing noop invoke.")

bddtests/syschaincode/noop/chaincode_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,23 @@ func TestInvokeUnsupported(t *testing.T) {
4747

4848
func TestInvokeExecuteNotEnoughArgs(t *testing.T) {
4949
var noop = SystemChaincode{mockLedger{}}
50-
var res, err = noop.Invoke(nil, "execute", []string{})
50+
var res, err = noop.Invoke(nil, "", []string{})
5151
if res != nil || err == nil {
5252
t.Errorf("Invoke.execute has to indicate error if called with less than one arguments!")
5353
}
5454
}
5555

5656
func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) {
5757
var noop = SystemChaincode{mockLedger{}}
58-
var res, err = noop.Invoke(nil, "execute", []string{"arg1"})
58+
var res, err = noop.Invoke(nil, "transaction", []string{})
5959
if res != nil || err != nil {
6060
t.Errorf("Invoke.execute has to return nil with no error.")
6161
}
6262
}
6363

6464
func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) {
6565
var noop = SystemChaincode{mockLedger{}}
66-
var res, err = noop.Invoke(nil, "execute", []string{"arg1", "arg2"})
66+
var res, err = noop.Invoke(nil, "transaction", []string{"arg1"})
6767
if res != nil || err == nil {
6868
t.Errorf("Invoke.execute has to return error when called with more than one arguments.")
6969
}

0 commit comments

Comments
 (0)