@Test public void testGetTransient() { final SignedProposal signedProposal = SignedProposal.newBuilder() .setProposalBytes(Proposal.newBuilder() .setHeader(Header.newBuilder() .setChannelHeader(ChannelHeader.newBuilder() .setType(ENDORSER_TRANSACTION_VALUE) .setTimestamp(Timestamp.getDefaultInstance()) .build().toByteString() ) .build().toByteString() ) .setPayload(ChaincodeProposalPayload.newBuilder() .putTransientMap("key0", ByteString.copyFromUtf8("value0")) .putTransientMap("key1", ByteString.copyFromUtf8("value1")) .build().toByteString() ) .build().toByteString() ).build(); final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal); assertThat(stub.getTransient(), allOf( hasEntry("key0", "value0".getBytes(UTF_8)), hasEntry("key1", "value1".getBytes(UTF_8)) )); }
@Test public void testGetCreator() { final Instant instant = Instant.now(); final byte[] creator = "CREATOR".getBytes(UTF_8); final Timestamp timestamp = Timestamp.newBuilder().setSeconds(instant.getEpochSecond()).setNanos(instant.getNano()).build(); final SignedProposal signedProposal = SignedProposal.newBuilder() .setProposalBytes(Proposal.newBuilder() .setHeader(Header.newBuilder() .setChannelHeader(ChannelHeader.newBuilder() .setType(ENDORSER_TRANSACTION_VALUE) .setTimestamp(timestamp) .build().toByteString() ) .setSignatureHeader(SignatureHeader.newBuilder() .setCreator(ByteString.copyFrom(creator)) .build().toByteString() ) .build().toByteString() ) .build().toByteString() ).build(); final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal); assertThat(stub.getCreator(), is(creator)); }
@Test public void testGetTxTimestamp() { final Instant instant = Instant.now(); final Timestamp timestamp = Timestamp.newBuilder().setSeconds(instant.getEpochSecond()).setNanos(instant.getNano()).build(); final SignedProposal signedProposal = SignedProposal.newBuilder() .setProposalBytes(Proposal.newBuilder() .setHeader(Header.newBuilder() .setChannelHeader(ChannelHeader.newBuilder() .setType(ENDORSER_TRANSACTION_VALUE) .setTimestamp(timestamp) .build().toByteString() ) .build().toByteString() ) .build().toByteString() ).build(); final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal); assertThat(stub.getTxTimestamp(), is(instant)); }
@Test public void testGetBinding() { final byte[] expectedDigest = DatatypeConverter.parseHexBinary("5093dd4f4277e964da8f4afbde0a9674d17f2a6a5961f0670fc21ae9b67f2983"); final SignedProposal signedProposal = SignedProposal.newBuilder() .setProposalBytes(Proposal.newBuilder() .setHeader(Header.newBuilder() .setChannelHeader(ChannelHeader.newBuilder() .setType(ENDORSER_TRANSACTION_VALUE) .setTimestamp(Timestamp.getDefaultInstance()) .setEpoch(10) .build().toByteString() ) .setSignatureHeader(SignatureHeader.newBuilder() .setNonce(ByteString.copyFromUtf8("nonce")) .setCreator(ByteString.copyFromUtf8("creator")) .build().toByteString() ) .build().toByteString() ) .build().toByteString() ).build(); final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txid", handler, new ArrayList<>(), signedProposal); assertThat(stub.getBinding(), is(expectedDigest)); }
@Test public void testGetSignedProposal() { final SignedProposal signedProposal = SignedProposal.newBuilder() .setProposalBytes(Proposal.newBuilder() .setHeader(Header.newBuilder() .setChannelHeader(ChannelHeader.newBuilder() .setType(ENDORSER_TRANSACTION_VALUE) .setTimestamp(Timestamp.getDefaultInstance()) .build().toByteString() ) .build().toByteString() ) .build().toByteString() ).build(); final ChaincodeStubImpl stub = new ChaincodeStubImpl("myc", "txId", handler, Collections.emptyList(), signedProposal); assertThat(stub.getSignedProposal(), is(signedProposal)); }
public Builder mergeFrom(org.hyperledger.fabric.protos.peer.ProposalPackage.Proposal other) { if (other == org.hyperledger.fabric.protos.peer.ProposalPackage.Proposal.getDefaultInstance()) return this; if (other.getHeader() != com.google.protobuf.ByteString.EMPTY) { setHeader(other.getHeader()); } if (other.getPayload() != com.google.protobuf.ByteString.EMPTY) { setPayload(other.getPayload()); } if (other.getExtension() != com.google.protobuf.ByteString.EMPTY) { setExtension(other.getExtension()); } onChanged(); return this; }