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);
}
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);
}
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);
}
}
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));
}
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;
}
Aggregations