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()));
}
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());
}
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()));
}
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()));
}
Aggregations