use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class CreateAccountsBeforeReconnect method runCreateAccounts.
private HapiApiSpec runCreateAccounts() {
PerfTestLoadSettings settings = new PerfTestLoadSettings(ACCOUNT_CREATION_RECONNECT_TPS, DEFAULT_MINS_FOR_RECONNECT_TESTS, DEFAULT_THREADS_FOR_RECONNECT_TESTS);
Supplier<HapiSpecOperation[]> createBurst = () -> new HapiSpecOperation[] { generateCreateAccountOperation() };
return defaultHapiSpec("RunCreateAccounts").given(logIt(ignore -> settings.toString())).when().then(defaultLoadTest(createBurst, settings));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class ValidateCongestionPricingAfterReconnect method validateCongestionPricing.
private HapiApiSpec validateCongestionPricing() {
var artificialLimits = protoDefsFromResource("testSystemFiles/artificial-limits-6N.json");
var defaultThrottles = protoDefsFromResource("testSystemFiles/throttles-dev.json");
String tmpMinCongestionPeriodInSecs = "5";
String civilianAccount = "civilian";
String oneContract = "contract";
AtomicLong normalPrice = new AtomicLong();
AtomicLong tenXPrice = new AtomicLong();
return customHapiSpec("ValidateCongestionPricing").withProperties(Map.of("txn.start.offset.secs", "-5")).given(sleepFor(Duration.ofSeconds(25).toMillis()), cryptoCreate(civilianAccount).payingWith(GENESIS).balance(ONE_MILLION_HBARS), fileCreate("bytecode").path(ContractResources.MULTIPURPOSE_BYTECODE_PATH).payingWith(GENESIS), contractCreate(oneContract).bytecode("bytecode").payingWith(GENESIS).logging(), contractCall(oneContract).payingWith(civilianAccount).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("cheapCallBeforeCongestionPricing"), getTxnRecord("cheapCallBeforeCongestionPricing").providingFeeTo(normalPrice::set), getAccountBalance(GENESIS).setNode(reconnectingNode).unavailableNode()).when(/* update the multiplier to 10x with a 1% congestion for tmpMinCongestionPeriodInSecs */
fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", "1,10x", "fees.minCongestionPeriod", tmpMinCongestionPeriodInSecs)), fileUpdate(THROTTLE_DEFS).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).contents(artificialLimits.toByteArray()), blockingOrder(IntStream.range(0, 20).mapToObj(i -> contractCall(oneContract).payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR)).toArray(HapiSpecOperation[]::new))).then(withLiveNode(reconnectingNode).within(5 * 60, TimeUnit.SECONDS).loggingAvailabilityEvery(30).sleepingBetweenRetriesFor(10), blockingOrder(IntStream.range(0, 10).mapToObj(i -> contractCall(oneContract).payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).setNode(reconnectingNode)).toArray(HapiSpecOperation[]::new)), contractCall(oneContract).payingWith(civilianAccount).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("pricyCallAfterReconnect").setNode(reconnectingNode), getTxnRecord("pricyCallAfterReconnect").payingWith(GENESIS).providingFeeTo(tenXPrice::set).setNode(reconnectingNode), /* check if the multiplier took effect in the contract call operation */
withOpContext((spec, opLog) -> {
Assertions.assertEquals(10.0, (1.0 * tenXPrice.get()) / normalPrice.get(), 0.1, "~10x multiplier should be in affect!");
}), /* revert the multiplier before test ends */
fileUpdate(THROTTLE_DEFS).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).contents(defaultThrottles.toByteArray()).setNode(reconnectingNode), fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", defaultCongestionMultipliers, "fees.minCongestionPeriod", defaultMinCongestionPeriod)), cryptoTransfer(HapiCryptoTransfer.tinyBarsFromTo(GENESIS, FUNDING, 1)).payingWith(GENESIS));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class CongestionPricingSuite method canUpdateMultipliersDynamically.
private HapiApiSpec canUpdateMultipliersDynamically() {
var artificialLimits = protoDefsFromResource("testSystemFiles/artificial-limits.json");
var defaultThrottles = protoDefsFromResource("testSystemFiles/throttles-dev.json");
String tmpMinCongestionPeriod = "1";
AtomicLong normalPrice = new AtomicLong();
AtomicLong sevenXPrice = new AtomicLong();
return defaultHapiSpec("CanUpdateMultipliersDynamically").given(cryptoCreate("civilian").payingWith(GENESIS).balance(ONE_MILLION_HBARS), fileCreate("bytecode").path(ContractResources.MULTIPURPOSE_BYTECODE_PATH).payingWith(GENESIS), contractCreate("scMulti").bytecode("bytecode").payingWith(GENESIS), contractCall("scMulti").payingWith("civilian").fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("cheapCall"), getTxnRecord("cheapCall").providingFeeTo(normalFee -> {
log.info("Normal fee is {}", normalFee);
normalPrice.set(normalFee);
})).when(fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", "1,7x", "fees.minCongestionPeriod", tmpMinCongestionPeriod)), fileUpdate(THROTTLE_DEFS).payingWith(EXCHANGE_RATE_CONTROL).contents(artificialLimits.toByteArray()), blockingOrder(IntStream.range(0, 10).mapToObj(i -> contractCall("scMulti").payingWith(GENESIS).fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR)).toArray(HapiSpecOperation[]::new)), contractCall("scMulti").payingWith("civilian").fee(ONE_HUNDRED_HBARS).sending(ONE_HBAR).via("pricyCall")).then(getTxnRecord("pricyCall").payingWith(GENESIS).providingFeeTo(congestionFee -> {
log.info("Congestion fee is {}", congestionFee);
sevenXPrice.set(congestionFee);
}), withOpContext((spec, opLog) -> {
Assertions.assertEquals(7.0, (1.0 * sevenXPrice.get()) / normalPrice.get(), 0.1, "~7x multiplier should be in affect!");
}), fileUpdate(THROTTLE_DEFS).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).contents(defaultThrottles.toByteArray()), fileUpdate(APP_PROPERTIES).fee(ONE_HUNDRED_HBARS).payingWith(EXCHANGE_RATE_CONTROL).overridingProps(Map.of("fees.percentCongestionMultipliers", defaultCongestionMultipliers, "fees.minCongestionPeriod", defaultMinCongestionPeriod)), /* Make sure the multiplier is reset before the next spec runs */
cryptoTransfer(HapiCryptoTransfer.tinyBarsFromTo(GENESIS, FUNDING, 1)).payingWith(GENESIS));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation 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));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation 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);
}
};
}
Aggregations