Skip to content

Commit

Permalink
Fix noop chaincode argument handling
Browse files Browse the repository at this point in the history
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 <gabor@digitalasset.com>
  • Loading branch information
gaborh-da committed Sep 1, 2016
1 parent 0289230 commit 34ef640
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion bddtests/syschaincode/noop/chaincode.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ 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) {
if len(args) != 1 {
if len(args) != 0 || function == "" {
return nil, errors.New("Noop execute operation must have one single argument.")
}
logger.Infof("Executing noop invoke.")
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 @@ -47,23 +47,23 @@ func TestInvokeUnsupported(t *testing.T) {

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

func TestInvokeExecuteOneArgReturnsNothing(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "execute", []string{"arg1"})
var res, err = noop.Invoke(nil, "transaction", []string{})
if res != nil || err != nil {
t.Errorf("Invoke.execute has to return nil with no error.")
}
}

func TestInvokeExecuteMoreArgsReturnsError(t *testing.T) {
var noop = SystemChaincode{mockLedger{}}
var res, err = noop.Invoke(nil, "execute", []string{"arg1", "arg2"})
var res, err = noop.Invoke(nil, "transaction", []string{"arg1"})
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 34ef640

Please sign in to comment.