use of com.hedera.hashgraph.sdk.proto.Response in project hedera-mirror-node by hashgraph.
the class TransactionPublisherTest method validationRecovers.
@Test
@Timeout(3)
void validationRecovers() {
// Initialize publisher internals with first transaction
var request = request().build();
cryptoServiceStub.addTransactions(Mono.just(response(OK)));
transactionPublisher.publish(request).as(StepVerifier::create).expectNextCount(1L).expectComplete().verify(Duration.ofSeconds(1L));
var scenario = request.getScenario();
assertThat(scenario.getCount()).isEqualTo(1);
assertThat(scenario.getErrors()).isEmpty();
// Validate node as down manually
NodeProperties nodeProperties = monitorProperties.getNodes().iterator().next();
cryptoServiceStub.addQueries(Mono.just(receipt(ACCOUNT_DELETED)));
cryptoServiceStub.addTransactions(Mono.just(response(OK)));
assertThat(transactionPublisher.validateNode(nodeProperties)).isFalse();
request = request().build();
transactionPublisher.publish(request).as(StepVerifier::create).expectErrorSatisfies(t -> assertThat(t).isInstanceOf(PublishException.class).hasMessageContaining("No valid nodes available").hasCauseInstanceOf(IllegalArgumentException.class)).verify(Duration.ofSeconds(1L));
scenario = request.getScenario();
assertThat(scenario.getCount()).isZero();
assertThat(scenario.getErrors()).containsOnly(Map.entry(IllegalArgumentException.class.getSimpleName(), 1));
// Node recovers
cryptoServiceStub.addQueries(Mono.just(receipt(SUCCESS)));
cryptoServiceStub.addTransactions(Mono.just(response(OK)));
assertThat(transactionPublisher.validateNode(nodeProperties)).isTrue();
request = request().build();
cryptoServiceStub.addTransactions(Mono.just(response(OK)));
transactionPublisher.publish(request).as(StepVerifier::create).expectNextCount(1L).expectComplete().verify(Duration.ofSeconds(1L));
scenario = request.getScenario();
assertThat(scenario.getCount()).isEqualTo(1);
assertThat(scenario.getErrors()).isEmpty();
}
use of com.hedera.hashgraph.sdk.proto.Response in project hedera-sdk-java by hashgraph.
the class TransactionRecordTest method toFromBytes.
@Test
@DisplayName("using toBytes and fromBytes will produce the correct response")
void toFromBytes() throws InvalidProtocolBufferException {
var hbarTransfer = AccountAmount.newBuilder().setAccountID(AccountId.fromString("0.0.5005").toProtobuf()).setAmount(100_000);
var hbarTransferList = TransferList.newBuilder();
hbarTransferList.addAccountAmounts(hbarTransfer);
var tokenTransfer = AccountAmount.newBuilder().setAccountID(AccountId.fromString("0.0.5006").toProtobuf()).setAmount(100_000);
var tokenTransferList = TokenTransferList.newBuilder().setToken(TokenId.fromString("0.0.5007").toProtobuf());
tokenTransferList.addTransfers(tokenTransfer);
var nftTransfer = NftTransfer.newBuilder().setSenderAccountID(AccountId.fromString("0.0.5006").toProtobuf()).setReceiverAccountID(AccountId.fromString("0.0.5007").toProtobuf()).setSerialNumber(888);
var nftTransferList = TokenTransferList.newBuilder();
nftTransferList.addNftTransfers(nftTransfer);
Response response = Response.newBuilder().setTransactionGetRecord(TransactionGetRecordResponse.newBuilder().setTransactionRecord(com.hedera.hashgraph.sdk.proto.TransactionRecord.newBuilder().setReceipt(com.hedera.hashgraph.sdk.proto.TransactionReceipt.newBuilder().build()).setTransactionHash(ByteString.copyFrom("hello", StandardCharsets.UTF_8)).setConsensusTimestamp(InstantConverter.toProtobuf(exampleInstant)).setTransactionID(TransactionId.withValidStart(AccountId.fromString("0.0.5006"), exampleInstant).toProtobuf()).setMemo("hola").setTransactionFee(100_000).setTransferList(hbarTransferList).addTokenTransferLists(tokenTransferList).addTokenTransferLists(nftTransferList).setContractCallResult(ContractFunctionResult.newBuilder().addLogInfo(ContractLoginfo.newBuilder().addTopic(ByteString.copyFrom("aloha", StandardCharsets.UTF_8)).setContractID(ContractId.fromString("0.0.5007").toProtobuf()).setBloom(ByteString.copyFrom("bonjour", StandardCharsets.UTF_8))).setContractID(ContractId.fromString("0.0.5008").toProtobuf()).setContractCallResult(ByteString.copyFrom("hello again", StandardCharsets.UTF_8)).setBloom(ByteString.copyFrom("hola otra vez", StandardCharsets.UTF_8)).setGasUsed(100_000).setErrorMessage("hello x3")))).build();
TransactionRecord record = TransactionRecord.fromProtobuf(response.getTransactionGetRecord().getTransactionRecord());
assertNotNull(record);
assertNotNull(record.toBytes());
byte[] recordBytes = record.toBytes();
TransactionRecord newRecord = TransactionRecord.fromBytes(recordBytes);
assertEquals(record.toString(), newRecord.toString());
}
Aggregations