Search in sources :

Example 1 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class SqlEntityListenerTest method makeTransaction.

private Transaction makeTransaction() {
    EntityId entityId = EntityId.of(10, 10, 10, ACCOUNT);
    Transaction transaction = new Transaction();
    transaction.setConsensusTimestamp(101L);
    transaction.setEntityId(entityId);
    transaction.setNodeAccountId(entityId);
    transaction.setMemo("memo".getBytes());
    transaction.setNonce(0);
    transaction.setType(14);
    transaction.setResult(22);
    transaction.setTransactionHash("transaction hash".getBytes());
    transaction.setTransactionBytes("transaction bytes".getBytes());
    transaction.setPayerAccountId(entityId);
    transaction.setValidStartNs(1L);
    transaction.setValidDurationSeconds(1L);
    transaction.setMaxFee(1L);
    transaction.setChargedTxFee(1L);
    transaction.setInitialBalance(0L);
    transaction.setScheduled(true);
    return transaction;
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Transaction(com.hedera.mirror.common.domain.transaction.Transaction)

Example 2 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction 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 3 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class ContractCreateTransactionHandlerTest method updateTransactionStakedAccountId.

@Test
void updateTransactionStakedAccountId() {
    // given
    final AccountID accountID = AccountID.newBuilder().setAccountNum(1L).build();
    var recordItem = recordItemBuilder.contractCreate().transactionBody(b -> b.clearAutoRenewAccountId().setDeclineReward(false).setStakedAccountId(accountID)).build();
    // when
    transactionHandler.updateTransaction(transaction(recordItem), recordItem);
    // then
    verify(entityListener).onContract(contracts.capture());
    assertThat(contracts.getValue()).isNotNull().returns(false, Contract::isDeclineReward).returns(accountID.getAccountNum(), Contract::getStakedAccountId).returns(-1L, Contract::getStakedNodeId).returns(Utility.getEpochDay(recordItem.getConsensusTimestamp()), Contract::getStakePeriodStart);
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) 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) Descriptors(com.google.protobuf.Descriptors) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) EthereumTransactionParser(com.hedera.mirror.importer.parser.record.ethereum.EthereumTransactionParser) Captor(org.mockito.Captor) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) TestUtils(com.hedera.mirror.importer.TestUtils) Mockito.doReturn(org.mockito.Mockito.doReturn) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) 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) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) EntityProperties(com.hedera.mirror.importer.parser.record.entity.EntityProperties) Assertions(org.junit.jupiter.api.Assertions) Message(com.google.protobuf.Message) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) 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) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction in project hedera-mirror-node by hashgraph.

the class ContractCreateTransactionHandlerTest 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.contractCreate().transactionBody(b -> b.getAutoRenewAccountIdBuilder().setAlias(alias)).build();
    var contractId = EntityId.of(recordItem.getRecord().getReceipt().getContractID());
    var timestamp = recordItem.getConsensusTimestamp();
    var transaction = domainBuilder.transaction().customize(t -> t.consensusTimestamp(timestamp).entityId(contractId)).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) 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) Descriptors(com.google.protobuf.Descriptors) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) EnumSource(org.junit.jupiter.params.provider.EnumSource) EthereumTransactionParser(com.hedera.mirror.importer.parser.record.ethereum.EthereumTransactionParser) Captor(org.mockito.Captor) EntityType(com.hedera.mirror.common.domain.entity.EntityType) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) RecordParserProperties(com.hedera.mirror.importer.parser.record.RecordParserProperties) ArgumentCaptor(org.mockito.ArgumentCaptor) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) AliasNotFoundException(com.hedera.mirror.importer.exception.AliasNotFoundException) TestUtils(com.hedera.mirror.importer.TestUtils) Mockito.doReturn(org.mockito.Mockito.doReturn) AccountID(com.hederahashgraph.api.proto.java.AccountID) Utility(com.hedera.mirror.importer.util.Utility) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) 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) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) CONTRACT(com.hedera.mirror.common.domain.entity.EntityType.CONTRACT) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) EntityProperties(com.hedera.mirror.importer.parser.record.entity.EntityProperties) Assertions(org.junit.jupiter.api.Assertions) Message(com.google.protobuf.Message) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) 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 5 with Transaction

use of com.hedera.mirror.common.domain.transaction.Transaction 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)

Aggregations

Transaction (com.hedera.mirror.common.domain.transaction.Transaction)37 Test (org.junit.jupiter.api.Test)24 EntityId (com.hedera.mirror.common.domain.entity.EntityId)23 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)19 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)18 DomainUtils (com.hedera.mirror.common.util.DomainUtils)17 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)17 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)17 EntityType (com.hedera.mirror.common.domain.entity.EntityType)16 AccountID (com.hederahashgraph.api.proto.java.AccountID)16 Mockito.verify (org.mockito.Mockito.verify)16 RecordParserProperties (com.hedera.mirror.importer.parser.record.RecordParserProperties)15 Mockito.verifyNoInteractions (org.mockito.Mockito.verifyNoInteractions)15 Range (com.google.common.collect.Range)14 AliasNotFoundException (com.hedera.mirror.importer.exception.AliasNotFoundException)14 PartialDataAction (com.hedera.mirror.importer.parser.PartialDataAction)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 Assertions (org.junit.jupiter.api.Assertions)14 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 Mockito.when (org.mockito.Mockito.when)14