Search in sources :

Example 11 with Transaction

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

the class TokenUpdateTransactionHandlerTest method noTreasuryUpdate.

@Test
void noTreasuryUpdate() {
    AbstractEntity entity = getExpectedUpdatedEntity();
    TokenTransferList tokenTransferList = TokenTransferList.newBuilder().setToken(TokenID.newBuilder().setTokenNum(3L).build()).addNftTransfers(NftTransfer.newBuilder().setReceiverAccountID(AccountID.newBuilder().setAccountNum(2L).build()).setSenderAccountID(AccountID.newBuilder().setAccountNum(1L).build()).setSerialNumber(// Not wildcard
    1L).build()).build();
    TransactionRecord record = getDefaultTransactionRecord().addTokenTransferLists(tokenTransferList).build();
    RecordItem recordItem = getRecordItem(getDefaultTransactionBody().build(), record);
    when(entityIdService.lookup(AccountID.newBuilder().setAccountNum(DEFAULT_AUTO_RENEW_ACCOUNT_NUM).build())).thenReturn(EntityIdEndec.decode(DEFAULT_AUTO_RENEW_ACCOUNT_NUM, EntityType.ACCOUNT));
    Transaction transaction = new Transaction();
    transaction.setEntityId(entity.toEntityId());
    transactionHandler.updateTransaction(transaction, recordItem);
    Mockito.verifyNoInteractions(nftRepository);
}
Also used : TokenTransferList(com.hederahashgraph.api.proto.java.TokenTransferList) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) AbstractEntity(com.hedera.mirror.common.domain.entity.AbstractEntity) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with Transaction

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

the class EthereumTransactionHandlerTest method updateTransactionDisabled.

@Test
void updateTransactionDisabled() {
    entityProperties.getPersist().setEthereumTransactions(false);
    var recordItem = recordItemBuilder.ethereumTransaction(true).build();
    transactionHandler.updateTransaction(new Transaction(), recordItem);
    // verify parse and listener are never called
    verify(entityListener, never()).onEntity(any());
    verify(entityListener, never()).onEthereumTransaction(any());
    verify(ethereumTransactionParser, never()).decode(any());
}
Also used : Transaction(com.hedera.mirror.common.domain.transaction.Transaction) EthereumTransaction(com.hedera.mirror.common.domain.transaction.EthereumTransaction) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with Transaction

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

the class EntityRecordItemListener method buildTransaction.

private Transaction buildTransaction(long consensusTimestamp, RecordItem recordItem) {
    TransactionBody body = recordItem.getTransactionBody();
    TransactionRecord txRecord = recordItem.getRecord();
    Long validDurationSeconds = body.hasTransactionValidDuration() ? body.getTransactionValidDuration().getSeconds() : null;
    // transactions in stream always have valid node account id.
    var nodeAccount = EntityId.of(body.getNodeAccountID());
    var transactionId = body.getTransactionID();
    // build transaction
    Transaction transaction = new Transaction();
    transaction.setChargedTxFee(txRecord.getTransactionFee());
    transaction.setConsensusTimestamp(consensusTimestamp);
    transaction.setIndex(recordItem.getTransactionIndex());
    transaction.setInitialBalance(0L);
    transaction.setMaxFee(body.getTransactionFee());
    transaction.setMemo(DomainUtils.toBytes(body.getMemoBytes()));
    transaction.setNodeAccountId(nodeAccount);
    transaction.setNonce(transactionId.getNonce());
    transaction.setPayerAccountId(recordItem.getPayerAccountId());
    transaction.setResult(txRecord.getReceipt().getStatusValue());
    transaction.setScheduled(txRecord.hasScheduleRef());
    transaction.setTransactionBytes(entityProperties.getPersist().isTransactionBytes() ? recordItem.getTransactionBytes() : null);
    transaction.setTransactionHash(DomainUtils.toBytes(txRecord.getTransactionHash()));
    transaction.setType(recordItem.getTransactionType());
    transaction.setValidDurationSeconds(validDurationSeconds);
    transaction.setValidStartNs(DomainUtils.timeStampInNanos(transactionId.getTransactionValidStart()));
    if (txRecord.hasParentConsensusTimestamp()) {
        transaction.setParentConsensusTimestamp(DomainUtils.timestampInNanosMax(txRecord.getParentConsensusTimestamp()));
    }
    return transaction;
}
Also used : TokenUnpauseTransactionBody(com.hederahashgraph.api.proto.java.TokenUnpauseTransactionBody) TokenRevokeKycTransactionBody(com.hederahashgraph.api.proto.java.TokenRevokeKycTransactionBody) FileAppendTransactionBody(com.hederahashgraph.api.proto.java.FileAppendTransactionBody) TokenPauseTransactionBody(com.hederahashgraph.api.proto.java.TokenPauseTransactionBody) TokenFeeScheduleUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenFeeScheduleUpdateTransactionBody) ConsensusSubmitMessageTransactionBody(com.hederahashgraph.api.proto.java.ConsensusSubmitMessageTransactionBody) TokenMintTransactionBody(com.hederahashgraph.api.proto.java.TokenMintTransactionBody) TokenAssociateTransactionBody(com.hederahashgraph.api.proto.java.TokenAssociateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) FileUpdateTransactionBody(com.hederahashgraph.api.proto.java.FileUpdateTransactionBody) TokenGrantKycTransactionBody(com.hederahashgraph.api.proto.java.TokenGrantKycTransactionBody) TokenUpdateTransactionBody(com.hederahashgraph.api.proto.java.TokenUpdateTransactionBody) TokenCreateTransactionBody(com.hederahashgraph.api.proto.java.TokenCreateTransactionBody) TokenUnfreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenUnfreezeAccountTransactionBody) TokenWipeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenWipeAccountTransactionBody) TokenDissociateTransactionBody(com.hederahashgraph.api.proto.java.TokenDissociateTransactionBody) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) TokenFreezeAccountTransactionBody(com.hederahashgraph.api.proto.java.TokenFreezeAccountTransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord)

Example 14 with Transaction

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

the class ContractResultServiceImplIntegrationTest method parseRecordItemAndCommit.

protected void parseRecordItemAndCommit(RecordItem recordItem, Transaction transaction) {
    transactionTemplate.executeWithoutResult(status -> {
        Instant instant = Instant.ofEpochSecond(0, recordItem.getConsensusTimestamp());
        String filename = StreamFilename.getFilename(StreamType.RECORD, DATA, instant);
        long consensusStart = recordItem.getConsensusTimestamp();
        RecordFile recordFile = domainBuilder.recordFile().customize(x -> x.consensusStart(consensusStart).consensusEnd(consensusStart + 1).name(filename)).get();
        recordStreamFileListener.onStart();
        contractResultService.process(recordItem, transaction);
        // commit, close connection
        recordStreamFileListener.onEnd(recordFile);
    });
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResultRepository(com.hedera.mirror.importer.repository.ContractResultRepository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RequiredArgsConstructor(lombok.RequiredArgsConstructor) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) ContractID(com.hederahashgraph.api.proto.java.ContractID) DomainBuilder(com.hedera.mirror.common.domain.DomainBuilder) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) DomainUtils(com.hedera.mirror.common.util.DomainUtils) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) RecordStreamFileListener(com.hedera.mirror.importer.parser.record.RecordStreamFileListener) DATA(com.hedera.mirror.importer.domain.StreamFilename.FileType.DATA) StreamType(com.hedera.mirror.common.domain.StreamType) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) TokenType(com.hederahashgraph.api.proto.java.TokenType) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) ObjectAssert(org.assertj.core.api.ObjectAssert) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Instant(java.time.Instant) ByteString(com.google.protobuf.ByteString)

Example 15 with Transaction

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

the class RemoveInvalidEntityMigrationTest method verifyEntityTypeMigrationInvalidEntitiesMultiBatch.

@Test
void verifyEntityTypeMigrationInvalidEntitiesMultiBatch() throws Exception {
    insertEntity(entityId(1, EntityType.ACCOUNT));
    insertEntity(entityId(2, EntityType.CONTRACT));
    insertEntity(entityId(3, EntityType.FILE));
    insertEntity(entityId(4, EntityType.TOPIC));
    insertEntity(entityId(5, EntityType.TOKEN));
    EntityId typeMismatchedAccountEntityId = entityId(6, EntityType.TOPIC);
    EntityId typeMismatchedContractEntityId = entityId(7, EntityType.TOKEN);
    EntityId typeMismatchedFileEntityId = entityId(8, EntityType.CONTRACT);
    EntityId typeMismatchedTopicEntityId = entityId(9, EntityType.ACCOUNT);
    EntityId typeMismatchedTokenEntityId = entityId(10, EntityType.FILE);
    insertEntity(typeMismatchedAccountEntityId);
    insertEntity(typeMismatchedContractEntityId);
    insertEntity(typeMismatchedFileEntityId);
    insertEntity(typeMismatchedTopicEntityId);
    insertEntity(typeMismatchedTokenEntityId);
    List<Transaction> transactionList = new ArrayList<>();
    transactionList.add(transaction(1, 1, EntityType.ACCOUNT, ResponseCodeEnum.SUCCESS, TransactionType.CRYPTOCREATEACCOUNT));
    transactionList.add(transaction(20, 2, EntityType.CONTRACT, ResponseCodeEnum.SUCCESS, TransactionType.CONTRACTCREATEINSTANCE));
    transactionList.add(transaction(30, 3, EntityType.FILE, ResponseCodeEnum.SUCCESS, TransactionType.FILECREATE));
    transactionList.add(transaction(40, 4, EntityType.TOPIC, ResponseCodeEnum.SUCCESS, TransactionType.CONSENSUSCREATETOPIC));
    transactionList.add(transaction(50, 5, EntityType.TOKEN, ResponseCodeEnum.SUCCESS, TransactionType.TOKENCREATION));
    transactionList.add(transaction(60, 6, EntityType.ACCOUNT, ResponseCodeEnum.SUCCESS, TransactionType.CRYPTOCREATEACCOUNT));
    transactionList.add(transaction(70, 7, EntityType.CONTRACT, ResponseCodeEnum.SUCCESS, TransactionType.CONTRACTCREATEINSTANCE));
    transactionList.add(transaction(80, 8, EntityType.FILE, ResponseCodeEnum.SUCCESS, TransactionType.FILECREATE));
    transactionList.add(transaction(90, 9, EntityType.TOPIC, ResponseCodeEnum.SUCCESS, TransactionType.CONSENSUSCREATETOPIC));
    transactionList.add(transaction(100, 10, EntityType.TOKEN, ResponseCodeEnum.SUCCESS, TransactionType.TOKENCREATION));
    transactionList.add(transaction(500, 50, EntityType.TOPIC, ResponseCodeEnum.INVALID_TOPIC_ID, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.add(transaction(1000, 100, EntityType.TOPIC, ResponseCodeEnum.TOPIC_EXPIRED, TransactionType.CONSENSUSSUBMITMESSAGE));
    transactionList.forEach(this::insertTransaction);
    // migration
    migrate();
    assertEquals(10, getEntityCount());
    assertEquals(12, transactionRepository.count());
    assertAll(() -> assertThat(findEntityById(typeMismatchedAccountEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.ACCOUNT), () -> assertThat(findEntityById(typeMismatchedContractEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.CONTRACT), () -> assertThat(findEntityById(typeMismatchedFileEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.FILE), () -> assertThat(findEntityById(typeMismatchedTopicEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.TOPIC), () -> assertThat(findEntityById(typeMismatchedTokenEntityId.getId())).extracting(Entity::getType).isEqualTo(EntityType.TOKEN));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) Transaction(com.hedera.mirror.common.domain.transaction.Transaction) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest)

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