use of com.hedera.mirror.common.domain.contract.ContractLog 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);
}
use of com.hedera.mirror.common.domain.contract.ContractLog in project hedera-mirror-node by hashgraph.
the class ContractLogRepositoryTest method save.
@Test
void save() {
ContractLog contractLog = domainBuilder.contractLog().persist();
assertThat(contractLogRepository.findById(contractLog.getId())).get().isEqualTo(contractLog);
}
use of com.hedera.mirror.common.domain.contract.ContractLog in project hedera-mirror-node by hashgraph.
the class ContractResultServiceImpl method processContractLogs.
private void processContractLogs(ContractFunctionResult functionResult, ContractResult contractResult) {
for (int index = 0; index < functionResult.getLogInfoCount(); ++index) {
ContractLoginfo contractLoginfo = functionResult.getLogInfo(index);
ContractLog contractLog = new ContractLog();
contractLog.setBloom(DomainUtils.toBytes(contractLoginfo.getBloom()));
contractLog.setConsensusTimestamp(contractResult.getConsensusTimestamp());
contractLog.setContractId(lookup(contractResult.getContractId(), contractLoginfo.getContractID()));
contractLog.setData(DomainUtils.toBytes(contractLoginfo.getData()));
contractLog.setIndex(index);
contractLog.setRootContractId(contractResult.getContractId());
contractLog.setPayerAccountId(contractResult.getPayerAccountId());
contractLog.setTopic0(Utility.getTopic(contractLoginfo, 0));
contractLog.setTopic1(Utility.getTopic(contractLoginfo, 1));
contractLog.setTopic2(Utility.getTopic(contractLoginfo, 2));
contractLog.setTopic3(Utility.getTopic(contractLoginfo, 3));
entityListener.onContractLog(contractLog);
}
}
use of com.hedera.mirror.common.domain.contract.ContractLog in project hedera-mirror-node by hashgraph.
the class SqlEntityListenerTest method onContractLog.
@Test
void onContractLog() {
// given
ContractLog contractLog = domainBuilder.contractLog().get();
// when
sqlEntityListener.onContractLog(contractLog);
completeFileAndCommit();
// then
assertThat(contractLogRepository.findAll()).containsExactlyInAnyOrder(contractLog);
}
Aggregations