Skip to content

Commit

Permalink
[FAB-2538] NodeSDK - endorsement error msg
Browse files Browse the repository at this point in the history
Have the NodeSDK return an error message when
there are no valid endorsements in the
sendTransaction() api call

Change-Id: I8c70b750e8e888eb8ca7090b4fd6a2c8ee5041a6
Signed-off-by: Bret Harrison <beharrison@nc.rr.com>
  • Loading branch information
harrisob committed Jul 14, 2017
1 parent 509b86a commit aed892f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
12 changes: 10 additions & 2 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -1414,7 +1414,6 @@ var Channel = class {

let proposalResponses = request.proposalResponses;
let chaincodeProposal = request.proposal;
let header = _commonProto.Header.decode(chaincodeProposal.getHeader());

// verify that we have an orderer configured
if(!this.getOrderers()) {
Expand All @@ -1434,9 +1433,18 @@ var Channel = class {
}
}
} else {
endorsements.push(proposalResponse.endorsement);
if (proposalResponse && proposalResponse.response && proposalResponse.response.status === 200) {
endorsements.push(proposalResponse.endorsement);
}
}

if(endorsements.length < 1) {
logger.error('sendTransaction - no valid endorsements found');
return Promise.reject(new Error('no valid endorsements found'));
}

let header = _commonProto.Header.decode(chaincodeProposal.getHeader());

var chaincodeEndorsedAction = new _transProto.ChaincodeEndorsedAction();
chaincodeEndorsedAction.setProposalResponsePayload(proposalResponse.payload);
chaincodeEndorsedAction.setEndorsements(endorsements);
Expand Down
3 changes: 2 additions & 1 deletion test/integration/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
request = eputil.createRequest(client, channel, the_user, chaincode_id, targets, '', '');
request.chaincodePath = 'github.com/events_cc';
request.chaincodeVersion = chaincode_version;
Client.setConfigSetting('request-timeout', 60000);

return client.installChaincode(request);
}).then((results) => {
Expand All @@ -216,7 +217,7 @@ test('Test chaincode instantiate with event, transaction invocation with chainco
}).then((results) => {
if ( eputil.checkProposal(results)) {
t.pass('Successfully endorsed the instantiate chaincode proposal');
var tmo = 50000;
var tmo = 60000;
return Promise.all([eputil.registerTxEvent(eh, request.txId.getTransactionID().toString(), tmo),
eputil.sendTransaction(channel, results)]);
} else {
Expand Down
17 changes: 16 additions & 1 deletion test/unit/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,22 @@ test('\n\n ** Channel sendTransaction() tests **\n\n', function (t) {
}
});

Promise.all([p1, p2, p3])
var p4 = _channel.sendTransaction({
proposal: 'blah',
proposalResponses: {response : { status : 500}},
header: 'blah'
})
.then(function () {
t.fail('Should not have been able to resolve the promise because of missing endorsement');
}, function (err) {
if (err.message.indexOf('no valid endorsements found') >= 0) {
t.pass('Successfully caught missing endorsement error');
} else {
t.fail('Failed to catch the missing endorsement error. Error: ' + err.stack ? err.stack : err);
}
});

Promise.all([p1, p2, p3, p4])
.then(
function (data) {
t.end();
Expand Down

0 comments on commit aed892f

Please sign in to comment.