Search in sources :

Example 1 with ContractCallTransactionBody

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));
}
Also used : TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Address(org.hyperledger.besu.datatypes.Address) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Test(org.junit.jupiter.api.Test)

Example 2 with ContractCallTransactionBody

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);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) Arrays(java.util.Arrays) TrieSigMapGenerator.uniqueWithFullPrefixesFor(com.hedera.services.bdd.spec.keys.TrieSigMapGenerator.uniqueWithFullPrefixesFor) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) CallTransaction(org.ethereum.core.CallTransaction) Function(java.util.function.Function) Supplier(java.util.function.Supplier) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ArrayList(java.util.ArrayList) Tuple(com.esaulpaugh.headlong.abi.Tuple) QueryVerbs.getTxnRecord(com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) HashUtil.sha3(org.ethereum.crypto.HashUtil.sha3) GENESIS(com.hedera.services.bdd.suites.HapiApiSuite.GENESIS) TupleType(com.esaulpaugh.headlong.abi.TupleType) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) MoreObjects(com.google.common.base.MoreObjects) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CommonUtils(com.swirlds.common.CommonUtils) ByteUtil(org.ethereum.util.ByteUtil) ObjLongConsumer(java.util.function.ObjLongConsumer) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) TxnUtils.extractTxnId(com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Collections(java.util.Collections) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) CommonUtils(com.swirlds.common.CommonUtils) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) Tuple(com.esaulpaugh.headlong.abi.Tuple)

Example 3 with ContractCallTransactionBody

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);
}
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 4 with ContractCallTransactionBody

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));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ContractCallTransactionBody

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));
}
Also used : ContractUpdateTransactionBody(com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Transaction(com.hederahashgraph.api.proto.java.Transaction) ContractCallTransactionBody(com.hederahashgraph.api.proto.java.ContractCallTransactionBody) TransactionRecord(com.hederahashgraph.api.proto.java.TransactionRecord) RecordItem(com.hedera.mirror.common.domain.transaction.RecordItem) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)7 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)6 Transaction (com.hederahashgraph.api.proto.java.Transaction)5 RecordItem (com.hedera.mirror.common.domain.transaction.RecordItem)4 ContractCreateTransactionBody (com.hederahashgraph.api.proto.java.ContractCreateTransactionBody)4 ContractUpdateTransactionBody (com.hederahashgraph.api.proto.java.ContractUpdateTransactionBody)4 TransactionRecord (com.hederahashgraph.api.proto.java.TransactionRecord)4 ByteString (com.google.protobuf.ByteString)3 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 Range (com.google.common.collect.Range)2 BytesValue (com.google.protobuf.BytesValue)2 Int32Value (com.google.protobuf.Int32Value)2 StringValue (com.google.protobuf.StringValue)2 AccountIdConverter (com.hedera.mirror.common.converter.AccountIdConverter)2 Contract (com.hedera.mirror.common.domain.contract.Contract)2 ContractLog (com.hedera.mirror.common.domain.contract.ContractLog)2 ContractResult (com.hedera.mirror.common.domain.contract.ContractResult)2 ContractStateChange (com.hedera.mirror.common.domain.contract.ContractStateChange)2