Search in sources :

Example 6 with CryptoCreateTransactionBody

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

the class EntityRecordItemListenerCryptoTest method cryptoCreateFailedTransaction.

@Test
void cryptoCreateFailedTransaction() {
    Transaction transaction = cryptoCreateTransaction();
    TransactionBody transactionBody = getTransactionBody(transaction);
    CryptoCreateTransactionBody cryptoCreateTransactionBody = transactionBody.getCryptoCreateAccount();
    // Clear receipt.accountID since transaction is failure.
    TransactionRecord.Builder recordBuilder = transactionRecord(transactionBody, ResponseCodeEnum.INSUFFICIENT_PAYER_BALANCE).toBuilder();
    recordBuilder.getReceiptBuilder().clearAccountID();
    TransactionRecord record = recordBuilder.build();
    parseRecordItemAndCommit(new RecordItem(transaction, record));
    var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
    assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertCryptoTransfers(3), () -> assertTransactionAndRecord(transactionBody, record), () -> assertNull(dbTransaction.getEntityId()), () -> 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 7 with CryptoCreateTransactionBody

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

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

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

CryptoCreateTransactionBody (com.hederahashgraph.api.proto.java.CryptoCreateTransactionBody)9 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)8 CryptoUpdateTransactionBody (com.hederahashgraph.api.proto.java.CryptoUpdateTransactionBody)6 Transaction (com.hederahashgraph.api.proto.java.Transaction)6 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)5 UtilityTest (com.hedera.mirror.importer.util.UtilityTest)5 CryptoAddLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoAddLiveHashTransactionBody)5 CryptoDeleteLiveHashTransactionBody (com.hederahashgraph.api.proto.java.CryptoDeleteLiveHashTransactionBody)5 SignedTransaction (com.hederahashgraph.api.proto.java.SignedTransaction)5 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)5 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 CryptoTransfer (com.hedera.mirror.common.domain.transaction.CryptoTransfer)3 ByteString (com.google.protobuf.ByteString)2 AccountID (com.hederahashgraph.api.proto.java.AccountID)2 MoreObjects (com.google.common.base.MoreObjects)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 HapiPropertySource (com.hedera.services.bdd.spec.HapiPropertySource)1 AdapterUtils (com.hedera.services.bdd.spec.fees.AdapterUtils)1 KeyType (com.hedera.services.bdd.spec.keys.KeyFactory.KeyType)1