Search in sources :

Example 41 with HapiApiSpec

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

the class HapiTokenBurn method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var tId = TxnUtils.asTokenId(token, spec);
    TokenBurnTransactionBody opBody = spec.txns().<TokenBurnTransactionBody, TokenBurnTransactionBody.Builder>body(TokenBurnTransactionBody.class, b -> {
        b.setToken(tId);
        b.setAmount(amount);
        b.addAllSerialNumbers(serialNumbers);
    });
    return b -> b.setTokenBurn(opBody);
}
Also used : Transaction(com.hederahashgraph.api.proto.java.Transaction) TokenOpsUsage(com.hedera.services.usage.token.TokenOpsUsage) TOKEN_OPS_USAGE_UTILS(com.hedera.services.usage.token.TokenOpsUsageUtils.TOKEN_OPS_USAGE_UTILS) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Consumer(java.util.function.Consumer) BaseTransactionMeta(com.hedera.services.usage.BaseTransactionMeta) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) AdapterUtils(com.hedera.services.bdd.spec.fees.AdapterUtils) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) UsageAccumulator(com.hedera.services.usage.state.UsageAccumulator) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) SubType(com.hederahashgraph.api.proto.java.SubType) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody) SigValueObj(com.hederahashgraph.fee.SigValueObj) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) TokenBurnTransactionBody(com.hederahashgraph.api.proto.java.TokenBurnTransactionBody)

Example 42 with HapiApiSpec

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

the class HapiTokenDelete method opBodyDef.

@Override
protected Consumer<TransactionBody.Builder> opBodyDef(HapiApiSpec spec) throws Throwable {
    var tId = TxnUtils.asTokenId(token, spec);
    TokenDeleteTransactionBody opBody = spec.txns().<TokenDeleteTransactionBody, TokenDeleteTransactionBody.Builder>body(TokenDeleteTransactionBody.class, b -> {
        b.setToken(tId);
    });
    return b -> b.setTokenDeletion(opBody);
}
Also used : TokenDeleteUsage(com.hedera.services.usage.token.TokenDeleteUsage) Transaction(com.hederahashgraph.api.proto.java.Transaction) HapiTxnOp(com.hedera.services.bdd.spec.transactions.HapiTxnOp) FeeData(com.hederahashgraph.api.proto.java.FeeData) MoreObjects(com.google.common.base.MoreObjects) TokenDeleteTransactionBody(com.hederahashgraph.api.proto.java.TokenDeleteTransactionBody) SUCCESS(com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS) Function(java.util.function.Function) Consumer(java.util.function.Consumer) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) Logger(org.apache.logging.log4j.Logger) TxnUtils(com.hedera.services.bdd.spec.transactions.TxnUtils) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) TxnUtils.suFrom(com.hedera.services.bdd.spec.transactions.TxnUtils.suFrom) TransactionResponse(com.hederahashgraph.api.proto.java.TransactionResponse) SigValueObj(com.hederahashgraph.fee.SigValueObj) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) TokenDeleteTransactionBody(com.hederahashgraph.api.proto.java.TokenDeleteTransactionBody)

Example 43 with HapiApiSpec

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

the class HapiApiSuite method summarizeResults.

private void summarizeResults(Logger log) {
    if (getDeferResultsSummary()) {
        return;
    }
    log.info("-------------- STARTING " + name() + " SUITE --------------");
    log.info("-------------- RESULTS OF " + name() + " SUITE --------------");
    for (HapiApiSpec spec : finalSpecs) {
        log.info(spec);
    }
}
Also used : HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec)

Example 44 with HapiApiSpec

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

the class MacroFeesChargedSanityCheckSuite method renewalCappedByAffordablePeriod.

private HapiApiSpec renewalCappedByAffordablePeriod() {
    final long briefAutoRenew = 10L;
    final long normalAutoRenew = THREE_MONTHS_IN_SECONDS;
    final long threeHoursInSeconds = 3 * 3600L;
    final AtomicLong initialExpiry = new AtomicLong();
    final AtomicLong balanceForThreeHourRenew = new AtomicLong();
    final var target = "czar";
    final String crazyMemo = "Calmer than you are!";
    final ExtantCryptoContext cryptoCtx = ExtantCryptoContext.newBuilder().setCurrentExpiry(0L).setCurrentKey(Key.newBuilder().setEd25519(copyFromUtf8(randomUppercase(32))).build()).setCurrentlyHasProxy(true).setCurrentMemo(crazyMemo).setCurrentNumTokenRels(0).build();
    return defaultHapiSpec("RenewalCappedByAffordablePeriod").given(withOpContext((spec, opLog) -> {
        final var tbFee = autoRenewFeesFor(spec, cryptoCtx);
        balanceForThreeHourRenew.set(tbFee.totalTb(3));
        opLog.info("Balance {} will pay for three-hour renewal", balanceForThreeHourRenew.get());
    }), fileUpdate(APP_PROPERTIES).payingWith(GENESIS).overridingProps(enablingAutoRenewWith(1, 1234L)), sourcing(() -> cryptoCreate(target).entityMemo(crazyMemo).balance(balanceForThreeHourRenew.get()).autoRenewSecs(briefAutoRenew)), /* Despite asking for a three month autorenew here, the account will only
						be able to afford a three hour extension. */
    cryptoUpdate(target).autoRenewPeriod(normalAutoRenew), getAccountInfo(target).exposingExpiry(initialExpiry::set)).when(sleepFor(briefAutoRenew * 1_000L + 500L), cryptoTransfer(tinyBarsFromTo(DEFAULT_PAYER, FUNDING, 1L))).then(/* The account in question will have expired (and been auto-renewed);
						should only have received a three-hour renewal, and its entire balance
						been used. */
    getAccountBalance(target).hasTinyBars(0L), sourcing(() -> getAccountInfo(target).has(accountWith().expiry(initialExpiry.get() + threeHoursInSeconds, 0L))), cryptoDelete(target));
}
Also used : UtilVerbs.runWithProvider(com.hedera.services.bdd.spec.utilops.UtilVerbs.runWithProvider) ByteString.copyFromUtf8(com.google.protobuf.ByteString.copyFromUtf8) TxnVerbs.cryptoCreate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate) UtilVerbs.sourcing(com.hedera.services.bdd.spec.utilops.UtilVerbs.sourcing) UtilVerbs.withOpContext(com.hedera.services.bdd.spec.utilops.UtilVerbs.withOpContext) ExchangeRate(com.hederahashgraph.api.proto.java.ExchangeRate) AutoRenewConfigChoices.enablingAutoRenewWith(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.enablingAutoRenewWith) TxnVerbs.cryptoTransfer(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer) FeeBuilder.getTinybarsFromTinyCents(com.hederahashgraph.fee.FeeBuilder.getTinybarsFromTinyCents) TxnVerbs.fileUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.fileUpdate) CRYPTO_ENTITY_SIZES(com.hedera.services.usage.crypto.entities.CryptoEntitySizes.CRYPTO_ENTITY_SIZES) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) AccountInfoAsserts.accountWith(com.hedera.services.bdd.spec.assertions.AccountInfoAsserts.accountWith) TxnVerbs.cryptoUpdate(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoUpdate) UtilVerbs.sleepFor(com.hedera.services.bdd.spec.utilops.UtilVerbs.sleepFor) QueryVerbs.getAccountInfo(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo) HapiApiSuite(com.hedera.services.bdd.suites.HapiApiSuite) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TxnVerbs.cryptoDelete(com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoDelete) FEE_DIVISOR_FACTOR(com.hederahashgraph.fee.FeeBuilder.FEE_DIVISOR_FACTOR) HapiApiSpec.defaultHapiSpec(com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec) AutoRenewConfigChoices.disablingAutoRenewWithDefaults(com.hedera.services.bdd.suites.autorenew.AutoRenewConfigChoices.disablingAutoRenewWithDefaults) HapiCryptoTransfer.tinyBarsFromTo(com.hedera.services.bdd.spec.transactions.crypto.HapiCryptoTransfer.tinyBarsFromTo) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) QueryVerbs.getAccountBalance(com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Key(com.hederahashgraph.api.proto.java.Key) List(java.util.List) CryptoAccountAutoRenew(com.hederahashgraph.api.proto.java.HederaFunctionality.CryptoAccountAutoRenew) Logger(org.apache.logging.log4j.Logger) UtilVerbs.assertionsHold(com.hedera.services.bdd.spec.utilops.UtilVerbs.assertionsHold) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Assertions(org.junit.jupiter.api.Assertions) TxnUtils.randomUppercase(com.hedera.services.bdd.spec.transactions.TxnUtils.randomUppercase) Optional(java.util.Optional) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) AtomicLong(java.util.concurrent.atomic.AtomicLong) ExtantCryptoContext(com.hedera.services.usage.crypto.ExtantCryptoContext)

Example 45 with HapiApiSpec

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

the class ProviderRun method submitOp.

@Override
protected boolean submitOp(HapiApiSpec spec) {
    int MAX_N = Runtime.getRuntime().availableProcessors();
    int MAX_OPS_PER_SEC = maxOpsPerSecSupplier.getAsInt();
    int MAX_PENDING_OPS = maxPendingOpsSupplier.getAsInt();
    int BACKOFF_SLEEP_SECS = backoffSleepSecsSupplier.getAsInt();
    long duration = durationSupplier.getAsLong();
    OpProvider provider = providerFn.apply(spec);
    allRunFor(spec, provider.suggestedInitializers().toArray(new HapiSpecOperation[0]));
    log.info("Finished initialization for provider run...");
    TimeUnit unit = unitSupplier.get();
    Stopwatch stopwatch = Stopwatch.createStarted();
    final var remainingOpsToSubmit = new AtomicInteger(totalOpsToSubmit.getAsInt());
    final boolean fixedOpSubmission = (remainingOpsToSubmit.get() < 0) ? false : true;
    int submittedSoFar = 0;
    long durationMs = unit.toMillis(duration);
    long logIncrementMs = durationMs / 100;
    long nextLogTargetMs = logIncrementMs;
    long lastDeltaLogged = -1;
    final var opsThisSecond = new AtomicInteger(0);
    final var submissionBoundaryMs = new AtomicLong(stopwatch.elapsed(MILLISECONDS) + 1_000);
    while (stopwatch.elapsed(unit) < duration) {
        long elapsedMs = stopwatch.elapsed(MILLISECONDS);
        if (elapsedMs > submissionBoundaryMs.get()) {
            submissionBoundaryMs.getAndAdd(1_000);
            opsThisSecond.set(0);
        }
        int numPending = spec.numPendingOps();
        if (elapsedMs > nextLogTargetMs) {
            nextLogTargetMs += logIncrementMs;
            long delta = duration - stopwatch.elapsed(unit);
            if (delta != lastDeltaLogged) {
                log.info(delta + " " + unit.toString().toLowerCase() + (fixedOpSubmission ? (" or " + remainingOpsToSubmit + " ops ") : "") + " left in test - " + submittedSoFar + " ops submitted so far (" + numPending + " pending).");
                log.info("Precheck txn status counts :: " + spec.precheckStatusCounts());
                log.info("Resolved txn status counts :: " + spec.finalizedStatusCounts());
                log.info("\n------------------------------\n");
                lastDeltaLogged = delta;
            }
        }
        if (fixedOpSubmission && remainingOpsToSubmit.get() <= 0) {
            if (numPending > 0) {
                continue;
            }
            log.info("Finished submission of total {} operations", totalOpsToSubmit.getAsInt());
            break;
        }
        if (numPending < MAX_PENDING_OPS) {
            HapiSpecOperation[] burst = IntStream.range(0, Math.min(MAX_N, fixedOpSubmission ? Math.min(remainingOpsToSubmit.get(), MAX_OPS_PER_SEC - opsThisSecond.get()) : MAX_OPS_PER_SEC - opsThisSecond.get())).mapToObj(ignore -> provider.get()).flatMap(Optional::stream).peek(op -> counts.get(op.type()).getAndIncrement()).toArray(HapiSpecOperation[]::new);
            if (burst.length > 0) {
                allRunFor(spec, inParallel(burst));
                submittedSoFar += burst.length;
                if (fixedOpSubmission) {
                    remainingOpsToSubmit.getAndAdd(-burst.length);
                }
                opsThisSecond.getAndAdd(burst.length);
            }
        } else {
            log.warn("Now " + numPending + " ops pending; backing off for " + BACKOFF_SLEEP_SECS + "s!");
            try {
                Thread.sleep(BACKOFF_SLEEP_SECS * 1_000L);
            } catch (InterruptedException ignore) {
            }
        }
    }
    Map<HederaFunctionality, Integer> finalCounts = counts.entrySet().stream().filter(entry -> entry.getValue().get() > 0).collect(Collectors.toMap(Map.Entry::getKey, entry -> entry.getValue().get()));
    log.info("Final breakdown of *provided* ops: " + finalCounts);
    log.info("Final breakdown of *resolved* statuses: " + spec.finalizedStatusCounts());
    return false;
}
Also used : IntStream(java.util.stream.IntStream) LongSupplier(java.util.function.LongSupplier) Stopwatch(com.google.common.base.Stopwatch) HashMap(java.util.HashMap) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) CustomSpecAssert.allRunFor(com.hedera.services.bdd.spec.utilops.CustomSpecAssert.allRunFor) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) UtilVerbs.inParallel(com.hedera.services.bdd.spec.utilops.UtilVerbs.inParallel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Map(java.util.Map) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) Optional(java.util.Optional) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) LogManager(org.apache.logging.log4j.LogManager) IntSupplier(java.util.function.IntSupplier) HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Optional(java.util.Optional) Stopwatch(com.google.common.base.Stopwatch) OpProvider(com.hedera.services.bdd.spec.infrastructure.OpProvider) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HapiSpecOperation(com.hedera.services.bdd.spec.HapiSpecOperation) TimeUnit(java.util.concurrent.TimeUnit) HashMap(java.util.HashMap) Map(java.util.Map)

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