Search in sources :

Example 6 with ContractResult

use of com.hedera.mirror.common.domain.contract.ContractResult in project hedera-mirror-node by hashgraph.

the class ContractCreateTransactionHandlerTest method updateContractResultNonContractCallTransaction.

@Test
void updateContractResultNonContractCallTransaction() {
    ContractResult contractResult = ContractResult.builder().build();
    var recordItem = recordItemBuilder.contractCall().build();
    transactionHandler.updateContractResult(contractResult, recordItem);
    assertThat(contractResult).returns(null, ContractResult::getAmount).returns(null, ContractResult::getGasLimit).returns(null, ContractResult::getFunctionParameters);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with ContractResult

use of com.hedera.mirror.common.domain.contract.ContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultRepositoryTest method save.

@Test
void save() {
    ContractResult contractResult = domainBuilder.contractResult().persist();
    assertThat(contractResultRepository.findById(contractResult.getId())).get().isEqualTo(contractResult);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Test(org.junit.jupiter.api.Test)

Example 8 with ContractResult

use of com.hedera.mirror.common.domain.contract.ContractResult in project hedera-mirror-node by hashgraph.

the class ContractResultServiceImpl method processContractResult.

private void processContractResult(RecordItem recordItem, EntityId contractEntityId, ContractFunctionResult functionResult, TransactionHandler transactionHandler) {
    // create child contracts regardless of contractResults support
    List<Long> contractIds = getCreatedContractIds(functionResult, recordItem, contractEntityId);
    if (!entityProperties.getPersist().isContractResults()) {
        return;
    }
    ContractResult contractResult = new ContractResult();
    contractResult.setConsensusTimestamp(recordItem.getConsensusTimestamp());
    contractResult.setContractId(contractEntityId);
    contractResult.setPayerAccountId(recordItem.getPayerAccountId());
    transactionHandler.updateContractResult(contractResult, recordItem);
    if (isValidContractFunctionResult(functionResult)) {
        if (!isContractCreateOrCall(recordItem.getTransactionBody())) {
            // amount, gasLimit and functionParameters were missing from record proto prior to HAPI v0.25
            contractResult.setAmount(functionResult.getAmount());
            contractResult.setGasLimit(functionResult.getGas());
            contractResult.setFunctionParameters(DomainUtils.toBytes(functionResult.getFunctionParameters()));
        }
        contractResult.setBloom(DomainUtils.toBytes(functionResult.getBloom()));
        contractResult.setCallResult(DomainUtils.toBytes(functionResult.getContractCallResult()));
        contractResult.setCreatedContractIds(contractIds);
        contractResult.setErrorMessage(functionResult.getErrorMessage());
        contractResult.setFunctionResult(functionResult.toByteArray());
        contractResult.setGasUsed(functionResult.getGasUsed());
        if (functionResult.hasSenderId()) {
            contractResult.setSenderId(EntityId.of(functionResult.getSenderId()));
        }
        processContractLogs(functionResult, contractResult);
        processContractStateChanges(functionResult, contractResult);
    }
    entityListener.onContractResult(contractResult);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult)

Example 9 with ContractResult

use of com.hedera.mirror.common.domain.contract.ContractResult 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());
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) DomainUtils.toBytes(com.hedera.mirror.common.util.DomainUtils.toBytes) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) EntityId(com.hedera.mirror.common.domain.entity.EntityId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StringValue(com.google.protobuf.StringValue) ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) Duration(com.hederahashgraph.api.proto.java.Duration) EntityType(com.hedera.mirror.common.domain.entity.EntityType) ByteBuffer(java.nio.ByteBuffer) ContractID(com.hederahashgraph.api.proto.java.ContractID) Map(java.util.Map) RecordFile(com.hedera.mirror.common.domain.transaction.RecordFile) Version(org.springframework.data.util.Version) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TestUtils(com.hedera.mirror.importer.TestUtils) Utility(com.hedera.mirror.importer.util.Utility) RecordItemBuilder(com.hedera.mirror.importer.parser.domain.RecordItemBuilder) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) Range(com.google.common.collect.Range) Resource(javax.annotation.Resource) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo) Collectors(java.util.stream.Collectors) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) BytesValue(com.google.protobuf.BytesValue) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount) List(java.util.List) ContractLogRepository(com.hedera.mirror.importer.repository.ContractLogRepository) STAKEDID_NOT_SET(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody.StakedIdCase.STAKEDID_NOT_SET) ObjectAssert(org.assertj.core.api.ObjectAssert) Optional(java.util.Optional) AccountIdConverter(com.hedera.mirror.common.converter.AccountIdConverter) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) CsvSource(org.junit.jupiter.params.provider.CsvSource) Contract(com.hedera.mirror.common.domain.contract.Contract) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) Value(lombok.Value) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractStateChangeRepository(com.hedera.mirror.importer.repository.ContractStateChangeRepository) AccountID(com.hederahashgraph.api.proto.java.AccountID) Timestamp(com.hederahashgraph.api.proto.java.Timestamp) Int32Value(com.google.protobuf.Int32Value) DomainUtils(com.hedera.mirror.common.util.DomainUtils) FileID(com.hederahashgraph.api.proto.java.FileID) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) Consumer(java.util.function.Consumer) TokenType(com.hederahashgraph.api.proto.java.TokenType) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TokenID(com.hederahashgraph.api.proto.java.TokenID) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Assertions(org.junit.jupiter.api.Assertions) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) FUNGIBLE_COMMON(com.hederahashgraph.api.proto.java.TokenType.FUNGIBLE_COMMON) Collections(java.util.Collections) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractFunctionResult(com.hederahashgraph.api.proto.java.ContractFunctionResult) ContractID(com.hederahashgraph.api.proto.java.ContractID)

Example 10 with ContractResult

use of com.hedera.mirror.common.domain.contract.ContractResult in project hedera-mirror-node by hashgraph.

the class CompositeBatchPersisterTest method persist.

@Test
@Transactional
void persist() {
    Contract contract = domainBuilder.contract().get();
    ContractResult contractResult = domainBuilder.contractResult().get();
    compositeBatchInserter.persist(List.of(contract));
    compositeBatchInserter.persist(List.of(contractResult));
    assertThat(contractRepository.findAll()).containsExactly(contract);
    assertThat(contractResultRepository.findAll()).containsExactly(contractResult);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Contract(com.hedera.mirror.common.domain.contract.Contract) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)12 Test (org.junit.jupiter.api.Test)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Contract (com.hedera.mirror.common.domain.contract.Contract)4 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)4 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)4 EntityId (com.hedera.mirror.common.domain.entity.EntityId)4 ContractLoginfo (com.hederahashgraph.api.proto.java.ContractLoginfo)4 Range (com.google.common.collect.Range)3 ByteString (com.google.protobuf.ByteString)3 BytesValue (com.google.protobuf.BytesValue)3 Int32Value (com.google.protobuf.Int32Value)3 StringValue (com.google.protobuf.StringValue)3 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)3 EntityType (com.hedera.mirror.common.domain.entity.EntityType)3 RecordFile (com.hedera.mirror.common.domain.transaction.RecordFile)3 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)3 DomainUtils (com.hedera.mirror.common.util.DomainUtils)3 DomainUtils.toBytes (com.hedera.mirror.common.util.DomainUtils.toBytes)3 TestUtils (com.hedera.mirror.importer.TestUtils)3