Search in sources :

Example 96 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class HapiContractCreate method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    if (!omitAdminKey && !useDeprecatedAdminKey) {
        generateAdminKey(spec);
    }
    if (bytecodeFileFn.isPresent()) {
        bytecodeFile = Optional.of(bytecodeFileFn.get().get());
    }
    if (!bytecodeFile.isPresent()) {
        setBytecodeToDefaultContract(spec);
    }
    Optional<byte[]> params;
    if (explicitHexedParams.isPresent()) {
        params = explicitHexedParams.map(Supplier::get).map(CommonUtils::unhex);
    } else {
        params = abi.isPresent() ? Optional.of(CallTransaction.Function.fromJsonInterface(abi.get()).encodeArguments(args.get())) : Optional.empty();
    }
    FileID bytecodeFileId = TxnUtils.asFileId(bytecodeFile.get(), spec);
    ContractCreateTransactionBody opBody = spec.txns().<ContractCreateTransactionBody, ContractCreateTransactionBody.Builder>body(ContractCreateTransactionBody.class, b -> {
        if (useDeprecatedAdminKey) {
            b.setAdminKey(DEPRECATED_CID_ADMIN_KEY);
        } else if (!omitAdminKey) {
            b.setAdminKey(adminKey);
        }
        b.setFileID(bytecodeFileId);
        autoRenewPeriodSecs.ifPresent(p -> b.setAutoRenewPeriod(Duration.newBuilder().setSeconds(p).build()));
        balance.ifPresent(b::setInitialBalance);
        memo.ifPresent(b::setMemo);
        gas.ifPresent(b::setGas);
        proxy.ifPresent(p -> b.setProxyAccountID(asId(p, spec)));
        params.ifPresent(bytes -> b.setConstructorParameters(ByteString.copyFrom(bytes)));
    });
    return b -> b.setContractCreateInstance(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) SigControl(com.hedera.services.bdd.spec.keys.SigControl) HapiFileCreate(com.hedera.services.bdd.spec.transactions.file.HapiFileCreate) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) ContractGetInfoResponse(com.hederahashgraph.api.proto.java.ContractGetInfoResponse) CallTransaction(org.ethereum.core.CallTransaction) HapiContractCall.doGasLookup(com.hedera.services.bdd.spec.transactions.contract.HapiContractCall.doGasLookup) Duration(com.hederahashgraph.api.proto.java.Duration) Function(java.util.function.Function) Supplier(java.util.function.Supplier) HapiSpecRegistry(com.hedera.services.bdd.spec.infrastructure.HapiSpecRegistry) TxnVerbs(com.hedera.services.bdd.spec.transactions.TxnVerbs) ContractID(com.hederahashgraph.api.proto.java.ContractID) OptionalLong(java.util.OptionalLong) TxnUtils.asId(com.hedera.services.bdd.spec.transactions.TxnUtils.asId) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TxnUtils.solidityIdFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.solidityIdFrom) FileID(com.hederahashgraph.api.proto.java.FileID) TxnUtils.equivAccount(com.hedera.services.bdd.spec.transactions.TxnUtils.equivAccount) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) KeyGenerator(com.hedera.services.bdd.spec.keys.KeyGenerator) MoreObjects(com.google.common.base.MoreObjects) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) LongConsumer(java.util.function.LongConsumer) ByteString(com.google.protobuf.ByteString) KeyFactory(com.hedera.services.bdd.spec.keys.KeyFactory) Consumer(java.util.function.Consumer) TxnFactory.bannerWith(com.hedera.services.bdd.spec.transactions.TxnFactory.bannerWith) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) CommonUtils(com.swirlds.common.CommonUtils) ObjLongConsumer(java.util.function.ObjLongConsumer) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) ContractCreateTransactionBody(com.hederahashgraph.api.proto.java.ContractCreateTransactionBody) Supplier(java.util.function.Supplier) FileID(com.hederahashgraph.api.proto.java.FileID)

Example 97 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class CryptoTransferLoadTestWithInvalidAccounts method runCryptoTransfers.

protected HapiApiSpec runCryptoTransfers() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    Supplier<HapiSpecOperation[]> transferBurst = () -> {
        return new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromTo("0.0.1000000001", "0.0.1000000002", 1L)).noLogging().signedBy(GENESIS).suppressStats(true).fee(100_000_000L).hasKnownStatusFrom(INVALID_ACCOUNT_ID).hasRetryPrecheckFrom(BUSY, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
    };
    return defaultHapiSpec("RunCryptoTransfers").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when().then(defaultLoadTest(transferBurst, settings));
}
Also used : LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) Supplier(java.util.function.Supplier) INVALID_ACCOUNT_ID(com.hederahashgraph.api.proto.java.ResponseCodeEnum.INVALID_ACCOUNT_ID) List(java.util.List) Logger(org.apache.logging.log4j.Logger) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) BUSY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PLATFORM_TRANSACTION_NOT_CREATED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings)

Example 98 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class FileExpansionLoadProvider method fileExpansionsFactory.

private Function<HapiApiSpec, OpProvider> fileExpansionsFactory() {
    final SplittableRandom r = new SplittableRandom();
    final Set<String> usableTargets = ConcurrentHashMap.newKeySet();
    final LongFunction<String> targetNameFn = i -> "expandingFile" + i;
    final AtomicInteger nextTargetNum = new AtomicInteger(numActiveTargets.get());
    final var key = "multi";
    final var waclShape = KeyShape.listOf(SIMPLE, threshOf(1, 3), listOf(2));
    return spec -> new OpProvider() {

        @Override
        public List<HapiSpecOperation> suggestedInitializers() {
            final List<HapiSpecOperation> ops = new ArrayList<>();
            ops.add(newKeyNamed(key).shape(waclShape));
            for (int i = 0, n = numActiveTargets.get(); i < n; i++) {
                ops.add(fileCreate(targetNameFn.apply(i)).key(key).noLogging().contents(DATA_CHUNK).payingWith(GENESIS));
            }
            return ops;
        }

        @Override
        public Optional<HapiSpecOperation> get() {
            HapiSpecOperation op;
            if (usableTargets.size() < numActiveTargets.get()) {
                final var name = targetNameFn.apply(nextTargetNum.getAndIncrement());
                op = fileCreate(name).noLogging().key(key).contents(DATA_CHUNK).payingWith(GENESIS).deferStatusResolution().exposingNumTo(num -> {
                    usableTargets.add(name);
                });
            } else {
                final var skips = r.nextInt(usableTargets.size());
                final var iter = usableTargets.iterator();
                try {
                    for (int i = 0; i < skips; i++) {
                        iter.next();
                    }
                    final var target = iter.next();
                    op = fileAppend(target).noLogging().deferStatusResolution().payingWith(GENESIS).content(DATA_CHUNK).hasKnownStatusFrom(MAX_FILE_SIZE_EXCEEDED, SUCCESS).alertingPost(code -> {
                        if (code == MAX_FILE_SIZE_EXCEEDED) {
                            log.info("File {} reached max size, no longer in rotation", target);
                            usableTargets.remove(target);
                        }
                    });
                } catch (Exception ignore) {
                    op = noOp();
                }
            }
            return Optional.of(op);
        }
    };
}
Also used : UtilVerbs.overriding(com.hedera.services.bdd.spec.utilops.UtilVerbs.overriding) UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) MINUTES(java.util.concurrent.TimeUnit.MINUTES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) ArrayList(java.util.ArrayList) KeyShape.listOf(com.hedera.services.bdd.spec.keys.KeyShape.listOf) PerfUtilOps.stdMgmtOf(com.hedera.services.bdd.suites.perf.PerfUtilOps.stdMgmtOf) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) KeyShape(com.hedera.services.bdd.spec.keys.KeyShape) SplittableRandom(java.util.SplittableRandom) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) MAX_FILE_SIZE_EXCEEDED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.MAX_FILE_SIZE_EXCEEDED) LongFunction(java.util.function.LongFunction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) UtilVerbs.newKeyNamed(com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) KeyShape.threshOf(com.hedera.services.bdd.spec.keys.KeyShape.threshOf) TimeUnit(java.util.concurrent.TimeUnit) SIMPLE(com.hedera.services.bdd.spec.keys.KeyShape.SIMPLE) AtomicLong(java.util.concurrent.atomic.AtomicLong) UtilVerbs.noOp(com.hedera.services.bdd.spec.utilops.UtilVerbs.noOp) List(java.util.List) HapiSpecSetup.getDefaultNodeProps(com.hedera.services.bdd.spec.HapiSpecSetup.getDefaultNodeProps) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) BYTES_4K(com.hedera.services.bdd.spec.transactions.TxnUtils.BYTES_4K) PerfUtilOps.mgmtOfIntProp(com.hedera.services.bdd.suites.perf.PerfUtilOps.mgmtOfIntProp) ArrayList(java.util.ArrayList) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) SplittableRandom(java.util.SplittableRandom)

Example 99 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class FileUpdateLoadTest method runFileUpdates.

private HapiApiSpec runFileUpdates() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    final AtomicInteger submittedSoFar = new AtomicInteger(0);
    final byte[] NEW_CONTENTS = TxnUtils.randomUtf8Bytes(TxnUtils.BYTES_4K);
    Supplier<HapiSpecOperation[]> fileUpdateBurst = () -> new HapiSpecOperation[] { inParallel(IntStream.range(0, settings.getBurstSize()).mapToObj(i -> TxnVerbs.fileUpdate("target").fee(Integer.MAX_VALUE).contents(NEW_CONTENTS).noLogging().hasPrecheckFrom(OK, BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution()).toArray(n -> new HapiSpecOperation[n])), logIt(ignore -> String.format("Now a total of %d file updates submitted.", submittedSoFar.addAndGet(settings.getBurstSize()))) };
    return defaultHapiSpec("RunFileUpdates").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(fileCreate("target").contents("The initial contents!")).then(runLoadTest(fileUpdateBurst).tps(settings::getTps).tolerance(settings::getTolerancePercentage).allowedSecsBelow(settings::getAllowedSecsBelow).lasting(settings::getMins, () -> MINUTES));
}
Also used : IntStream(java.util.stream.IntStream) OK(com.hederahashgraph.api.proto.java.ResponseCodeEnum.OK) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UtilVerbs.runLoadTest(com.hedera.services.bdd.spec.utilops.UtilVerbs.runLoadTest) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) Supplier(java.util.function.Supplier) TxnVerbs(com.hedera.services.bdd.spec.transactions.TxnVerbs) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) DUPLICATE_TRANSACTION(com.hederahashgraph.api.proto.java.ResponseCodeEnum.DUPLICATE_TRANSACTION) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) BUSY(com.hederahashgraph.api.proto.java.ResponseCodeEnum.BUSY) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PLATFORM_TRANSACTION_NOT_CREATED(com.hederahashgraph.api.proto.java.ResponseCodeEnum.PLATFORM_TRANSACTION_NOT_CREATED) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Example 100 with HapiApiSpec

use of com.hedera.services.bdd.spec.HapiApiSpec in project hedera-services by hashgraph.

the class MixedFileOpsLoadTest method runMixedFileOps.

protected HapiApiSpec runMixedFileOps() {
    PerfTestLoadSettings settings = new PerfTestLoadSettings();
    final AtomicInteger submittedSoFar = new AtomicInteger(0);
    String initialContent = "The initial contents!";
    String targetFile = "targetFile";
    Supplier<HapiSpecOperation[]> mixedFileOpsBurst = () -> new HapiSpecOperation[] { fileCreate(targetFile + submittedSoFar.getAndIncrement()).contents(initialContent).hasKnownStatusFrom(SUCCESS, UNKNOWN), fileUpdate(targetFile).fee(ONE_HUNDRED_HBARS).contents(TxnUtils.randomUtf8Bytes(TxnUtils.BYTES_4K)).noLogging().payingWith(GENESIS).hasAnyPrecheck().hasKnownStatusFrom(SUCCESS, UNKNOWN).deferStatusResolution(), fileAppend(targetFile).content("dummy").hasAnyPrecheck().payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).hasKnownStatusFrom(SUCCESS, UNKNOWN).deferStatusResolution() };
    return defaultHapiSpec("runMixedFileOps").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(fileCreate(targetFile).contents(initialContent).hasAnyPrecheck().payingWith(GENESIS), getFileInfo(targetFile).logging().payingWith(GENESIS)).then(defaultLoadTest(mixedFileOpsBurst, settings));
}
Also used : LoadTest(com.hedera.services.bdd.spec.utilops.LoadTest) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) UNKNOWN(com.hederahashgraph.api.proto.java.ResponseCodeEnum.UNKNOWN) UtilVerbs.logIt(com.hedera.services.bdd.spec.utilops.UtilVerbs.logIt) QueryVerbs.getFileInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getFileInfo) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Supplier(java.util.function.Supplier) List(java.util.List) TxnVerbs.fileCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate) Logger(org.apache.logging.log4j.Logger) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) TxnVerbs.fileAppend(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileAppend) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) PerfTestLoadSettings(com.hedera.services.bdd.suites.perf.PerfTestLoadSettings) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation)

Aggregations

HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)140 List (java.util.List)134 LogManager (org.apache.logging.log4j.LogManager)125 Logger (org.apache.logging.log4j.Logger)125 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)84 UtilVerbs.withOpContext (com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext)78 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)76 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)69 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)65 Function (java.util.function.Function)63 HapiSpecOperation (com.hedera.services.bdd.spec.HapiSpecOperation)58 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)56 ByteString (com.google.protobuf.ByteString)53 Key (com.hederahashgraph.api.proto.java.Key)52 CustomSpecAssert.allRunFor (com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor)51 Optional (java.util.Optional)50 UtilVerbs.newKeyNamed (com.hedera.services.bdd.spec.utilops.UtilVerbs.newKeyNamed)49 Consumer (java.util.function.Consumer)49 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)47 TxnVerbs.fileCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.fileCreate)46