Search in sources :

Example 86 with TransactionRecord

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

the class EntityRecordItemListenerCryptoTest method cryptoCreateWithInitialBalance.

@Test
void cryptoCreateWithInitialBalance() {
    Transaction transaction = cryptoCreateTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
    long initialBalance = cryptoCreateTransactionBody.getInitialBalance();
    var transfer1 = accountAmount(accountId1.getAccountNum(), initialBalance);
    var transfer2 = accountAmount(PAYER.getAccountNum(), -initialBalance);
    TransactionRecord record = transactionRecordSuccess(transactionBody, recordBuilder -> groupCryptoTransfersByAccountId(recordBuilder, List.of(transfer1, transfer2)));
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    var accountEntityId = EntityId.of(accountId1);
    var consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    Optional<CryptoTransfer> initialBalanceTransfer = cryptoTransferRepository.findById(new CryptoTransfer.Id(initialBalance, consensusTimestamp, accountEntityId.getId()));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(accountEntityId), () -> assertCryptoTransfers(4).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer1.build())).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer2.build())), () -> assertCryptoTransaction(transactionBody, record), () -> assertCryptoEntity(cryptoCreateTransactionBody, record.getConsensusTimestamp()), () -> assertEquals(cryptoCreateTransactionBody.getInitialBalance(), dbTransaction.getInitialBalance()), () -> assertThat(initialBalanceTransfer).isPresent());
}
Also used : CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 87 with TransactionRecord

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

the class EntityRecordItemListenerCryptoTest method cryptoCreateInitialBalanceInTransferList.

@Test
void cryptoCreateInitialBalanceInTransferList() {
    Transaction transaction = cryptoCreateTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
    // add initial balance to transfer list
    long initialBalance = cryptoCreateTransactionBody.getInitialBalance();
    var transfer1 = accountAmount(accountId1.getAccountNum(), initialBalance);
    var transfer2 = accountAmount(PAYER.getAccountNum(), -initialBalance);
    TransactionRecord record = transactionRecordSuccess(transactionBody, recordBuilder -> groupCryptoTransfersByAccountId(recordBuilder, List.of(transfer1, transfer2)));
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(EntityId.of(accountId1)), () -> assertCryptoTransfers(4).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer1.build())).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer2.build())), () -> assertCryptoTransaction(transactionBody, record), () -> assertCryptoEntity(cryptoCreateTransactionBody, record.getConsensusTimestamp()), () -> assertEquals(cryptoCreateTransactionBody.getInitialBalance(), dbTransaction.getInitialBalance()));
}
Also used : CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 88 with TransactionRecord

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

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithoutPersistence.

@Test
void cryptoTransferWithoutPersistence() {
    entityProperties.getPersist().setCryptoTransferAmounts(false);
    // make the transfers
    Transaction transaction = cryptoTransferTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord record = transactionRecordSuccess(transactionBody);
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertEquals(0, entityRepository.count()), () -> assertCryptoTransfers(0), () -> assertTransactionAndRecord(transactionBody, record));
}
Also used : CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 89 with TransactionRecord

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

the class EntityRecordItemListenerCryptoTest method cryptoTransferWithAlias.

@Test
void cryptoTransferWithAlias() {
    entityProperties.getPersist().setCryptoTransferAmounts(true);
    entityProperties.getPersist().setNonFeeTransfers(true);
    Entity entity = domainBuilder.entity().persist();
    var newAccount = AccountID.newBuilder().setAccountNum(domainBuilder.id()).build();
    assertThat(entityRepository.findByAlias(entity.getAlias())).get().isEqualTo(entity.getId());
    assertThat(entityRepository.findByAlias(ALIAS_KEY.toByteArray())).isNotPresent();
    // Crypto create alias account
    Transaction accountCreateTransaction = cryptoCreateTransaction();
    TransactionBody accountCreateTransactionBody = getTransactionBody(accountCreateTransaction);
    TransactionRecord recordCreate = buildTransactionRecord(recordBuilder -> recordBuilder.setAlias(ALIAS_KEY).getReceiptBuilder().setAccountID(newAccount), accountCreateTransactionBody, ResponseCodeEnum.SUCCESS.getNumber());
    var transfer1 = accountAliasAmount(ALIAS_KEY, 1003).build();
    var transfer2 = accountAliasAmount(ByteString.copyFrom(entity.getAlias()), 1004).build();
    // Crypto transfer to both existing alias and newly created alias accounts
    Transaction transaction = buildTransaction(builder -> builder.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(transfer1).addAccountAmounts(transfer2));
    TransactionBody transactionBody = getTransactionBody(transaction);
    TransactionRecord recordTransfer = transactionRecordSuccess(transactionBody, builder -> groupCryptoTransfersByAccountId(builder, List.of()));
    parseRecordItemsAndCommit(List.of(new RecordItem(accountCreateTransaction, recordCreate), new RecordItem(transaction, recordTransfer)));
    assertAll(() -> assertEquals(2, transactionRepository.count()), () -> assertEntities(EntityId.of(newAccount), entity.toEntityId()), () -> assertCryptoTransfers(6).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer1)).areAtMost(1, isAccountAmountReceiverAccountAmount(transfer2)), () -> assertEquals(additionalTransfers.length * 2 + 2, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, recordTransfer), () -> assertThat(findNonFeeTransfers()).extracting(NonFeeTransfer::getEntityId).extracting(EntityId::getEntityNum).contains(newAccount.getAccountNum(), entity.getNum()));
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) Entity(com.hedera.mirror.common.domain.entity.Entity) CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 90 with TransactionRecord

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

the class EntityRecordItemListenerCryptoTest method cryptoCreateAccountAlias.

@Test
void cryptoCreateAccountAlias() {
    Transaction transaction = cryptoCreateTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
    TransactionRecord record = buildTransactionRecord(recordBuilder -> recordBuilder.setAlias(ALIAS_KEY).getReceiptBuilder().setAccountID(accountId1), transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    var accountEntityId = EntityId.of(accountId1);
    var consensusTimestamp = DomainUtils.timeStampInNanos(record.getConsensusTimestamp());
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    Optional<CryptoTransfer> initialBalanceTransfer = cryptoTransferRepository.findById(new CryptoTransfer.Id(0, consensusTimestamp, accountEntityId.getId()));
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(accountEntityId), () -> assertCryptoTransfers(3), () -> assertCryptoTransaction(transactionBody, record), () -> assertCryptoEntity(cryptoCreateTransactionBody, record.getConsensusTimestamp()), () -> assertEquals(cryptoCreateTransactionBody.getInitialBalance(), dbTransaction.getInitialBalance()), () -> assertThat(initialBalanceTransfer).isEmpty(), () -> assertThat(entityRepository.findByAlias(ALIAS_KEY.toByteArray())).get().isEqualTo(accountEntityId.getId()));
}
Also used : CryptoDeleteLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoUpdateTransactionBody(com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) CryptoAddLiveHashTransactionBody(com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) CryptoCreateTransactionBody(com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody) CryptoTransfer(com.hedera.mirror.common.domain.transaction.CryptoTransfer) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) UtilityTest(com.hedera.mirror.importer.util.UtilityTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)107 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)86 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)84 Transaction (com.hederahashgraph.api.proto.java.Transaction)83 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)74 Test (org.junit.jupiter.api.Test)69 FileAppendTransactionBody (com.hederahashgraph.api.proto.java.FileAppendTransactionBody)30 FileUpdateTransactionBody (com.hederahashgraph.api.proto.java.FileUpdateTransactionBody)30 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)28 FileCreateTransactionBody (com.hederahashgraph.api.proto.java.FileCreateTransactionBody)28 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)28 CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)26 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)26 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)26 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)23 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)19 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)19 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)19 Entity (com.hedera.mirror.common.domain.entity.Entity)17 EnumSource (org.junit.jupiter.params.provider.EnumSource)13