Search in sources :

Example 6 with Timestamp

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

the class TokenUpdateTransactionHandlerTest 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.tokenUpdate().transactionBody(b -> b.getAutoRenewAccountBuilder().setAlias(alias)).build();
    var tokenId = EntityId.of(recordItem.getTransactionBody().getTokenUpdate().getToken());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(tokenId)).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 : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) Duration(com.hederahashgraph.api.proto.java.Duration) NftTransfer(com.hederahashgraph.api.proto.java.NftTransfer) EntityType(com.hedera.mirror.common.domain.entity.EntityType) TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) NftRepository(com.hedera.mirror.importer.repository.NftRepository) DomainUtils(com.hedera.mirror.common.util.DomainUtils) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) EntityIdEndec(com.hedera.mirror.common.domain.entity.EntityIdEndec) Range(com.google.common.collect.Range) Mockito.when(org.mockito.Mockito.when) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) 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) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) NftTransferId(com.hedera.mirror.common.domain.token.NftTransferId) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) 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 7 with Timestamp

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

the class ProtoBalanceFileReader method toFlux.

private Flux<AccountBalance> toFlux(StreamFileData streamFileData) {
    return Flux.defer(() -> {
        InputStream inputStream = streamFileData.getInputStream();
        ExtensionRegistryLite extensionRegistry = ExtensionRegistryLite.getEmptyRegistry();
        CodedInputStream input = CodedInputStream.newInstance(inputStream);
        AtomicLong consensusTimestamp = new AtomicLong(0L);
        UnknownFieldSet.Builder unknownFieldSet = UnknownFieldSet.newBuilder();
        return Flux.<AccountBalance>generate(sink -> {
            try {
                boolean done = false;
                while (!done) {
                    int tag = input.readTag();
                    switch(tag) {
                        case TAG_EOF:
                            done = true;
                            break;
                        case TAG_TIMESTAMP:
                            Timestamp timestamp = input.readMessage(Timestamp.parser(), extensionRegistry);
                            consensusTimestamp.set(DomainUtils.timestampInNanosMax(timestamp));
                            break;
                        case TAG_BALANCE:
                            Assert.state(consensusTimestamp.get() > 0, "Missing consensus timestamp)");
                            var ab = input.readMessage(SingleAccountBalances.parser(), extensionRegistry);
                            sink.next(toAccountBalance(consensusTimestamp.get(), ab));
                            return;
                        default:
                            log.warn("Unsupported tag: {}", tag);
                            done = !unknownFieldSet.mergeFieldFrom(tag, input);
                    }
                }
                Assert.state(consensusTimestamp.get() > 0, "Missing consensus timestamp)");
                sink.complete();
            } catch (IOException e) {
                sink.error(new StreamFileReaderException(e));
            } catch (IllegalStateException e) {
                sink.error(new InvalidStreamFileException(e));
            }
        }).doFinally(s -> IOUtils.closeQuietly(inputStream));
    });
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) AccountBalanceFile(com.hedera.mirror.common.domain.balance.AccountBalanceFile) AccountBalance(com.hedera.mirror.common.domain.balance.AccountBalance) ExtensionRegistryLite(com.google.protobuf.ExtensionRegistryLite) Named(javax.inject.Named) SingleAccountBalances(com.hedera.services.stream.proto.SingleAccountBalances) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) UnknownFieldSet(com.google.protobuf.UnknownFieldSet) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) DomainUtils(com.hedera.mirror.common.util.DomainUtils) IOException(java.io.IOException) Instant(java.time.Instant) TokenBalance(com.hedera.mirror.common.domain.balance.TokenBalance) Collectors(java.util.stream.Collectors) AtomicLong(java.util.concurrent.atomic.AtomicLong) IOUtils(org.apache.commons.io.IOUtils) Flux(reactor.core.publisher.Flux) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) List(java.util.List) CodedInputStream(com.google.protobuf.CodedInputStream) Log4j2(lombok.extern.log4j.Log4j2) DigestUtils(org.apache.commons.codec.digest.DigestUtils) InputStream(java.io.InputStream) Assert(org.springframework.util.Assert) StreamFileData(com.hedera.mirror.importer.domain.StreamFileData) InvalidStreamFileException(com.hedera.mirror.importer.exception.InvalidStreamFileException) CodedInputStream(com.google.protobuf.CodedInputStream) InputStream(java.io.InputStream) CodedInputStream(com.google.protobuf.CodedInputStream) ExtensionRegistryLite(com.google.protobuf.ExtensionRegistryLite) StreamFileReaderException(com.hedera.mirror.importer.exception.StreamFileReaderException) IOException(java.io.IOException) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) AtomicLong(java.util.concurrent.atomic.AtomicLong) UnknownFieldSet(com.google.protobuf.UnknownFieldSet)

Example 8 with Timestamp

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

the class ConsensusUpdateTopicTransactionHandler method doUpdateEntity.

@Override
protected void doUpdateEntity(Entity entity, RecordItem recordItem) {
    var transactionBody = recordItem.getTransactionBody().getConsensusUpdateTopic();
    if (transactionBody.hasAutoRenewAccount()) {
        getAccountId(transactionBody.getAutoRenewAccount()).map(EntityId::getId).ifPresent(entity::setAutoRenewAccountId);
    }
    if (transactionBody.hasAutoRenewPeriod()) {
        entity.setAutoRenewPeriod(transactionBody.getAutoRenewPeriod().getSeconds());
    }
    if (transactionBody.hasExpirationTime()) {
        Timestamp expirationTime = transactionBody.getExpirationTime();
        entity.setExpirationTimestamp(DomainUtils.timestampInNanosMax(expirationTime));
    }
    if (transactionBody.hasAdminKey()) {
        entity.setKey(transactionBody.getAdminKey().toByteArray());
    }
    if (transactionBody.hasMemo()) {
        entity.setMemo(transactionBody.getMemo().getValue());
    }
    if (transactionBody.hasSubmitKey()) {
        entity.setSubmitKey(transactionBody.getSubmitKey().toByteArray());
    }
    entityListener.onEntity(entity);
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp)

Example 9 with Timestamp

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

the class DomainUtilsTest method timeStampInNanosInvalid.

@Test
@DisplayName("converting illegal timestamp to nanos")
void timeStampInNanosInvalid() {
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(1568376750538L).setNanos(0).build();
    assertThrows(ArithmeticException.class, () -> {
        DomainUtils.timeStampInNanos(timestamp);
    });
}
Also used : Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 10 with Timestamp

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

the class DomainUtilsTest method timeStampInNanosTimeStamp.

@ParameterizedTest(name = "with seconds {0} and nanos {1}")
@CsvSource({ "1569936354, 901", "0, 901", "1569936354, 0", "0,0" })
void timeStampInNanosTimeStamp(long seconds, int nanos) {
    Timestamp timestamp = Timestamp.newBuilder().setSeconds(seconds).setNanos(nanos).build();
    Long timeStampInNanos = DomainUtils.timeStampInNanos(timestamp);
    assertThat(timeStampInNanos).isNotNull();
    Instant fromTimeStamp = Instant.ofEpochSecond(0, timeStampInNanos);
    assertAll(() -> assertEquals(timestamp.getSeconds(), fromTimeStamp.getEpochSecond()), () -> assertEquals(timestamp.getNanos(), fromTimeStamp.getNano()));
}
Also used : Instant(java.time.Instant) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Timestamp (com.hederahashgraph.api.proto.java.Timestamp)26 Test (org.junit.jupiter.api.Test)12 Instant (java.time.Instant)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 EntityId (com.hedera.mirror.common.domain.entity.EntityId)5 DomainUtils (com.hedera.mirror.common.util.DomainUtils)5 Consumer (java.util.function.Consumer)5 Range (com.google.common.collect.Range)4 Entity (com.hedera.mirror.common.domain.entity.Entity)4 EntityType (com.hedera.mirror.common.domain.entity.EntityType)4 ACCOUNT (com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT)4 NftTransferId (com.hedera.mirror.common.domain.token.NftTransferId)4 Transaction (com.hedera.mirror.common.domain.transaction.Transaction)4 AccountID (com.hederahashgraph.api.proto.java.AccountID)4 Duration (com.hederahashgraph.api.proto.java.Duration)4 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 AbstractEntity (com.hedera.mirror.common.domain.entity.AbstractEntity)3 EntityIdEndec (com.hedera.mirror.common.domain.entity.EntityIdEndec)3