use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallDoNotPersist.
@Test
void contractCallDoNotPersist() {
entityProperties.getPersist().setContracts(false);
Transaction transaction = contractCallTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(), () -> assertTransactionAndRecord(transactionBody, record));
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferWithPersistence.
@Test
void cryptoTransferWithPersistence() {
entityProperties.getPersist().setCryptoTransferAmounts(true);
// 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(4, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record));
}
use of com.hederahashgraph.api.proto.java.TransactionRecord 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.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method proxyAccountIdSetTo0.
// Transactions in production have proxyAccountID explicitly set to '0.0.0'. Test is to prevent code regression
// in handling this weird case.
@Test
void proxyAccountIdSetTo0() {
// given
Transaction transaction = cryptoUpdateTransaction(accountId1);
TransactionBody transactionBody = getTransactionBody(transaction);
var bodyBuilder = transactionBody.toBuilder();
bodyBuilder.getCryptoUpdateAccountBuilder().setProxyAccountID(AccountID.getDefaultInstance());
transactionBody = bodyBuilder.build();
transaction = Transaction.newBuilder().setSignedTransactionBytes(SignedTransaction.newBuilder().setBodyBytes(transactionBody.toByteString()).build().toByteString()).build();
TransactionRecord record = transactionRecordSuccess(transactionBody);
// then: process the transaction without throwing NPE
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertThat(transactionRepository.count()).isEqualTo(1L);
assertThat(entityRepository.findById(EntityId.of(accountId1).getId())).get().extracting(Entity::getProxyAccountId).isNull();
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferHasCorrectIsApprovalValue.
@Test
void cryptoTransferHasCorrectIsApprovalValue() {
final long[] accountNums = { PAYER.getAccountNum(), PAYER2.getAccountNum(), PAYER3.getAccountNum() };
final long[] amounts = { 210, -300, 15 };
final boolean[] isApprovals = { false, true, false };
Transaction transaction = buildTransaction(r -> {
for (int i = 0; i < accountNums.length; i++) {
var accountAmount = accountAmount(accountNums[i], amounts[i]).setIsApproval(isApprovals[i]).build();
r.getCryptoTransferBuilder().getTransfersBuilder().addAccountAmounts(accountAmount);
}
});
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = buildTransactionRecordWithNoTransactions(builder -> {
for (int i = 0; i < accountNums.length; i++) {
var accountAmount = accountAmount(accountNums[i], amounts[i]).setIsApproval(false).build();
builder.getTransferListBuilder().addAccountAmounts(accountAmount);
}
}, transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
var recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(amounts.length, cryptoTransferRepository.count()), () -> {
for (var cryptoTransfer : cryptoTransferRepository.findAll()) {
for (int i = 0; i < isApprovals.length; i++) {
if (cryptoTransfer.getEntityId() != accountNums[i]) {
continue;
}
assertThat(cryptoTransfer).extracting(CryptoTransfer::getIsApproval).isEqualTo(isApprovals[i]);
}
}
});
}
Aggregations