use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallToExisting.
@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToExisting(ContractIdType contractIdType) {
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
// now call
Transaction transaction = contractCallTransaction(setupResult.protoContractId);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
ContractCallTransactionBody contractCallTransactionBody = transactionBody.getContractCall();
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID), EntityId.of(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record), () -> assertThat(contractRepository.findAll()).contains(setupResult.contract));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllToExistingInvalidTransaction.
@ParameterizedTest
@EnumSource(value = ContractIdType.class)
void contractUpdateAllToExistingInvalidTransaction(ContractIdType contractIdType) {
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE, ContractTransactionType.UPDATE);
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(contractRepository.findAll()).containsExactly(setupResult.contract));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallToExistingWithPaidStakingRewards.
@Test
void contractCallToExistingWithPaidStakingRewards() {
// given
var setupResult = setupContract(CONTRACT_ID, ContractIdType.PLAIN, true, false);
// 19137 days since epoch
var timestamp = 1653506322000111222L;
var stakePeriodStart = 19137L;
// now call
var transaction = contractCallTransaction(setupResult.protoContractId);
var transactionBody = getTransactionBody(transaction);
var record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
var contractCallTransactionBody = transactionBody.getContractCall();
var amount = contractCallTransactionBody.getAmount();
var contractAccountId = AccountID.newBuilder().setAccountNum(CONTRACT_ID.getContractNum()).build();
var contractAmount = AccountAmount.newBuilder().setAccountID(contractAccountId).setAmount(// with 15 reward payout
amount + 15L);
var stakingRewardAmount = AccountAmount.newBuilder().setAccountID(RecordItemBuilder.STAKING_REWARD_ACCOUNT).setAmount(-15L);
var transferList = record.getTransferList().toBuilder().addAccountAmounts(contractAmount).addAccountAmounts(stakingRewardAmount);
var paidRewardTransfer = AccountAmount.newBuilder().setAccountID(contractAccountId).setAmount(15L);
record = record.toBuilder().setConsensusTimestamp(TestUtils.toTimestamp(timestamp)).setTransferList(transferList).addPaidStakingRewards(paidRewardTransfer).build();
var recordItem = new RecordItem(transaction, record);
// when
parseRecordItemAndCommit(recordItem);
// then
var contract = setupResult.contract;
contract.setStakePeriodStart(stakePeriodStart);
Contract newContract = EntityId.of(CREATED_CONTRACT_ID).toEntity();
newContract.setCreatedTimestamp(timestamp);
newContract.setDeleted(false);
newContract.setMaxAutomaticTokenAssociations(0);
newContract.setMemo("");
newContract.setStakedAccountId(-1L);
newContract.setStakedNodeId(-1L);
newContract.setStakePeriodStart(-1L);
newContract.setTimestampLower(timestamp);
assertAll(() -> assertEquals(0, entityRepository.count()), () -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(5, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, recordItem.getRecord()), () -> assertContractCallResult(contractCallTransactionBody, recordItem.getRecord()), () -> assertThat(contractRepository.findAll()).containsExactlyInAnyOrder(contract, newContract));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoTransferFailedTransaction.
@Test
void cryptoTransferFailedTransaction() {
entityProperties.getPersist().setCryptoTransferAmounts(true);
// make the transfers
Transaction transaction = cryptoTransferTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = transactionRecord(transactionBody, ResponseCodeEnum.INVALID_ACCOUNT_ID);
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertCryptoTransfers(3), () -> assertEquals(0, nonFeeTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerCryptoTest method cryptoAddLiveHashPersist.
@Test
void cryptoAddLiveHashPersist() {
Transaction transaction = cryptoAddLiveHashTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
CryptoAddLiveHashTransactionBody cryptoAddLiveHashTransactionBody = transactionBody.getCryptoAddLiveHash();
TransactionRecord record = transactionRecordSuccess(transactionBody);
parseRecordItemAndCommit(new RecordItem(transaction, record));
var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
LiveHash dbLiveHash = liveHashRepository.findById(dbTransaction.getConsensusTimestamp()).get();
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertCryptoTransfers(3), () -> assertEquals(1, liveHashRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertArrayEquals(cryptoAddLiveHashTransactionBody.getLiveHash().getHash().toByteArray(), dbLiveHash.getLivehash()));
}
Aggregations