use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.
the class HapiQueryOp method fittedPayment.
private Transaction fittedPayment(HapiApiSpec spec) throws Throwable {
if (explicitPayment.isPresent()) {
return explicitPayment.get().signedTxnFor(spec);
} else if (nodePaymentFn.isPresent()) {
return finalizedTxn(spec, opDef(spec, nodePaymentFn.get().apply(spec)));
} else if (nodePayment.isPresent()) {
return finalizedTxn(spec, opDef(spec, nodePayment.get()));
} else {
long initNodePayment = costOnlyNodePayment(spec);
Transaction payment = finalizedTxn(spec, opDef(spec, initNodePayment), true);
if (!loggingOff) {
log.info(spec.logPrefix() + "Paying for COST_ANSWER of " + this + " with " + txnToString(payment));
}
long realNodePayment = timedCostLookupWith(spec, payment);
if (recordsNodePayment) {
spec.registry().saveAmount(nodePaymentName, realNodePayment);
}
if (!suppressStats) {
spec.incrementNumLedgerOps();
}
if (expectedCostAnswerPrecheck() != OK) {
return null;
}
if (spec.setup().costSnapshotMode() != OFF) {
spec.recordPayment(new Payment(initNodePayment, self().getClass().getSimpleName(), COST_ANSWER_QUERY_COST));
spec.recordPayment(new Payment(realNodePayment, self().getClass().getSimpleName(), ANSWER_ONLY_QUERY_COST));
}
txnSubmitted = payment;
if (!loggingOff) {
log.info(spec.logPrefix() + "--> Node payment for " + this + " is " + realNodePayment + " tinyBars.");
}
if (expectStrictCostAnswer) {
Transaction insufficientPayment = finalizedTxn(spec, opDef(spec, realNodePayment - 1));
submitWith(spec, insufficientPayment);
if (INSUFFICIENT_TX_FEE != reflectForPrecheck(response)) {
String errMsg = String.format("Strict cost of answer! suppose to be %s, but get %s", INSUFFICIENT_TX_FEE, reflectForPrecheck(response));
log.error(errMsg);
throw new HapiQueryPrecheckStateException(errMsg);
} else {
log.info("Query with node payment of {} tinyBars got INSUFFICIENT_TX_FEE as expected!", realNodePayment - 1);
}
}
return finalizedTxn(spec, opDef(spec, realNodePayment));
}
}
use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.
the class HapiApiSpec method compareWithSnapshot.
private void compareWithSnapshot() {
int nActual = costs.size();
int nExpected = costSnapshot.size();
boolean allMatch = (nActual == nExpected);
if (!allMatch) {
log.error("Expected " + nExpected + " payments to be recorded, not " + nActual + "!");
}
for (int i = 0; i < Math.min(nActual, nExpected); i++) {
Payment actual = costs.get(i);
Payment expected = costSnapshot.get(i);
if (!actual.equals(expected)) {
allMatch = false;
log.error("Expected " + expected + " for payment " + i + ", not " + actual + "!");
}
}
if (!allMatch) {
status = FAILED;
}
}
use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.
the class HapiApiSpec method takeCostSnapshot.
private void takeCostSnapshot() {
try {
Properties deserializedCosts = new Properties();
for (int i = 0; i < costs.size(); i++) {
Payment cost = costs.get(i);
deserializedCosts.put(String.format("%d.%s", i, cost.entryName()), "" + cost.tinyBars);
}
File file = new File(costSnapshotFilePath());
CharSink sink = Files.asCharSink(file, Charset.forName("UTF-8"));
deserializedCosts.store(sink.openBufferedStream(), "Cost snapshot");
} catch (Exception e) {
log.warn("Couldn't take cost snapshot to file '" + costSnapshotFile() + "!", e);
}
}
use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.
the class HapiTxnOp method publishFeeChargedTo.
private void publishFeeChargedTo(HapiApiSpec spec) throws Throwable {
if (recordOfSubmission == null) {
lookupSubmissionRecord(spec);
}
long fee = recordOfSubmission.getTransactionFee();
spec.recordPayment(new Payment(fee, self().getClass().getSimpleName(), TXN_FEE));
}
use of com.hedera.services.bdd.spec.fees.Payment in project hedera-services by hashgraph.
the class HapiApiSpec method costSnapshotFrom.
public static List<Payment> costSnapshotFrom(String loc) {
Properties serializedCosts = new Properties();
final ByteSource source = Files.asByteSource(new File(loc));
try (InputStream inStream = source.openBufferedStream()) {
serializedCosts.load(inStream);
} catch (IOException ie) {
log.error("Couldn't load cost snapshots as requested!", ie);
throw new IllegalArgumentException(ie);
}
Map<Integer, Payment> costsByOrder = new HashMap<>();
serializedCosts.forEach((a, b) -> {
String meta = (String) a;
long amount = Long.valueOf((String) b);
int i = meta.indexOf(".");
costsByOrder.put(Integer.valueOf(meta.substring(0, i)), Payment.fromEntry(meta.substring(i + 1), amount));
});
return IntStream.range(0, costsByOrder.size()).mapToObj(costsByOrder::get).collect(toList());
}
Aggregations