Search in sources :

Example 71 with TransactionBody

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

the class ContractUpdateTransactionHandlerTest method updateTransactionStakedAccountId.

@Test
void updateTransactionStakedAccountId() {
    AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
    RecordItem withStakedNodeIdSet = recordItemBuilder.contractUpdate().transactionBody(body -> body.clear().setStakedAccountId(accountId)).build();
    setupForContractUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Contract::getStakedAccountId).returns(false, Contract::isDeclineReward).returns(-1L, Contract::getStakedNodeId).returns(Utility.getEpochDay(withStakedNodeIdSet.getConsensusTimestamp()), Contract::getStakePeriodStart));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) 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) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) 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) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with TransactionBody

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

the class ContractUpdateTransactionHandlerTest method updateTransactionStakedNodeId.

@Test
void updateTransactionStakedNodeId() {
    RecordItem withStakedNodeIdSet = recordItemBuilder.contractUpdate().transactionBody(body -> body.setStakedNodeId(1L)).build();
    setupForContractUpdateTransactionTest(withStakedNodeIdSet, t -> assertThat(t).returns(1L, Contract::getStakedNodeId).returns(-1L, Contract::getStakedAccountId).returns(true, Contract::isDeclineReward).returns(Utility.getEpochDay(withStakedNodeIdSet.getConsensusTimestamp()), Contract::getStakePeriodStart));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) Contract(com.hedera.mirror.common.domain.contract.Contract) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) BoolValue(com.google.protobuf.BoolValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ContractID(com.hederahashgraph.api.proto.java.ContractID) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) 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) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) 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) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) Contract(com.hedera.mirror.common.domain.contract.Contract) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 73 with TransactionBody

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

the class CryptoApproveAllowanceTransactionHandlerTest 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.cryptoApproveAllowance().transactionBody(b -> {
        b.getCryptoAllowancesBuilderList().forEach(builder -> builder.getOwnerBuilder().setAlias(alias));
        b.getNftAllowancesBuilderList().forEach(builder -> builder.getOwnerBuilder().setAlias(alias));
        b.getTokenAllowancesBuilderList().forEach(builder -> builder.getOwnerBuilder().setAlias(alias));
    }).build();
    var transaction = domainBuilder.transaction().get();
    when(entityIdService.lookup(AccountID.newBuilder().setAlias(alias).build())).thenThrow(new AliasNotFoundException("alias", EntityType.ACCOUNT));
    // when, then
    assertThrows(AliasNotFoundException.class, () -> transactionHandler.updateTransaction(transaction, recordItem));
}
Also used : NftId(com.hedera.mirror.common.domain.token.NftId) BeforeEach(org.junit.jupiter.api.BeforeEach) PartialDataAction(com.hedera.mirror.importer.parser.PartialDataAction) EntityId(com.hedera.mirror.common.domain.entity.EntityId) BoolValue(com.google.protobuf.BoolValue) 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) TestUtils(com.hedera.mirror.importer.TestUtils) AccountID(com.hederahashgraph.api.proto.java.AccountID) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) Range(com.google.common.collect.Range) Mockito.times(org.mockito.Mockito.times) CryptoAllowance(com.hedera.mirror.common.domain.entity.CryptoAllowance) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) NftAllowance(com.hedera.mirror.common.domain.entity.NftAllowance) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Nft(com.hedera.mirror.common.domain.token.Nft) TokenID(com.hederahashgraph.api.proto.java.TokenID) Assertions(org.junit.jupiter.api.Assertions) TokenAllowance(com.hedera.mirror.common.domain.entity.TokenAllowance) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) CryptoApproveAllowanceTransactionBody(com.hederahashgraph.api.proto.java.CryptoApproveAllowanceTransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 74 with TransactionBody

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

the class CryptoCreateTransactionHandlerTest method getUpdateEntityTestSpecsForCreateTransaction.

@Override
protected List<UpdateEntityTestSpec> getUpdateEntityTestSpecsForCreateTransaction(FieldDescriptor memoField) {
    List<UpdateEntityTestSpec> testSpecs = super.getUpdateEntityTestSpecsForCreateTransaction(memoField);
    TransactionBody body = getTransactionBodyForUpdateEntityWithoutMemo();
    Message innerBody = getInnerBody(body);
    FieldDescriptor field = getInnerBodyFieldDescriptorByName("max_automatic_token_associations");
    innerBody = innerBody.toBuilder().setField(field, 500).build();
    body = getTransactionBody(body, innerBody);
    AbstractEntity expected = getExpectedUpdatedEntity();
    expected.setMaxAutomaticTokenAssociations(500);
    expected.setMemo("");
    testSpecs.add(UpdateEntityTestSpec.builder().description("create entity with non-zero max_automatic_token_associations").expected(expected).recordItem(getRecordItem(body, getDefaultTransactionRecord().build())).build());
    return testSpecs;
}
Also used : CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor)

Example 75 with TransactionBody

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

the class CryptoCreateTransactionHandlerTest method updateTransactionStakedAccountId.

@Test
void updateTransactionStakedAccountId() {
    // given
    final AccountID accountId = AccountID.newBuilder().setAccountNum(1L).build();
    var recordItem = recordItemBuilder.cryptoCreate().transactionBody(b -> b.setDeclineReward(false).setStakedAccountId(accountId)).build();
    // when
    transactionHandler.updateTransaction(transaction(recordItem), recordItem);
    // then
    verify(entityListener).onEntity(entities.capture());
    assertThat(entities.getValue()).isNotNull().returns(false, Entity::isDeclineReward).returns(accountId.getAccountNum(), Entity::getStakedAccountId).returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Entity::getStakePeriodStart);
}
Also used : CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Captor(org.mockito.Captor) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verify(org.mockito.Mockito.verify) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) Entity(com.hedera.mirror.common.domain.entity.Entity) Test(org.junit.jupiter.api.Test) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) List(java.util.List) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Message(com.google.protobuf.Message) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) Utility(com.hedera.mirror.importer.util.Utility) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) Entity(com.hedera.mirror.common.domain.entity.Entity) AccountID(com.hederahashgraph.api.proto.java.AccountID) Test(org.junit.jupiter.api.Test) UtilityTest(com.hedera.mirror.importer.util.UtilityTest)

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