use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.
the class UtilVerbs method recordFeeAmount.
/* Some more complicated ops built from primitive sub-ops */
public static CustomSpecAssert recordFeeAmount(String forTxn, String byName) {
return new CustomSpecAssert((spec, workLog) -> {
HapiGetTxnRecord subOp = getTxnRecord(forTxn);
allRunFor(spec, subOp);
TransactionRecord record = subOp.getResponseRecord();
long fee = record.getTransactionFee();
spec.registry().saveAmount(byName, fee);
});
}
use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.
the class HapiSpecOperation method lookupSubmissionRecord.
protected void lookupSubmissionRecord(HapiApiSpec spec) throws Throwable {
HapiGetTxnRecord subOp = getTxnRecord(extractTxnId(txnSubmitted)).noLogging().assertingNothing().suppressStats(true).nodePayment(spec.setup().defaultNodePaymentTinyBars());
Optional<Throwable> error = subOp.execFor(spec);
if (error.isPresent()) {
throw error.get();
}
recordOfSubmission = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
}
use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord 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.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.
the class UtilVerbs method validateTransferListForBalances.
public static HapiSpecOperation validateTransferListForBalances(List<String> txns, List<String> accounts, Set<String> wereDeleted) {
return assertionsHold((spec, assertLog) -> {
Map<String, Long> actualBalances = accounts.stream().collect(Collectors.toMap((String account) -> asAccountString(spec.registry().getAccountID(account)), (String account) -> {
if (wereDeleted.contains(account)) {
return 0L;
}
long balance = -1L;
try {
BalanceSnapshot preOp = balanceSnapshot("x", account);
allRunFor(spec, preOp);
balance = spec.registry().getBalanceSnapshot("x");
} catch (Throwable ignore) {
}
return balance;
}));
List<AccountAmount> transfers = new ArrayList<>();
for (String txn : txns) {
HapiGetTxnRecord subOp = getTxnRecord(txn).logged().payingWith(EXCHANGE_RATE_CONTROL);
allRunFor(spec, subOp);
TransactionRecord record = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
transfers.addAll(record.getTransferList().getAccountAmountsList());
}
Map<String, Long> changes = changesAccordingTo(transfers);
assertLog.info("Balance changes according to transfer list: " + changes);
changes.entrySet().forEach(change -> {
String account = change.getKey();
long oldBalance = -1L;
/* The account/contract may have just been created, no snapshot was taken. */
try {
oldBalance = spec.registry().getBalanceSnapshot(account + "Snapshot");
} catch (Throwable ignore) {
}
long expectedBalance = change.getValue() + Math.max(0L, oldBalance);
long actualBalance = actualBalances.getOrDefault(account, -1L);
assertLog.info("Balance of " + account + " was expected to be " + expectedBalance + ", is actually " + actualBalance + "...");
Assertions.assertEquals(expectedBalance, actualBalance, "New balance for " + account + " should be " + expectedBalance + " tinyBars.");
});
});
}
use of com.hedera.services.bdd.spec.queries.meta.HapiGetTxnRecord in project hedera-services by hashgraph.
the class UtilVerbs method validateRecordTransactionFees.
public static HapiSpecOperation validateRecordTransactionFees(String txn, Set<AccountID> feeRecipients) {
return assertionsHold((spec, assertLog) -> {
HapiGetTxnRecord subOp = getTxnRecord(txn).logged().payingWith(EXCHANGE_RATE_CONTROL).expectStrictCostAnswer();
allRunFor(spec, subOp);
TransactionRecord record = subOp.getResponse().getTransactionGetRecord().getTransactionRecord();
long realFee = record.getTransferList().getAccountAmountsList().stream().filter(aa -> feeRecipients.contains(aa.getAccountID())).mapToLong(AccountAmount::getAmount).sum();
Assertions.assertEquals(realFee, record.getTransactionFee(), "Inconsistent transactionFee field!");
});
}
Aggregations