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