use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class HCSChunkingRealisticPerfSuite method fragmentLongMessageIntoChunks.
private static HapiApiSpec fragmentLongMessageIntoChunks() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
Supplier<HapiSpecOperation[]> submitBurst = () -> new HapiSpecOperation[] { chunkAFile(LARGE_FILE, CHUNK_SIZE, PAYER, TOPIC, totalMsgSubmitted) };
return defaultHapiSpec("fragmentLongMessageIntoChunks").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), newKeyNamed("submitKey"), logIt(ignore -> settings.toString())).when(cryptoCreate(PAYER).balance(initialBalance.getAsLong()).withRecharging().rechargeWindow(30).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED), withOpContext((spec, ignore) -> {
int factor = settings.getIntProperty("collisionAvoidanceFactor", DEFAULT_COLLISION_AVOIDANCE_FACTOR);
List<HapiSpecOperation> opsList = new ArrayList<HapiSpecOperation>();
for (int i = 0; i < settings.getThreads() * factor; i++) {
var op = createTopic(TOPIC + i).submitKeyName("submitKey").hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED);
opsList.add(op);
}
CustomSpecAssert.allRunFor(spec, inParallel(flattened(opsList)));
}), // wait all other thread ready
sleepFor(5000)).then(defaultLoadTest(submitBurst, settings));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class createTopicLoadTest method runCreateTopics.
private static HapiApiSpec runCreateTopics() {
PerfTestLoadSettings settings = new PerfTestLoadSettings();
final AtomicInteger submittedSoFar = new AtomicInteger(0);
KeyShape submitKeyShape = threshOf(2, SIMPLE, SIMPLE, listOf(2));
Supplier<HapiSpecOperation[]> submitBurst = () -> new HapiSpecOperation[] { createTopic("testTopic" + submittedSoFar.addAndGet(1)).submitKeyShape(submitKeyShape).noLogging().hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED).deferStatusResolution() };
return defaultHapiSpec("runCreateTopics").given(withOpContext((spec, ignore) -> settings.setFrom(spec.setup().ciPropertiesMap())), logIt(ignore -> settings.toString())).when().then(defaultLoadTest(submitBurst, settings));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class ContractRecordsSanityCheckSuite method circularTransfersRecordSanityChecks.
private HapiApiSpec circularTransfersRecordSanityChecks() {
int NUM_ALTRUISTS = 3;
Function<String, Long> INIT_BALANCE_FN = ignore -> 1_000_000L;
int INIT_KEEP_AMOUNT_DIVISOR = 2;
BigInteger STOP_BALANCE = BigInteger.valueOf(399_999L);
String[] CANONICAL_ACCOUNTS = { FUNDING, NODE, DEFAULT_PAYER };
String[] altruists = IntStream.range(0, NUM_ALTRUISTS).mapToObj(i -> String.format("Altruist%s", new String(new char[] { (char) ('A' + i) }))).toArray(n -> new String[n]);
return defaultHapiSpec("CircularTransfersRecordSanityChecks").given(flattened(fileCreate("bytecode").path(ContractResources.CIRCULAR_TRANSFERS_BYTECODE_PATH), Stream.of(altruists).map(name -> contractCreate(name).bytecode("bytecode")).toArray(n -> new HapiSpecOperation[n]), Stream.of(altruists).map(name -> contractCall(name, ContractResources.SET_NODES_ABI, spec -> new Object[] { Stream.of(altruists).map(a -> spec.registry().getContractId(a).getContractNum()).toArray() }).gas(120_000).via("txnFor" + name).sending(INIT_BALANCE_FN.apply(name))).toArray(n -> new HapiSpecOperation[n]), UtilVerbs.takeBalanceSnapshots(Stream.of(Stream.of(altruists), Stream.of(CANONICAL_ACCOUNTS)).flatMap(identity()).toArray(n -> new String[n])))).when(contractCall(altruists[0], ContractResources.RECEIVE_AND_SEND_ABI, INIT_KEEP_AMOUNT_DIVISOR, STOP_BALANCE).via("altruisticTxn")).then(validateTransferListForBalances("altruisticTxn", Stream.concat(Stream.of(CANONICAL_ACCOUNTS), Stream.of(altruists)).collect(toList())), validateRecordTransactionFees("altruisticTxn"), addLogInfo((spec, infoLog) -> {
long[] finalBalances = IntStream.range(0, NUM_ALTRUISTS).mapToLong(ignore -> INIT_BALANCE_FN.apply("")).toArray();
int i = 0, divisor = INIT_KEEP_AMOUNT_DIVISOR;
while (true) {
long toKeep = finalBalances[i] / divisor;
if (toKeep < STOP_BALANCE.longValue()) {
break;
}
int j = (i + 1) % NUM_ALTRUISTS;
finalBalances[j] += (finalBalances[i] - toKeep);
finalBalances[i] = toKeep;
i = j;
divisor++;
}
infoLog.info("Expected Final Balances");
infoLog.info("-----------------------");
for (i = 0; i < NUM_ALTRUISTS; i++) {
infoLog.info(" " + i + " = " + finalBalances[i] + " tinyBars");
}
}));
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class UtilVerbs method chunkAFile.
public static HapiSpecOperation chunkAFile(String filePath, int chunkSize, String payer, String topic, AtomicLong count) {
return withOpContext((spec, ctxLog) -> {
List<HapiSpecOperation> opsList = new ArrayList<HapiSpecOperation>();
String overriddenFile = new String(filePath);
int overriddenChunkSize = chunkSize;
String overriddenTopic = new String(topic);
boolean validateRunningHash = false;
long currentCount = count.getAndIncrement();
if (currentCount >= 0) {
var ciProperties = spec.setup().ciPropertiesMap();
if (null != ciProperties) {
if (ciProperties.has("file")) {
overriddenFile = ciProperties.get("file");
}
if (ciProperties.has("chunkSize")) {
overriddenChunkSize = ciProperties.getInteger("chunkSize");
}
if (ciProperties.has("validateRunningHash")) {
validateRunningHash = ciProperties.getBoolean("validateRunningHash");
}
int threads = PerfTestLoadSettings.DEFAULT_THREADS;
if (ciProperties.has("threads")) {
threads = ciProperties.getInteger("threads");
}
int factor = HCSChunkingRealisticPerfSuite.DEFAULT_COLLISION_AVOIDANCE_FACTOR;
if (ciProperties.has("collisionAvoidanceFactor")) {
factor = ciProperties.getInteger("collisionAvoidanceFactor");
}
overriddenTopic += currentCount % (threads * factor);
}
}
ByteString msg = ByteString.copyFrom(Files.readAllBytes(Paths.get(overriddenFile)));
int size = msg.size();
int totalChunks = (size + overriddenChunkSize - 1) / overriddenChunkSize;
int position = 0;
int currentChunk = 0;
var initialTransactionID = asTransactionID(spec, Optional.of(payer));
while (position < size) {
++currentChunk;
int newPosition = Math.min(size, position + overriddenChunkSize);
ByteString subMsg = msg.substring(position, newPosition);
HapiMessageSubmit subOp = submitMessageTo(overriddenTopic).message(subMsg).chunkInfo(totalChunks, currentChunk, initialTransactionID).payingWith(payer).hasKnownStatus(SUCCESS).hasRetryPrecheckFrom(BUSY, DUPLICATE_TRANSACTION, PLATFORM_TRANSACTION_NOT_CREATED, INSUFFICIENT_PAYER_BALANCE).noLogging().suppressStats(true);
if (1 == currentChunk) {
subOp = subOp.usePresetTimestamp();
}
if (validateRunningHash) {
String txnName = "submitMessage-" + overriddenTopic + "-" + currentChunk;
HapiGetTxnRecord validateOp = getTxnRecord(txnName).hasCorrectRunningHash(overriddenTopic, subMsg.toByteArray()).payingWith(payer).noLogging();
opsList.add(subOp.via(txnName));
opsList.add(validateOp);
} else {
opsList.add(subOp.deferStatusResolution());
}
position = newPosition;
}
CustomSpecAssert.allRunFor(spec, opsList);
});
}
use of com.hedera.services.bdd.spec.HapiSpecOperation in project hedera-services by hashgraph.
the class UtilVerbs method ensureDissociated.
public static HapiSpecOperation ensureDissociated(String account, List<String> tokens) {
return withOpContext((spec, opLog) -> {
var query = getAccountBalance(account);
allRunFor(spec, query);
var answer = query.getResponse().getCryptogetAccountBalance().getTokenBalancesList();
for (String token : tokens) {
var tid = spec.registry().getTokenID(token);
var match = answer.stream().filter(tb -> tb.getTokenId().equals(tid)).findAny();
if (match.isPresent()) {
var tb = match.get();
opLog.info("Account '{}' is associated to token '{}' ({})", account, token, HapiPropertySource.asTokenString(tid));
if (tb.getBalance() > 0) {
opLog.info(" -->> Balance is {}, transferring to treasury", tb.getBalance());
var treasury = spec.registry().getTreasury(token);
var xfer = cryptoTransfer(moving(tb.getBalance(), token).between(account, treasury));
allRunFor(spec, xfer);
}
opLog.info(" -->> Dissociating '{}' from '{}' now", account, token);
var dis = tokenDissociate(account, token);
allRunFor(spec, dis);
}
}
});
}
Aggregations