Search in sources :

Example 1 with ContractResult

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

the class EntityRecordItemListenerContractTest method assertContractCreateResult.

private void assertContractCreateResult(ContractCreateTransactionBody transactionBody, TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
    TransactionReceipt receipt = record.getReceipt();
    ContractFunctionResult result = record.getContractCreateResult();
    ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getInitialBalance(), ContractResult::getAmount).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId).returns(toBytes(transactionBody.getConstructorParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
    if (receipt.getStatus() == ResponseCodeEnum.SUCCESS) {
        contractResult.returns(EntityId.of(receipt.getContractID()), ContractResult::getContractId);
    }
    assertContractResult(consensusTimestamp, result, result.getLogInfoList(), contractResult, result.getStateChangesList());
}
Also used : 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) TransactionReceipt(com.hederahashgraph.api.proto.java.TransactionReceipt)

Example 2 with ContractResult

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

the class EntityRecordItemListenerContractTest method assertPartialContractCallResult.

private void assertPartialContractCallResult(ContractCallTransactionBody transactionBody, TransactionRecord record) {
    long consensusTimestamp = DomainUtils.timestampInNanosMax(record.getConsensusTimestamp());
    ContractFunctionResult result = record.getContractCallResult();
    ObjectAssert<ContractResult> contractResult = assertThat(contractResultRepository.findAll()).filteredOn(c -> c.getConsensusTimestamp().equals(consensusTimestamp)).hasSize(1).first().returns(transactionBody.getAmount(), ContractResult::getAmount).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(EntityId.of(transactionBody.getContractID()), ContractResult::getContractId).returns(toBytes(transactionBody.getFunctionParameters()), ContractResult::getFunctionParameters).returns(transactionBody.getGas(), ContractResult::getGasLimit);
    assertPartialContractResult(contractResult);
}
Also used : 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)

Example 3 with ContractResult

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

the class EntityRecordItemListenerContractTest method assertContractResult.

private void assertContractResult(long consensusTimestamp, ContractFunctionResult result, List<ContractLoginfo> logInfoList, ObjectAssert<ContractResult> contractResult, List<com.hederahashgraph.api.proto.java.ContractStateChange> stateChanges) {
    List<Long> createdContractIds = result.getCreatedContractIDsList().stream().map(ContractID::getContractNum).collect(Collectors.toList());
    contractResult.returns(result.getBloom().toByteArray(), ContractResult::getBloom).returns(result.getContractCallResult().toByteArray(), ContractResult::getCallResult).returns(consensusTimestamp, ContractResult::getConsensusTimestamp).returns(createdContractIds, ContractResult::getCreatedContractIds).returns(result.getErrorMessage(), ContractResult::getErrorMessage).returns(result.toByteArray(), ContractResult::getFunctionResult).returns(result.getGasUsed(), ContractResult::getGasUsed);
    for (int i = 0; i < logInfoList.size(); i++) {
        int index = i;
        ContractLoginfo logInfo = logInfoList.get(i);
        assertThat(contractLogRepository.findById(new ContractLog.Id(consensusTimestamp, index))).isPresent().get().returns(logInfo.getBloom().toByteArray(), ContractLog::getBloom).returns(consensusTimestamp, ContractLog::getConsensusTimestamp).returns(EntityId.of(logInfo.getContractID()), ContractLog::getContractId).returns(logInfo.getData().toByteArray(), ContractLog::getData).returns(index, ContractLog::getIndex).returns(EntityId.of(result.getContractID()), ContractLog::getRootContractId).returns(Utility.getTopic(logInfo, 0), ContractLog::getTopic0).returns(Utility.getTopic(logInfo, 1), ContractLog::getTopic1).returns(Utility.getTopic(logInfo, 2), ContractLog::getTopic2).returns(Utility.getTopic(logInfo, 3), ContractLog::getTopic3);
    }
    int count = 0;
    var contractStateChanges = assertThat(contractStateChangeRepository.findAll());
    for (var contractStateChangeInfo : stateChanges) {
        EntityId contractId = EntityId.of(contractStateChangeInfo.getContractID());
        for (var storageChange : contractStateChangeInfo.getStorageChangesList()) {
            byte[] slot = DomainUtils.toBytes(storageChange.getSlot());
            byte[] valueWritten = storageChange.hasValueWritten() ? storageChange.getValueWritten().getValue().toByteArray() : null;
            contractStateChanges.filteredOn(c -> c.getConsensusTimestamp() == consensusTimestamp && c.getContractId() == contractId.getId() && Arrays.equals(c.getSlot(), slot)).hasSize(1).first().returns(storageChange.getValueRead().toByteArray(), ContractStateChange::getValueRead).returns(valueWritten, ContractStateChange::getValueWritten);
            ++count;
        }
    }
    contractStateChanges.hasSize(count);
}
Also used : EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange) ContractLog(com.hedera.mirror.common.domain.contract.ContractLog) EntityId(com.hedera.mirror.common.domain.entity.EntityId) ContractLoginfo(com.hederahashgraph.api.proto.java.ContractLoginfo)

Example 4 with ContractResult

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

the class SqlEntityListenerTest method onContractResult.

@Test
void onContractResult() {
    // given
    ContractResult contractResult = domainBuilder.contractResult().get();
    // when
    sqlEntityListener.onContractResult(contractResult);
    completeFileAndCommit();
    // then
    assertThat(contractResultRepository.findAll()).containsExactlyInAnyOrder(contractResult);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Test(org.junit.jupiter.api.Test) IntegrationTest(com.hedera.mirror.importer.IntegrationTest) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ContractResult

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

the class ContractCallTransactionHandlerTest method updateContractResultEmptyContractCallFunctionParams.

@Test
void updateContractResultEmptyContractCallFunctionParams() {
    ContractResult contractResult = new ContractResult();
    var recordItem = recordItemBuilder.contractCall().build();
    transactionHandler.updateContractResult(contractResult, recordItem);
    var transaction = recordItem.getTransactionBody().getContractCall();
    assertThat(contractResult).returns(transaction.getAmount(), ContractResult::getAmount).returns(transaction.getGas(), ContractResult::getGasLimit).returns(DomainUtils.toBytes(transaction.getFunctionParameters()), ContractResult::getFunctionParameters);
}
Also used : ContractResult(com.hedera.mirror.common.domain.contract.ContractResult) Test(org.junit.jupiter.api.Test)

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