use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerTokenTest method getRecordItem.
private RecordItem getRecordItem(long consensusTimestamp, Transaction transaction, Consumer<TransactionRecord.Builder> customBuilder) {
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord transactionRecord = buildTransactionRecord(builder -> {
builder.setConsensusTimestamp(TestUtils.toTimestamp(consensusTimestamp));
customBuilder.accept(builder);
}, transactionBody, ResponseCodeEnum.SUCCESS.getNumber());
return new RecordItem(transaction, transactionRecord);
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllToExisting.
@ParameterizedTest
@CsvSource({ "PLAIN, 5005, 5005", "PARSABLE_EVM, 0, 0", "CREATE2_EVM, , 5002" })
void contractUpdateAllToExisting(ContractIdType contractIdType, Long newAutoRenewAccount, Long expectedAutoRenewAccount) {
// first create the contract
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true, c -> {
c.obtainerId(null).declineReward(true).stakedAccountId(1L);
if (newAutoRenewAccount == null) {
c.autoRenewAccountId(expectedAutoRenewAccount);
}
});
Contract contract = setupResult.contract;
// now update
Transaction transaction = contractUpdateAllTransaction(setupResult.protoContractId, true, b -> {
if (newAutoRenewAccount != null) {
b.getAutoRenewAccountIdBuilder().setAccountNum(newAutoRenewAccount);
}
});
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(expectedAutoRenewAccount, Contract::getAutoRenewAccountId).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method assertContractCallResult.
private void assertContractCallResult(ContractCallTransactionBody transactionBody, TransactionRecord record) {
long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
ContractFunctionResult result = record.getContractCallResult();
// get the corresponding entity id from the local cache, fall back to parseContractId if not found.
ContractID protoContractId = record.getContractCallResult().getContractID();
EntityId contractId = contractIds.getOrDefault(protoContractId, parseContractId(protoContractId));
ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getAmount(), ContractResult::getAmount).returns(contractId, ContractResult::getContractId).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(toBytes(transactionBody.getFunctionParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractUpdateAllWithMemoToExisting.
@Test
void contractUpdateAllWithMemoToExisting() {
// first create the contract
EntityId contractId = EntityId.of(CONTRACT_ID);
Contract contract = domainBuilder.contract().customize(c -> c.obtainerId(null).id(contractId.getId()).num(contractId.getEntityNum()).stakedNodeId(1L)).persist();
// now update
Transaction transaction = contractUpdateAllTransaction(false);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.UPDATE);
ContractUpdateTransactionBody contractUpdateTransactionBody = transactionBody.getContractUpdateInstance();
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID)), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractEntity(contractUpdateTransactionBody, record.getConsensusTimestamp()).returns(contract.getCreatedTimestamp(), Contract::getCreatedTimestamp).returns(contract.getFileId(), // FileId is ignored on updates by HAPI
Contract::getFileId));
}
use of com.hederahashgraph.api.proto.java.TransactionRecord in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallFailedWithoutResult.
@Test
void contractCallFailedWithoutResult() {
Transaction transaction = contractCallTransaction();
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE, ContractTransactionType.CALL).toBuilder().clearContractCallResult().build();
parseRecordItemAndCommit(new RecordItem(transaction, record));
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(), () -> assertFailedContractCallTransaction(transactionBody, record));
}
Aggregations