use of com.hederahashgraph.api.proto.java.ContractCallTransactionBody in project hedera-services by hashgraph.
the class ContractCallTransitionLogicTest method codeCacheThrowingExceptionDuringGetDoesntPropagate.
@Test
void codeCacheThrowingExceptionDuringGetDoesntPropagate() {
TransactionBody txnBody = Mockito.mock(TransactionBody.class);
ContractCallTransactionBody ccTxnBody = Mockito.mock(ContractCallTransactionBody.class);
given(accessor.getTxn()).willReturn(txnBody);
given(txnBody.getContractCall()).willReturn(ccTxnBody);
given(ccTxnBody.getContractID()).willReturn(IdUtils.asContract("0.0.1324"));
given(codeCache.getIfPresent(any(Address.class))).willThrow(new RuntimeException("oh no"));
// when:
assertDoesNotThrow(() -> subject.preFetch(accessor));
}
use of com.hederahashgraph.api.proto.java.ContractCallTransactionBody in project hedera-services by hashgraph.
the class HapiContractCall method opBodyDef.
@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
if (details.isPresent()) {
ActionableContractCall actionable = spec.registry().getActionableCall(details.get());
contract = actionable.getContract();
abi = actionable.getDetails().getAbi();
params = actionable.getDetails().getExampleArgs();
} else if (paramsFn.isPresent()) {
params = paramsFn.get().apply(spec);
}
byte[] callData;
if (explicitHexedParams.isPresent()) {
callData = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex).get();
} else {
final var paramsList = Arrays.asList(params);
final var tupleExist = paramsList.stream().anyMatch(p -> p instanceof Tuple || p instanceof Tuple[]);
if (tupleExist) {
callData = encodeParametersWithTuple(params);
} else {
callData = (!abi.equals(FALLBACK_ABI)) ? CallTransaction.Function.fromJsonInterface(abi).encode(params) : new byte[] {};
}
}
ContractCallTransactionBody opBody = spec.txns().<ContractCallTransactionBody, ContractCallTransactionBody.Builder>body(ContractCallTransactionBody.class, builder -> {
if (!tryAsHexedAddressIfLenMatches) {
builder.setContractID(spec.registry().getContractId(contract));
} else {
builder.setContractID(TxnUtils.asContractId(contract, spec));
}
builder.setFunctionParameters(ByteString.copyFrom(callData));
sentTinyHbars.ifPresent(builder::setAmount);
gas.ifPresent(builder::setGas);
});
return b -> b.setContractCall(opBody);
}
use of com.hederahashgraph.api.proto.java.ContractCallTransactionBody 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.hederahashgraph.api.proto.java.ContractCallTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallToNew.
@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToNew(ContractIdType contractIdType) {
// The contract is not in db, it should still work. Note for the create2 evm address,
// ContractCallTransactionHandler will get the correct plain contractId from the transaction record instead
// only cache the create2 evm address to verify it later
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, false, contractIdType == ContractIdType.CREATE2_EVM);
Transaction transaction = contractCallTransaction(setupResult.protoContractId);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
ContractCallTransactionBody contractCallTransactionBody = transactionBody.getContractCall();
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record));
}
use of com.hederahashgraph.api.proto.java.ContractCallTransactionBody in project hedera-mirror-node by hashgraph.
the class EntityRecordItemListenerContractTest method contractCallToExisting.
@ParameterizedTest
@EnumSource(ContractIdType.class)
void contractCallToExisting(ContractIdType contractIdType) {
SetupResult setupResult = setupContract(CONTRACT_ID, contractIdType, true, true);
// now call
Transaction transaction = contractCallTransaction(setupResult.protoContractId);
TransactionBody transactionBody = getTransactionBody(transaction);
TransactionRecord record = getContractTransactionRecord(transactionBody, ContractTransactionType.CALL);
ContractCallTransactionBody contractCallTransactionBody = transactionBody.getContractCall();
RecordItem recordItem = new RecordItem(transaction, record);
parseRecordItemAndCommit(recordItem);
assertAll(() -> assertEquals(1, transactionRepository.count()), () -> assertEquals(1, contractResultRepository.count()), () -> assertEquals(3, cryptoTransferRepository.count()), () -> assertEntities(EntityId.of(CONTRACT_ID), EntityId.of(CREATED_CONTRACT_ID)), () -> assertTransactionAndRecord(transactionBody, record), () -> assertContractCallResult(contractCallTransactionBody, record), () -> assertThat(contractRepository.findAll()).contains(setupResult.contract));
}
Aggregations