Skip to content

Commit

Permalink
[FAB-5377] response with payload in fabric-sdk-node
Browse files Browse the repository at this point in the history
Update test for payload with response

Change-Id: Ia1e6c9cc0d63d0aee586dd5b5dfe77f186a53122
Signed-off-by: Zhao Chaoyi <[email protected]>
  • Loading branch information
Zhao Chaoyi committed Oct 30, 2017
1 parent 2d8be9d commit 7e7d0f0
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
11 changes: 7 additions & 4 deletions test/fixtures/src/github.com/example_cc/example_cc.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ 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 All @@ -50,7 +54,7 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
if err != nil {
return shim.Error("Expecting integer value for asset holding")
}
logger.Info("Aval = %d, Bval = %d\n", Aval, Bval)
logger.Infof("Aval = %d, Bval = %d\n", Aval, Bval)

// Write the state to the ledger
err = stub.PutState(A, []byte(strconv.Itoa(Aval)))
Expand All @@ -64,8 +68,6 @@ func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
}

return shim.Success(nil)


}

// Transaction makes payment of X units from A to B
Expand All @@ -83,6 +85,7 @@ func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
// queries an entity state
return t.query(stub, args)
}

if function == "move" {
// Deletes an entity from its state
return t.move(stub, args)
Expand Down Expand Up @@ -146,7 +149,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
return shim.Error(err.Error())
}

return shim.Success(nil);
return shim.Success([]byte("move succeed"))
}

// Deletes an entity from state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (t *SimpleChaincode) move(stub shim.ChaincodeStubInterface, args []string)
return shim.Error(err.Error())
}

return shim.Success(nil);
return shim.Success([]byte("move succeed"))
}

// Deletes an entity from state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
pb "github.com/hyperledger/fabric/protos/peer"
)

var logger = shim.NewLogger("example_cc1")
var logger = shim.NewLogger("example_cc2")

// SimpleChaincode example simple Chaincode implementation
type SimpleChaincode struct {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/src/node_cc/example_cc/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ var Chaincode = class {
try {
await stub.putState(A, Buffer.from(Aval.toString()));
await stub.putState(B, Buffer.from(Bval.toString()));
return shim.success();
return shim.success(Buffer.from('move succeed'));
} catch (e) {
return shim.error(e);
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/src/node_cc/example_cc1/chaincode.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var Chaincode = class {
}

async Invoke(stub) {
logger.info('########### example_cc0 Invoke ###########');
logger.info('########### example_cc1 Invoke ###########');
let ret = stub.getFunctionAndParameters();
let fcn = ret.fcn;
let args = ret.params;
Expand Down Expand Up @@ -106,7 +106,7 @@ var Chaincode = class {
try {
await stub.putState(A, Buffer.from(Aval.toString()));
await stub.putState(B, Buffer.from(Bval.toString()));
return shim.success();
return shim.success(Buffer.from('move succeed'));
} catch (e) {
return shim.error(e);
}
Expand Down
12 changes: 11 additions & 1 deletion test/integration/e2e/e2eUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,17 @@ function invokeChaincode(userOrg, version, chaincodeId, t, useStore){
t.pass('transaction proposal has response status of good');
one_good = channel.verifyProposalResponse(proposal_response);
if(one_good) {
t.pass(' transaction proposal signature and endorser are valid');
t.pass('transaction proposal signature and endorser are valid');
}

// check payload
let payload = proposal_response.response.payload.toString();
// 'move success' is the expected payload from 'move' invoke
if(payload === 'move succeed'){
t.pass('transaction proposal payloads are valid');
} else {
one_good = false;
t.fail('transaction proposal payloads are invalid');
}
} else {
t.fail('transaction proposal was bad');
Expand Down

0 comments on commit 7e7d0f0

Please sign in to comment.