Search in sources :

Example 1 with ContractStateChange

use of com.hedera.mirror.common.domain.contract.ContractStateChange 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 2 with ContractStateChange

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

the class SqlEntityListenerTest method onContractStateChange.

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

Example 3 with ContractStateChange

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

the class ContractStateChangeRepositoryTest method save.

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

Example 4 with ContractStateChange

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

the class ContractResultServiceImpl method processContractStateChanges.

private void processContractStateChanges(ContractFunctionResult functionResult, ContractResult contractResult) {
    for (var stateChange : functionResult.getStateChangesList()) {
        var contractId = lookup(contractResult.getContractId(), stateChange.getContractID());
        for (var storageChange : stateChange.getStorageChangesList()) {
            ContractStateChange contractStateChange = new ContractStateChange();
            contractStateChange.setConsensusTimestamp(contractResult.getConsensusTimestamp());
            contractStateChange.setContractId(contractId);
            contractStateChange.setPayerAccountId(contractResult.getPayerAccountId());
            contractStateChange.setSlot(DomainUtils.toBytes(storageChange.getSlot()));
            contractStateChange.setValueRead(DomainUtils.toBytes(storageChange.getValueRead()));
            // absent. If a value was read and not written this value will not be present.
            if (storageChange.hasValueWritten()) {
                contractStateChange.setValueWritten(DomainUtils.toBytes(storageChange.getValueWritten().getValue()));
            }
            entityListener.onContractStateChange(contractStateChange);
        }
    }
}
Also used : ContractStateChange(com.hedera.mirror.common.domain.contract.ContractStateChange)

Aggregations

ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)4 Test (org.junit.jupiter.api.Test)2 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)1 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)1 EntityId (com.hedera.mirror.common.domain.entity.EntityId)1 IntegrationTest (com.hedera.mirror.importer.IntegrationTest)1 ContractLoginfo (com.hederahashgraph.api.proto.java.ContractLoginfo)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1