Search in sources :

Example 1 with ActionableContractCall

use of com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall in project hedera-services by hashgraph.

the class RandomContract method get.

@Override
public Optional<HapiSpecOperation> get() {
    if (contracts.numPresent() >= ceilingNum) {
        return Optional.empty();
    }
    Optional<String> key = keys.getQualifying();
    if (key.isEmpty()) {
        return Optional.empty();
    }
    int n = opNo.getAndIncrement();
    final String tentativeContract = my("contract" + n);
    final SupportedContract choice = choices[n % choices.length];
    HapiContractCreate op = contractCreate(tentativeContract).adminKey(key.get()).bytecode(fileFor(choice)).skipAccountRegistration().hasPrecheckFrom(STANDARD_PERMISSIBLE_PRECHECKS).hasKnownStatusFrom(permissibleOutcomes).uponSuccess(registry -> {
        registry.saveContractChoice(tentativeContract, choice);
        AtomicInteger tag = new AtomicInteger();
        choice.getCallDetails().forEach(detail -> {
            ActionableContractCall call = new ActionableContractCall(tentativeContract, detail);
            registry.saveActionableCall(tentativeContract + "-" + tag.getAndIncrement(), call);
        });
        choice.getLocalCallDetails().forEach(detail -> {
            ActionableContractCallLocal call = new ActionableContractCallLocal(tentativeContract, detail);
            registry.saveActionableLocalCall(tentativeContract + "-" + tag.getAndIncrement(), call);
        });
    });
    return Optional.of(op);
}
Also used : SupportedContract(com.hedera.services.bdd.spec.infrastructure.meta.SupportedContract) ActionableContractCall(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActionableContractCallLocal(com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCallLocal) HapiContractCreate(com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate)

Example 2 with ActionableContractCall

use of com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall 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)

Aggregations

ActionableContractCall (com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCall)2 Tuple (com.esaulpaugh.headlong.abi.Tuple)1 TupleType (com.esaulpaugh.headlong.abi.TupleType)1 DeserializationFeature (com.fasterxml.jackson.databind.DeserializationFeature)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MoreObjects (com.google.common.base.MoreObjects)1 ByteString (com.google.protobuf.ByteString)1 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)1 ActionableContractCallLocal (com.hedera.services.bdd.spec.infrastructure.meta.ActionableContractCallLocal)1 SupportedContract (com.hedera.services.bdd.spec.infrastructure.meta.SupportedContract)1 TrieSigMapGenerator.uniqueWithFullPrefixesFor (com.hedera.services.bdd.spec.keys.TrieSigMapGenerator.uniqueWithFullPrefixesFor)1 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)1 HapiTxnOp (com.hedera.services.bdd.spec.transactions.HapiTxnOp)1 TxnUtils (com.hedera.services.bdd.spec.transactions.TxnUtils)1 TxnUtils.extractTxnId (com.hedera.services.bdd.spec.transactions.TxnUtils.extractTxnId)1 HapiContractCreate (com.hedera.services.bdd.spec.transactions.contract.HapiContractCreate)1 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)1 GENESIS (com.hedera.services.bdd.suites.HapiApiSuite.GENESIS)1 ContractCallTransactionBody (com.hederahashgraph.api.proto.java.ContractCallTransactionBody)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1