Search in sources :

Example 76 with TransactionBody

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

the class TokenUpdateTransactionHandlerTest method updateTransactionWithAliasNotFoundAndPartialDataActionSkip.

@Test
void updateTransactionWithAliasNotFoundAndPartialDataActionSkip() {
    recordParserProperties.setPartialDataAction(PartialDataAction.SKIP);
    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));
    transactionHandler.updateTransaction(transaction, recordItem);
    assertTokenUpdate(timestamp, tokenId, Assertions::assertNull);
}
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) Assertions(org.junit.jupiter.api.Assertions) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 77 with TransactionBody

use of com.hederahashgraph.api.proto.java.TransactionBody 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 78 with TransactionBody

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

the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForUpdateTransaction.

private List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForUpdateTransaction(FieldDescriptor memoField, FieldDescriptor memoWrapperField, FieldDescriptor maxAutomaticTokenAssociationsField, FieldDescriptor receiverSigRequiredWrapperField) {
    TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
    Message innerBody = getInnerBody(body);
    List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
    if (receiverSigRequiredWrapperField != null) {
        innerBody = innerBody.toBuilder().setField(receiverSigRequiredWrapperField, UPDATED_RECEIVER_SIG_REQUIRED).build();
    }
    AbstractEntity expected = getExpectedUpdatedEntity();
    Message unchangedMemoInnerBody = innerBody;
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity without memo").expected(expected).recordItem(getRecordItem(body, unchangedMemoInnerBody)).build());
    Message updatedMemoInnerBody = innerBody;
    if (memoWrapperField != null) {
        // memo is of string type
        // non-empty string, expect memo set to non-empty string
        expected = getExpectedUpdatedEntity();
        expected.setMemo(UPDATED_MEMO);
        updatedMemoInnerBody = innerBody.toBuilder().setField(memoField, UPDATED_MEMO).build();
    }
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty String").expected(expected).recordItem(getRecordItem(body, updatedMemoInnerBody)).build());
    // memo is set through the StringValue field
    // there is always a StringValue field, either "memo" or "memoWrapper"
    FieldDescriptor field = memoWrapperField;
    if (field == null) {
        field = memoField;
    }
    expected = getExpectedUpdatedEntity();
    expected.setMemo("");
    Message clearedMemoInnerBody = innerBody.toBuilder().setField(field, StringValue.of("")).build();
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with empty StringValue memo, expect memo cleared").expected(expected).recordItem(getRecordItem(body, clearedMemoInnerBody)).build());
    // non-empty StringValue, expect memo in entity updated
    expected = getExpectedUpdatedEntity();
    expected.setMemo(UPDATED_MEMO);
    Message memoStringValueUpdatedInnerBody = innerBody.toBuilder().setField(field, StringValue.of(UPDATED_MEMO)).build();
    if (receiverSigRequiredWrapperField != null && expected instanceof Entity) {
        ((Entity) expected).setReceiverSigRequired(UPDATED_RECEIVER_SIG_REQUIRED.getValue());
    }
    testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with non-empty StringValue memo, expect memo updated").expected(expected).recordItem(getRecordItem(body, memoStringValueUpdatedInnerBody)).build());
    if (maxAutomaticTokenAssociationsField != null) {
        expected = getExpectedUpdatedEntity();
        expected.setMaxAutomaticTokenAssociations(500);
        if (expected instanceof Entity) {
            ((Entity) expected).setReceiverSigRequired(true);
        }
        Message updatedInnerBody = innerBody.toBuilder().setField(maxAutomaticTokenAssociationsField, Int32Value.of(500)).build();
        testSpecs.add(UpdateEntityTestSpec.builder().description("update entity with max_automatic_token_associations").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    }
    return testSpecs;
}
Also used : AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) LinkedList(java.util.LinkedList) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 79 with TransactionBody

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

the class AbstractTransactionHandlerTest method getUpdateEntityTestSpecsForCreateTransaction.

protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForCreateTransaction(FieldDescriptor memoField) {
    TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
    Message innerBody = getInnerBody(body);
    List<UpdateEntityTestSpec> testSpecs = new LinkedList<>();
    AbstractEntity expected = getExpectedUpdatedEntity();
    // Proto defaults to empty string
    expected.setMemo("");
    // no memo set, expect empty memo
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity without memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, innerBody)).build());
    expected = getExpectedUpdatedEntity();
    expected.setMemo("");
    // memo set to empty string, expect empty memo
    Message updatedInnerBody = innerBody.toBuilder().setField(memoField, "").build();
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with empty memo, expect empty memo").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    // memo set to non-empty string, expect memo set
    expected = getExpectedUpdatedEntity();
    expected.setMemo(DEFAULT_MEMO);
    updatedInnerBody = innerBody.toBuilder().setField(memoField, DEFAULT_MEMO).build();
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with non-empty memo, expect memo set").expected(expected).recordItem(getRecordItem(body, updatedInnerBody)).build());
    return testSpecs;
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) LinkedList(java.util.LinkedList)

Example 80 with TransactionBody

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

the class CryptoUpdateTransactionHandlerTest method updateTransactionStakedNodeId.

@Test
void updateTransactionStakedNodeId() {
    RecordItem withStakedNodeIdSet = recordItemBuilder.cryptoUpdate().transactionBody(body -> body.setStakedNodeId(1L)).build();
    setupForCrytoUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Entity::getStakedNodeId).returns(-1L, Entity::getStakedAccountId).returns(true, Entity::isDeclineReward).extracting(Entity::getStakePeriodStart).isNotNull());
}
Also used : CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) EntityType(com.hedera.mirror.common.domain.entity.EntityType) 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) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Assertions(org.junit.jupiter.api.Assertions) ACCOUNT(com.hedera.mirror.common.domain.entity.EntityType.ACCOUNT) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) Entity(com.hedera.mirror.common.domain.entity.Entity) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test)

Aggregations

TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)145 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)106 Test (org.junit.jupiter.api.Test)100 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)96 Transaction (com.hederahashgraph.api.proto.java.Transaction)91 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)91 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)34 AccountID (com.hederahashgraph.api.proto.java.AccountID)32 EnumSource (org.junit.jupiter.params.provider.EnumSource)32 EntityId (com.hedera.mirror.common.domain.entity.EntityId)31 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)31 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)31 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)31 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)31 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)31 Entity (com.hedera.mirror.common.domain.entity.Entity)29 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)29 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 Contract (com.hedera.mirror.common.domain.contract.Contract)27