Skip to content

Commit 52f2c8b

Browse files
[FAB-11485] Fixing empty proposal handling
Fixing empty proposal handling in ChaincodeMessage while creating ChaincodeStubImpl Change-Id: I13110f6b2e001defe8b2f74af73a11100df3a388 Signed-off-by: gennady <gennady@il.ibm.com>
1 parent 2b35a46 commit 52f2c8b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/ChaincodeStubImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class ChaincodeStubImpl implements ChaincodeStub {
6161
this.handler = handler;
6262
this.args = Collections.unmodifiableList(args);
6363
this.signedProposal = signedProposal;
64-
if(this.signedProposal == null) {
64+
if(this.signedProposal == null || this.signedProposal.getProposalBytes().isEmpty()) {
6565
this.creator = null;
6666
this.txTimestamp = null;
6767
this.transientMap = Collections.emptyMap();

fabric-chaincode-shim/src/test/java/org/hyperledger/fabric/shim/impl/ChaincodeStubImplTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,13 @@ public void testGetSignedProposal() {
351351
assertThat(stub.getSignedProposal(), is(signedProposal));
352352
}
353353

354+
@Test
355+
public void testGetSignedProposalWithEmptyProposal() {
356+
final SignedProposal signedProposal = SignedProposal.newBuilder().setProposalBytes(ByteString.EMPTY).build();
357+
final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txId", handler, Collections.emptyList(), signedProposal);
358+
assertThat(stub.getSignedProposal(), is(signedProposal));
359+
}
360+
354361
@Test
355362
public void testGetTxTimestamp() {
356363
final Instant instant = Instant.now();
@@ -377,6 +384,13 @@ public void testGetTxTimestampNullSignedProposal() {
377384
assertThat(stub.getTxTimestamp(), is(nullValue()));
378385
}
379386

387+
@Test
388+
public void testGetTxTimestampEmptySignedProposal() {
389+
final SignedProposal signedProposal = SignedProposal.newBuilder().setProposalBytes(ByteString.EMPTY).build();
390+
final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal);
391+
assertThat(stub.getTxTimestamp(), is(nullValue()));
392+
}
393+
380394
@Test
381395
public void testGetCreator() {
382396
final Instant instant = Instant.now();
@@ -453,4 +467,10 @@ public void testGetBinding() {
453467
assertThat(stub.getBinding(), is(expectedDigest));
454468
}
455469

470+
@Test
471+
public void testGetBindingEmptyProposal() {
472+
final SignedProposal signedProposal = SignedProposal.newBuilder().setProposalBytes(ByteString.EMPTY).build();
473+
final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal);
474+
assertThat(stub.getBinding(), is((byte[])null));
475+
}
456476
}

0 commit comments

Comments
 (0)