Search in sources :

Example 6 with Response

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();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) CryptoServiceGrpc(com.hedera.hashgraph.sdk.proto.CryptoServiceGrpc) NodeProperties(com.hedera.mirror.monitor.NodeProperties) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) OperatorProperties(com.hedera.mirror.monitor.OperatorProperties) OK(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.OK) TransactionType(com.hedera.mirror.monitor.publish.transaction.TransactionType) TimeoutException(java.util.concurrent.TimeoutException) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) ResponseCodeEnum(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum) Query(com.hedera.hashgraph.sdk.proto.Query) Transaction(com.hedera.hashgraph.sdk.proto.Transaction) StreamObserver(io.grpc.stub.StreamObserver) ResponseHeader(com.hedera.hashgraph.sdk.proto.ResponseHeader) Response(com.hedera.hashgraph.sdk.proto.Response) Duration(java.time.Duration) Map(java.util.Map) TransactionReceipt(com.hedera.hashgraph.sdk.proto.TransactionReceipt) TransactionRecord(com.hedera.hashgraph.sdk.proto.TransactionRecord) Server(io.grpc.Server) ACCOUNT_DELETED(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.ACCOUNT_DELETED) SUCCESS(com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.SUCCESS) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Set(java.util.Set) IOException(java.io.IOException) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) TransactionGetRecordResponse(com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse) Test(org.junit.jupiter.api.Test) TransactionGetReceiptResponse(com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse) AfterEach(org.junit.jupiter.api.AfterEach) TransactionResponse(com.hedera.hashgraph.sdk.proto.TransactionResponse) Data(lombok.Data) Log4j2(lombok.extern.log4j.Log4j2) PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) Queue(java.util.Queue) Timeout(org.junit.jupiter.api.Timeout) MonitorProperties(com.hedera.mirror.monitor.MonitorProperties) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) NodeProperties(com.hedera.mirror.monitor.NodeProperties) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test) Timeout(org.junit.jupiter.api.Timeout)

Example 7 with Response

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());
}
Also used : TransactionGetRecordResponse(com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse) Response(com.hedera.hashgraph.sdk.proto.Response) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

Response (com.hedera.hashgraph.sdk.proto.Response)7 Test (org.junit.jupiter.api.Test)7 ResponseCodeEnum (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum)5 ResponseHeader (com.hedera.hashgraph.sdk.proto.ResponseHeader)5 TransactionGetRecordResponse (com.hedera.hashgraph.sdk.proto.TransactionGetRecordResponse)5 Arrays (java.util.Arrays)5 TimeoutException (java.util.concurrent.TimeoutException)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)4 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)4 TransferTransaction (com.hedera.hashgraph.sdk.TransferTransaction)4 CryptoServiceGrpc (com.hedera.hashgraph.sdk.proto.CryptoServiceGrpc)4 Query (com.hedera.hashgraph.sdk.proto.Query)4 ACCOUNT_DELETED (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.ACCOUNT_DELETED)4 OK (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.OK)4 SUCCESS (com.hedera.hashgraph.sdk.proto.ResponseCodeEnum.SUCCESS)4 Transaction (com.hedera.hashgraph.sdk.proto.Transaction)4 TransactionGetReceiptResponse (com.hedera.hashgraph.sdk.proto.TransactionGetReceiptResponse)4 TransactionReceipt (com.hedera.hashgraph.sdk.proto.TransactionReceipt)4