use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCreateFailedWithoutResult.
@Test
void contractCreateFailedWithoutResult() {
RecordItem recordItem = recordItemBuilder.contractCreate().receipt(r -> r.clearContractID().setStatus(ResponseCodeEnum.INSUFFICIENT_ACCOUNT_BALANCE)).record(TransactionRecord.Builder::clearContractCreateResult).build();
var record = recordItem.getRecord();
var transactionBody = recordItem.getTransactionBody();
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEntities(), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertFailedContractCreate(transactionBody, record));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallBadContractId.
// Test for bad entity id in a failed transaction
@Test
void contractCallBadContractId() {
Transaction transaction = contractCallTransaction(ContractID.newBuilder().setContractNum(-1L).build());
var transactionBody = getTransactionBody(transaction);
TransactionRecord record = buildTransactionRecord(recordBuilder -> {
var contractFunctionResult = recordBuilder.getContractCallResultBuilder();
buildContractFunctionResult(contractFunctionResult);
// Only contract create can contain parent ID
contractFunctionResult.removeCreatedContractIDs(0);
}, transactionBody, ResponseCodeEnum.INVALID_CONTRACT_ID.getNumber());
parseRecordItemAndCommit(new RecordItem(transaction, record));
var dbTransaction = getDbTransaction(record.getConsensusTimestamp());
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(), () -> assertTransactionAndRecord(transactionBody, record), () -> assertNull(dbTransaction.getEntityId()));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractDeleteToExisting.
@ParameterizedTest
@CsvSource({ "PLAIN, false", "PARSABLE_EVM,true", "CREATE2_EVM,false" })
void contractDeleteToExisting(ContractIdType contractIdType, boolean permanentRemoval) {
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
Transaction transaction = contractDeleteTransaction(setupResult.protoContractId, permanentRemoval);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.DELETE);
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
Contract dbContractEntity = getTransactionEntity(record.getConsensusTimestamp());
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(0, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(setupResult.contract.toEntityId()), () -> assertTransactionAndRecord(transactionBody, record), () -> assertThat(dbContractEntity).isNotNull().returns(true, Contract::getDeleted).returns(EntityId.of(PAYER), Contract::getObtainerId).returns(permanentRemoval, Contract::getPermanentRemoval).returns(Range.atLeast(recordItem.getConsensusTimestamp()), Contract::getTimestampRange).usingRecursiveComparison().ignoringFields("deleted", "obtainerId", "permanentRemoval", "timestampRange").isEqualTo(setupResult.contract));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallFailedWithResult.
@Test
void contractCallFailedWithResult() {
RecordItem recordItem = recordItemBuilder.contractCall().record(r -> r.setContractCreateResult(ContractFunctionResult.getDefaultInstance())).receipt(r -> r.clearContractID().setStatus(ResponseCodeEnum.CONTRACT_EXECUTION_EXCEPTION)).build();
var record = recordItem.getRecord();
var transactionBody = recordItem.getTransactionBody();
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(), () -> assertFailedContractCallTransaction(transactionBody, record));
}
use of com.hedera.mirror.common.domain.transaction.RecordItem in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallToNew.
@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToNew(ContractIdType contractIdType) {
// The contract is not in db, it should still work. Note for the create2 evm address,
// ContractCallTransactionHandler will get the correct plain contractId from the transaction record instead
// only cache the create2 evm address to verify it later
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, false, contractIdType == ContractIdType.CREATE2_EVM);
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(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record));
}
Aggregations