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());
}
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);
}
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);
}
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);
}
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);
}
Aggregations