Search in sources :

Example 6 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-services by hashgraph.

the class HapiTopicDelete method resolveTopicId.

private TopicID resolveTopicId(HapiApiSpec spec) {
    if (topicFn.isPresent()) {
        TopicID topicID = topicFn.get().apply(spec);
        topic = Optional.of(HapiPropertySource.asTopicString(topicID));
        return topicID;
    }
    if (topic.isPresent()) {
        return asTopicId(topic.get(), spec);
    }
    return TopicID.getDefaultInstance();
}
Also used : TopicID(com.hederahashgraph.api.proto.java.TopicID)

Example 7 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-mirror-node by hashgraph.

the class ConsensusUpdateTopicTransactionHandlerTest method updateTransactionThrowsWithAliasNotFound.

@ParameterizedTest(name = "{0}")
@EnumSource(value = PartialDataAction.class, names = { "DEFAULT", "ERROR" })
void updateTransactionThrowsWithAliasNotFound(PartialDataAction partialDataAction) {
    // given
    recordParserProperties.setPartialDataAction(partialDataAction);
    var alias = DomainUtils.fromBytes(domainBuilder.key());
    var recordItem = recordItemBuilder.consensusUpdateTopic().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
    var topicId = EntityId.of(recordItem.getTransactionBody().getConsensusUpdateTopic().getTopicID());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(topicId)).get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", ACCOUNT));
    // when, then
    assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
Also used : TOPIC(com.hedera.mirror.common.domain.entity.EntityType.TOPIC) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TopicID(com.hederahashgraph.api.proto.java.TopicID) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) ConsensusUpdateTopicTransactionBody(com.hederahashgraph.api.proto.java.ConsensusUpdateTopicTransactionBody) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Entity(com.hedera.mirror.common.domain.entity.Entity) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-mirror-node by hashgraph.

the class PubSubRecordItemListenerTest method testPubSubMessageNullEntityId.

@Test
void testPubSubMessageNullEntityId() throws Exception {
    // given
    byte[] message = new byte[] { 'a', 'b', 'c' };
    TopicID topicID = TopicID.newBuilder().setTopicNum(10L).build();
    EntityId topicIdEntity = EntityId.of(topicID);
    ConsensusSubmitMessageTransactionBody submitMessage = ConsensusSubmitMessageTransactionBody.newBuilder().setMessage(ByteString.copyFrom(message)).setTopicID(topicID).build();
    Transaction transaction = buildTransaction(builder -> builder.setConsensusSubmitMessage(submitMessage));
    // when
    doReturn(null).when(transactionHandler).getEntity(any());
    pubSubRecordItemListener.onItem(new RecordItem(transaction, DEFAULT_RECORD));
    // then
    var pubSubMessage = assertPubSubMessage(buildPubSubTransaction(transaction), 1);
    assertThat(pubSubMessage.getEntity()).isEqualTo(null);
    assertThat(pubSubMessage.getNonFeeTransfers()).isNull();
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TopicID(com.hederahashgraph.api.proto.java.TopicID) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Example 9 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-mirror-node by hashgraph.

the class ConsensusControllerTest method missingTopicID.

@Test
void missingTopicID() {
    ConsensusTopicQuery query = ConsensusTopicQuery.newBuilder().build();
    grpcConsensusService.subscribeTopic(Mono.just(query)).as(StepVerifier::create).expectErrorSatisfies(t -> assertException(t, Status.Code.INVALID_ARGUMENT, "topicId: must not be null")).verify(Duration.ofMillis(500));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TopicID(com.hederahashgraph.api.proto.java.TopicID) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) ConsensusServiceGrpc(com.hedera.mirror.api.proto.ConsensusServiceGrpc) Duration(java.time.Duration) Status(io.grpc.Status) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) GrpcClient(net.devh.boot.grpc.client.inject.GrpcClient) ReactorConsensusServiceGrpc(com.hedera.mirror.api.proto.ReactorConsensusServiceGrpc) ConsensusTopicResponse(com.hedera.mirror.api.proto.ConsensusTopicResponse) ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) Resource(javax.annotation.Resource) ListenerProperties(com.hedera.mirror.grpc.listener.ListenerProperties) Mono(reactor.core.publisher.Mono) Instant(java.time.Instant) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.jupiter.api.Test) Flux(reactor.core.publisher.Flux) AfterEach(org.junit.jupiter.api.AfterEach) Log4j2(lombok.extern.log4j.Log4j2) TopicMessage(com.hedera.mirror.grpc.domain.TopicMessage) DomainBuilder(com.hedera.mirror.grpc.domain.DomainBuilder) ConsensusTopicQuery(com.hedera.mirror.api.proto.ConsensusTopicQuery) StepVerifier(reactor.test.StepVerifier) GrpcIntegrationTest(com.hedera.mirror.grpc.GrpcIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 10 with TopicID

use of com.hederahashgraph.api.proto.java.TopicID in project hedera-services by hashgraph.

the class TxnReceipt method fromGrpc.

/* ---  Helpers --- */
public static TxnReceipt fromGrpc(TransactionReceipt grpc) {
    final var effRates = grpc.hasExchangeRate() ? ExchangeRates.fromGrpc(grpc.getExchangeRate()) : null;
    String status = grpc.getStatus() != null ? grpc.getStatus().name() : null;
    EntityId accountId = grpc.hasAccountID() ? EntityId.fromGrpcAccountId(grpc.getAccountID()) : null;
    EntityId jFileID = grpc.hasFileID() ? EntityId.fromGrpcFileId(grpc.getFileID()) : null;
    EntityId jContractID = grpc.hasContractID() ? EntityId.fromGrpcContractId(grpc.getContractID()) : null;
    EntityId topicId = grpc.hasTopicID() ? EntityId.fromGrpcTopicId(grpc.getTopicID()) : null;
    EntityId tokenId = grpc.hasTokenID() ? EntityId.fromGrpcTokenId(grpc.getTokenID()) : null;
    EntityId scheduleId = grpc.hasScheduleID() ? EntityId.fromGrpcScheduleId(grpc.getScheduleID()) : null;
    long runningHashVersion = Math.max(MISSING_RUNNING_HASH_VERSION, grpc.getTopicRunningHashVersion());
    long newTotalSupply = grpc.getNewTotalSupply();
    long[] serialNumbers = grpc.getSerialNumbersList().stream().mapToLong(l -> l).toArray();
    TxnId scheduledTxnId = grpc.hasScheduledTransactionID() ? TxnId.fromGrpc(grpc.getScheduledTransactionID()) : MISSING_SCHEDULED_TXN_ID;
    return TxnReceipt.newBuilder().setStatus(status).setAccountId(accountId).setFileId(jFileID).setContractId(jContractID).setTokenId(tokenId).setScheduleId(scheduleId).setExchangeRates(effRates).setTopicId(topicId).setTopicSequenceNumber(grpc.getTopicSequenceNumber()).setTopicRunningHash(grpc.getTopicRunningHash().toByteArray()).setRunningHashVersion(runningHashVersion).setNewTotalSupply(newTotalSupply).setScheduledTxnId(scheduledTxnId).setSerialNumbers(serialNumbers).build();
}
Also used : EntityId(com.hedera.services.state.submerkle.EntityId) TopicID(com.hederahashgraph.api.proto.java.TopicID) Arrays(java.util.Arrays) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) SerializableDataInputStream(com.swirlds.common.io.SerializableDataInputStream) EntityId(com.hedera.services.state.submerkle.EntityId) DomainSerdes(com.hedera.services.state.serdes.DomainSerdes) MoreObjects(com.google.common.base.MoreObjects) IOException(java.io.IOException) SelfSerializable(com.swirlds.common.io.SelfSerializable) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) SerializableDataOutputStream(com.swirlds.common.io.SerializableDataOutputStream) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Objects(java.util.Objects) RequestBuilder(com.hederahashgraph.builder.RequestBuilder) REVERTED_SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.REVERTED_SUCCESS) CommonUtils(com.swirlds.common.CommonUtils) TxnId(com.hedera.services.state.submerkle.TxnId) ExchangeRates(com.hedera.services.state.submerkle.ExchangeRates) CommonUtils.getNormalisedStringFromBytes(com.swirlds.common.CommonUtils.getNormalisedStringFromBytes) TxnId(com.hedera.services.state.submerkle.TxnId) ByteString(com.google.protobuf.ByteString)

Aggregations

TopicID (com.hederahashgraph.api.proto.java.TopicID)16 Test (org.junit.jupiter.api.Test)9 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)5 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 Transaction (com.hederahashgraph.api.proto.java.Transaction)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 Consumer (java.util.function.Consumer)4 MoreObjects (com.google.common.base.MoreObjects)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)3 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 ConsensusSubmitMessageTransactionBody (com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Range (com.google.common.collect.Range)2 ByteString (com.google.protobuf.ByteString)2 Entity (com.hedera.mirror.common.domain.entity.Entity)2 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)2 EntityType (com.hedera.mirror.common.domain.entity.EntityType)2 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)2 TOPIC (com.hedera.mirror.common.domain.entity.EntityType.TOPIC)2