From 9b8c6a0603cf05b42cac56e285d0f5650887377b Mon Sep 17 00:00:00 2001 From: Jim Zhang Date: Mon, 19 Jun 2017 14:14:02 -0400 Subject: [PATCH] [FAB-4870] Confusing fcn name handling in tests Change-Id: Iad54ac57911377b44eb03e76dd0a1d0b6d25ff8e Signed-off-by: Jim Zhang --- .../src/github.com/example_cc/example_cc.go | 32 ++++++----------- .../src/github.com/example_cc1/example_cc1.go | 34 +++++++------------ test/integration/e2e/e2eUtils.js | 10 +++--- test/integration/grpc.js | 4 +-- 4 files changed, 30 insertions(+), 50 deletions(-) diff --git a/test/fixtures/src/github.com/example_cc/example_cc.go b/test/fixtures/src/github.com/example_cc/example_cc.go index 5ede20c58f..06fd76b965 100644 --- a/test/fixtures/src/github.com/example_cc/example_cc.go +++ b/test/fixtures/src/github.com/example_cc/example_cc.go @@ -39,10 +39,6 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response { var Aval, Bval int // Asset holdings var err error - if len(args) != 4 { - return shim.Error("Incorrect number of arguments. Expecting 4") - } - // Initialize the chaincode A = args[0] Aval, err = strconv.Atoi(args[1]) @@ -78,24 +74,16 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { function, args := stub.GetFunctionAndParameters() - if function != "invoke" { - return shim.Error("Unknown function call") - } - - if len(args) < 2 { - return shim.Error("Incorrect number of arguments. Expecting at least 2") - } - - if args[0] == "delete" { + if function == "delete" { // Deletes an entity from its state return t.delete(stub, args) } - if args[0] == "query" { + if function == "query" { // queries an entity state return t.query(stub, args) } - if args[0] == "move" { + if function == "move" { // Deletes an entity from its state return t.move(stub, args) } @@ -111,12 +99,12 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) var X int // Transaction value var err error - if len(args) != 4 { + if len(args) != 3 { return shim.Error("Incorrect number of arguments. Expecting 4, function followed by 2 names and 1 value") } - A = args[1] - B = args[2] + A = args[0] + B = args[1] // Get the state from the ledger // TODO: will be nice to have a GetAllState call to ledger @@ -139,7 +127,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) Bval, _ = strconv.Atoi(string(Bvalbytes)) // Perform the execution - X, err = strconv.Atoi(args[3]) + X, err = strconv.Atoi(args[2]) if err != nil { return shim.Error("Invalid transaction amount, expecting a integer value") } @@ -167,7 +155,7 @@ func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string return shim.Error("Incorrect number of arguments. Expecting 1") } - A := args[1] + A := args[0] // Delete the key from the state in ledger err := stub.DelState(A) @@ -184,11 +172,11 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) var A string // Entities var err error - if len(args) != 2 { + if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting name of the person to query") } - A = args[1] + A = args[0] // Get the state from the ledger Avalbytes, err := stub.GetState(A) diff --git a/test/fixtures/src/github.com/example_cc1/example_cc1.go b/test/fixtures/src/github.com/example_cc1/example_cc1.go index e4bf3c863b..f2a0c1967d 100644 --- a/test/fixtures/src/github.com/example_cc1/example_cc1.go +++ b/test/fixtures/src/github.com/example_cc1/example_cc1.go @@ -44,32 +44,24 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response { logger.Info("########### example_cc1 Invoke ###########") function, args := stub.GetFunctionAndParameters() - - if function != "invoke" { - return shim.Error("Unknown function call") - } - - if len(args) < 2 { - return shim.Error("Incorrect number of arguments. Expecting at least 2") - } - if args[0] == "delete" { + if function == "delete" { // Deletes an entity from its state return t.delete(stub, args) } - if args[0] == "query" { + if function == "query" { // queries an entity state return t.query(stub, args) } - if args[0] == "move" { + if function == "move" { // Deletes an entity from its state return t.move(stub, args) } - if args[0] == "echo" { + if function == "echo" { return t.echo(stub, args) } - if args[0] == "testTransient" { + if function == "testTransient" { return t.testTransient(stub) } @@ -84,12 +76,12 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) var X int // Transaction value var err error - if len(args) != 4 { + if len(args) != 3 { return shim.Error("Incorrect number of arguments. Expecting 4, function followed by 2 names and 1 value") } - A = args[1] - B = args[2] + A = args[0] + B = args[1] // Get the state from the ledger // TODO: will be nice to have a GetAllState call to ledger @@ -112,7 +104,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string) Bval, _ = strconv.Atoi(string(Bvalbytes)) // Perform the execution - X, err = strconv.Atoi(args[3]) + X, err = strconv.Atoi(args[2]) if err != nil { return shim.Error("Invalid transaction amount, expecting a integer value") } @@ -140,7 +132,7 @@ func (t *SimpleChaincode) delete(stub shim.ChaincodeStubInterface, args []string return shim.Error("Incorrect number of arguments. Expecting 1") } - A := args[1] + A := args[0] // Delete the key from the state in ledger err := stub.DelState(A) @@ -157,11 +149,11 @@ func (t *SimpleChaincode) query(stub shim.ChaincodeStubInterface, args []string) var A string // Entities var err error - if len(args) != 2 { + if len(args) != 1 { return shim.Error("Incorrect number of arguments. Expecting name of the person to query") } - A = args[1] + A = args[0] // Get the state from the ledger Avalbytes, err := stub.GetState(A) @@ -201,7 +193,7 @@ func (t *SimpleChaincode) testTransient(stub shim.ChaincodeStubInterface) pb.Res func (t *SimpleChaincode) echo(stub shim.ChaincodeStubInterface, args []string) pb.Response { logger.Info("Echo Response\n") - return shim.Success([]byte(args[1])) + return shim.Success([]byte(args[0])) } func main() { diff --git a/test/integration/e2e/e2eUtils.js b/test/integration/e2e/e2eUtils.js index 20d3f3c618..8f1022f524 100644 --- a/test/integration/e2e/e2eUtils.js +++ b/test/integration/e2e/e2eUtils.js @@ -561,8 +561,8 @@ function invokeChaincode(userOrg, version, t, useStore){ // send proposal to endorser var request = { chaincodeId : e2e.chaincodeId, - fcn: 'invoke', - args: ['move', 'a', 'b','100'], + fcn: 'move', + args: ['a', 'b','100'], txId: tx_id, }; return channel.sendTransactionProposal(request); @@ -757,13 +757,13 @@ function queryChaincode(org, version, value, t, transientMap) { var request = { chaincodeId : e2e.chaincodeId, txId: tx_id, - fcn: 'invoke', - args: ['query','b'] + fcn: 'query', + args: ['b'] }; if (transientMap) { request.transientMap = transientMap; - request.args = ['testTransient', '']; + request.fcn = 'testTransient'; } return channel.queryByChaincode(request); diff --git a/test/integration/grpc.js b/test/integration/grpc.js index 5350a8d219..757f010e9c 100644 --- a/test/integration/grpc.js +++ b/test/integration/grpc.js @@ -168,8 +168,8 @@ function buildEchoRequest(client, peer) { return { targets: [peer], chaincodeId : e2e.chaincodeId, - fcn: 'invoke', - args: ['echo', crypto.randomBytes(1024 * 1024)], + fcn: 'echo', + args: [crypto.randomBytes(1024 * 1024)], txId: tx_id, nonce: nonce };