use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class FileContractMemoPerfSuite method RunMixedFileContractMemoOps.
// perform cryptoCreate, cryptoUpdate, TokenCreate, TokenUpdate, FileCreate, FileUpdate txs with entity memo set.
protected HapiApiSpec RunMixedFileContractMemoOps() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
final AtomicInteger createdSoFar = new AtomicInteger(0);
Supplier<HapiSpecOperation[]> mixedOpsBurst = () -> new HapiSpecOperation[] { fileCreate("testFile" + createdSoFar.getAndIncrement()).payingWith(GENESIS).entityMemo(new String(TxnUtils.randomUtf8Bytes(memoLength.getAsInt()), StandardCharsets.UTF_8)).noLogging().hasPrecheckFrom(OK, BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution(), getFileInfo(TARGET_FILE + "Info").hasMemo(FILE_MEMO), fileUpdate(TARGET_FILE).payingWith(GENESIS).entityMemo(new String(TxnUtils.randomUtf8Bytes(memoLength.getAsInt()), StandardCharsets.UTF_8)).noLogging().hasPrecheckFrom(OK, BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution(), contractCreate("testContract" + createdSoFar.getAndIncrement()).payingWith(GENESIS).bytecode(TARGET_FILE).entityMemo(new String(TxnUtils.randomUtf8Bytes(memoLength.getAsInt()), StandardCharsets.UTF_8)).noLogging().hasPrecheckFrom(OK, BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution(), getContractInfo(CONTRACT + "Info").hasExpectedInfo(), contractUpdate(CONTRACT).payingWith(GENESIS).newMemo(new String(TxnUtils.randomUtf8Bytes(memoLength.getAsInt()), StandardCharsets.UTF_8)).noLogging().hasPrecheckFrom(OK, BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
return defaultHapiSpec("RunMixedFileContractMemoOps").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(fileCreate(TARGET_FILE).payingWith(GENESIS).path(ContractResources.VALID_BYTECODE_PATH).entityMemo(FILE_MEMO).logged(), fileCreate(TARGET_FILE + "Info").payingWith(GENESIS).entityMemo(FILE_MEMO).logged(), contractCreate(CONTRACT).payingWith(GENESIS).bytecode(TARGET_FILE).entityMemo(CONTRACT_MEMO).logged(), contractCreate(CONTRACT + "Info").payingWith(GENESIS).bytecode(TARGET_FILE).entityMemo(CONTRACT_MEMO).logged()).then(defaultLoadTest(mixedOpsBurst, settings));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class ContractCallLoadTest method runContractCalls.
private HapiApiSpec runContractCalls() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
final AtomicInteger submittedSoFar = new AtomicInteger(0);
final String DEPOSIT_MEMO = "So we out-danced thought, body perfection brought...";
Supplier<HapiSpecOperation[]> callBurst = () -> new HapiSpecOperation[] { inParallel(IntStream.range(0, settings.getBurstSize()).mapToObj(i -> contractCall("perf", ContractResources.VERBOSE_DEPOSIT_ABI, i + 1, 0, DEPOSIT_MEMO).sending(i + 1).noLogging().suppressStats(true).hasRetryPrecheckFrom(PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution()).toArray(n -> new HapiSpecOperation[n])), logIt(ignore -> String.format("Now a total of %d transactions submitted.", submittedSoFar.addAndGet(settings.getBurstSize()))) };
return defaultHapiSpec("runContractCalls").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(fileCreate("contractBytecode").path(ContractResources.VERBOSE_DEPOSIT_BYTECODE_PATH), contractCreate("perf").bytecode("contractBytecode"), fileCreate("lookupBytecode").path(ContractResources.BALANCE_LOOKUP_BYTECODE_PATH), contractCreate("balanceLookup").bytecode("lookupBytecode").balance(1L), getContractInfo("perf").hasExpectedInfo().logged()).then(defaultLoadTest(callBurst, settings));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class ContractPerformanceSuite method getSpecsInSuite.
@Override
public List<HapiApiSpec> getSpecsInSuite() {
List<String> perfTests;
try {
perfTests = Files.readLines(new File(PERF_RESOURCES + "performanceContracts.csv"), Charset.defaultCharset()).stream().filter(s -> !s.isEmpty() && !s.startsWith("#")).collect(Collectors.toList());
} catch (IOException e) {
return List.of();
}
List<HapiApiSpec> hapiSpecs = new ArrayList<>();
for (String line : perfTests) {
String[] values = line.split(",", 2);
String test = values[0];
long gasCost = Long.parseLong(values[1]);
String path = PERF_RESOURCES + test;
String via = test.substring(0, test.length() - 4);
String contractCode;
try {
contractCode = new String(Files.toByteArray(new File(path)), StandardCharsets.US_ASCII);
} catch (IOException e) {
LOG.warn("createTestProgram for " + test + " failed to read bytes from '" + path + "'!", e);
contractCode = "FE";
}
HapiSpecOperation[] givenBlock;
if (contractCode.contains(EXTERNAL_CONTRACT_MARKER)) {
givenBlock = new HapiSpecOperation[] { createProgramFile(RETURN_CONTRACT + "bytecode", RETURN_PROGRAM), contractCreate(RETURN_CONTRACT).bytecode(RETURN_CONTRACT + "bytecode"), createProgramFile(REVERT_CONTRACT + "bytecode", REVERT_PROGRAM), contractCreate(REVERT_CONTRACT).bytecode(REVERT_CONTRACT + "bytecode"), withOpContext((spec, opLog) -> allRunFor(spec, createTestProgram(test, spec.registry().getContractId(RETURN_CONTRACT), spec.registry().getContractId(REVERT_CONTRACT)))), contractCreate(test).bytecode(test + "bytecode") };
} else {
givenBlock = new HapiSpecOperation[] { fileCreate("bytecode").path(PERF_RESOURCES + test), contractCreate(test).bytecode("bytecode") };
}
hapiSpecs.add(defaultHapiSpec("Perf_" + test).given(givenBlock).when(contractCall(test, "<empty>").gas(35000000).via(via)).then(getExecTime(via).payingWith(GENESIS).logged().assertingNoneLongerThan(20, ChronoUnit.SECONDS), getReceipt(via).hasPriorityStatus(ResponseCodeEnum.SUCCESS), getTxnRecord(via).hasPriority(recordWith().contractCallResult(resultWith().gasUsed(gasCost)))));
}
return hapiSpecs;
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class CryptoTransferLoadTest method runCryptoTransfers.
protected HapiApiSpec runCryptoTransfers() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
Supplier<HapiSpecOperation[]> transferBurst = () -> {
String sender = "sender";
String receiver = "receiver";
if (settings.getTotalAccounts() > 2) {
int s = r.nextInt(settings.getTotalAccounts());
int re = 0;
do {
re = r.nextInt(settings.getTotalAccounts());
} while (re == s);
sender = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + s);
receiver = String.format("0.0.%d", TEST_ACCOUNT_STARTS_FROM + re);
}
return new HapiSpecOperation[] { cryptoTransfer(tinyBarsFromTo(sender, receiver, 1L)).noLogging().payingWith(sender).signedBy(GENESIS).suppressStats(true).fee(100_000_000L).hasKnownStatusFrom(SUCCESS, OK, INSUFFICIENT_PAYER_BALANCE, UNKNOWN, TRANSACTION_EXPIRED, INSUFFICIENT_ACCOUNT_BALANCE).hasRetryPrecheckFrom(BUSY, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
};
return defaultHapiSpec("RunCryptoTransfers").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when(cryptoCreate("sender").balance(ignore -> settings.getInitialBalance()).payingWith(GENESIS).withRecharging().key(GENESIS).rechargeWindow(3).logging().hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), cryptoCreate("receiver").payingWith(GENESIS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).key(GENESIS).logging()).then(defaultLoadTest(transferBurst, settings), getAccountBalance("sender").logged());
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class SplittingThrottlesWorks method cryptoCreateOps.
private Function<HapiApiSpec, OpProvider> cryptoCreateOps() {
var i = new AtomicInteger(0);
return spec -> new OpProvider() {
@Override
public List<HapiSpecOperation> suggestedInitializers() {
return List.of(cryptoCreate("civilian").payingWith(GENESIS).balance(ONE_MILLION_HBARS).withRecharging());
}
@Override
public Optional<HapiSpecOperation> get() {
HapiSpecOperation op;
final var nextI = i.getAndIncrement();
if (nextI % (scheduleCreatesPerCryptoCreate + 1) == 0) {
op = cryptoCreate("w/e" + nextI).noLogging().deferStatusResolution().payingWith("civilian").hasPrecheckFrom(OK, BUSY);
} else {
op = scheduleCreate("scheduleW/e" + nextI, cryptoTransfer(tinyBarsFromTo("civilian", FUNDING, 1)).memo(TxnUtils.randomAlphaNumeric(32)).hasPrecheckFrom(STANDARD_PERMISSIBLE_PRECHECKS)).noLogging().deferStatusResolution().payingWith("civilian").hasPrecheckFrom(OK, BUSY);
}
return Optional.of(op);
}
};
}
Aggregations