diff --git a/fabric-client/lib/Channel.js b/fabric-client/lib/Channel.js index 6d5ba1b007..7836d0abcf 100755 --- a/fabric-client/lib/Channel.js +++ b/fabric-client/lib/Channel.js @@ -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()) { @@ -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); diff --git a/test/integration/events.js b/test/integration/events.js index 0f9d194b8c..04b70008c8 100644 --- a/test/integration/events.js +++ b/test/integration/events.js @@ -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) => { @@ -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 { diff --git a/test/unit/channel.js b/test/unit/channel.js index ae406aa6db..76056fe2dc 100644 --- a/test/unit/channel.js +++ b/test/unit/channel.js @@ -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();