Skip to content

Commit

Permalink
FABN-1060: Handle error responses in comparison
Browse files Browse the repository at this point in the history
Proposal responses returned from Channel.sendTransactionProposal()
can be any of: ProposalResponse, Error, or Error augmented with
response element of a ProposalResponse. Changing
Channel.compareProposalResponseResults() so that it can handle any
responses returned by Channel.sendTransactionProposal() without
error. Where any of the responses are not good (i.e. instances of
Error), compareProposalResponseResults() will return false, since
they don't contain valid write sets.

Similar change to Channel.verifyProposalResponse() to return false
for error responses.

If client code wants to compare only the successful proposal
responses, they can do so with:

const goodResponses = responses.filter((response) => !(response instanceof Error));
channel.compareProposalResponseResults(goodResponses);

Change-Id: Id1af8b3c5a1cb51eb2f4e9b50897671634848a8a
Signed-off-by: Mark S. Lewis <mark_lewis@uk.ibm.com>
(cherry picked from commit ab1e371)
  • Loading branch information
bestbeforetoday authored and harrisob committed Dec 28, 2018
1 parent 050f250 commit ea92a09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fabric-client/lib/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3320,6 +3320,9 @@ const Channel = class {
if (!proposal_response) {
throw new Error('Missing proposal response');
}
if (proposal_response instanceof Error) {
return false;
}
if (!proposal_response.endorsement) {
throw new Error('Parameter must be a ProposalResponse Object');
}
Expand Down Expand Up @@ -3389,6 +3392,10 @@ const Channel = class {
throw new Error('proposal_responses is empty');
}

if (proposal_responses.some((response) => response instanceof Error)) {
return false;
}

const first_one = _getProposalResponseResults(proposal_responses[0]);
for (let i = 1; i < proposal_responses.length; i++) {
const next_one = _getProposalResponseResults(proposal_responses[i]);
Expand Down
13 changes: 13 additions & 0 deletions fabric-client/test/Channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,13 @@ describe('Channel', () => {
const result = channel.compareProposalResponseResults([proposalResponse1, proposalResponse2]);
expect(result).to.be.false;
});

it('returns false if any proposal responses are Error objects', () => {
const proposalResponse1 = createProposalResponse('foo');
const proposalResponse2 = new Error('bah');
const result = channel.compareProposalResponseResults([proposalResponse1, proposalResponse2]);
expect(result).to.be.false;
});
});

describe('#generateUnsignedProposal', () => {
Expand Down Expand Up @@ -760,6 +767,12 @@ describe('Channel', () => {
const result = channel.verifyProposalResponse(proposalResponse);
expect(result).to.be.true;
});

it('returns false if the proposal response is an error', () => {
const proposalResponse = new Error('sadface');
const result = channel.verifyProposalResponse(proposalResponse);
expect(result).to.be.false;
});
});

describe('#generateUnsignedTransaction', () => {
Expand Down

0 comments on commit ea92a09

Please sign in to comment.