Skip to content

Commit

Permalink
[FAB-4870] Confusing fcn name handling in tests
Browse files Browse the repository at this point in the history
Change-Id: Iad54ac57911377b44eb03e76dd0a1d0b6d25ff8e
Signed-off-by: Jim Zhang <jzhang@us.ibm.com>
  • Loading branch information
jimthematrix committed Jun 19, 2017
1 parent 9f9659f commit 9b8c6a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 50 deletions.
32 changes: 10 additions & 22 deletions test/fixtures/src/github.com/example_cc/example_cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
34 changes: 13 additions & 21 deletions test/fixtures/src/github.com/example_cc1/example_cc1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -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")
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions test/integration/e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions test/integration/grpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down

0 comments on commit 9b8c6a0

Please sign in to comment.