use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method estimatesContractCallPayerBalanceChanges.
@Test
void estimatesContractCallPayerBalanceChanges() throws Throwable {
// setup:
long gas = 1_234L, sent = 5_432L;
signedTxn = newSignedContractCall().payer(asAccountString(payer)).gas(gas).sending(sent).txnValidStart(at).get();
accessor = new SignedTxnAccessor(signedTxn);
given(exchange.rate(at)).willReturn(currentRate);
given(usagePrices.defaultPricesGiven(ContractCall, at)).willReturn(defaultCurrentPrices);
// and:
long expectedGasPrice = getTinybarsFromTinyCents(currentRate, mockFees.getGas() / FEE_DIVISOR_FACTOR);
// expect:
assertEquals(-(gas * expectedGasPrice + sent), subject.estimatedNonFeePayerAdjustments(accessor, at));
}
use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method estimatesCryptoTransferPayerBalanceChanges.
@Test
void estimatesCryptoTransferPayerBalanceChanges() throws Throwable {
// setup:
long sent = 1_234L;
signedTxn = newSignedCryptoTransfer().payer(asAccountString(payer)).transfers(tinyBarsFromTo(asAccountString(payer), asAccountString(receiver), sent)).txnValidStart(at).get();
accessor = new SignedTxnAccessor(signedTxn);
// expect:
assertEquals(-sent, subject.estimatedNonFeePayerAdjustments(accessor, at));
}
use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.
the class TransactionPrecheckTest method abortsOnStructuralFlawWithBadAccessor.
@Test
void abortsOnStructuralFlawWithBadAccessor() {
givenActivePlatform();
final Pair<TxnValidityAndFeeReq, SignedTxnAccessor> dummyPair = Pair.of(new TxnValidityAndFeeReq(OK), null);
given(structuralPrecheck.assess(any())).willReturn(dummyPair);
final var topLevelResponse = subject.performForTopLevel(Transaction.getDefaultInstance());
final var queryPaymentResponse = subject.performForQueryPayment(Transaction.getDefaultInstance());
assertFailure(OK, topLevelResponse);
assertFailure(OK, queryPaymentResponse);
verify(syntaxPrecheck, never()).validate(any());
}
use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.
the class PlatformSubmissionManagerTest method setup.
@BeforeEach
void setup() throws InvalidProtocolBufferException {
platform = mock(Platform.class);
recordCache = mock(RecordCache.class);
speedometers = mock(MiscSpeedometers.class);
accessor = new SignedTxnAccessor(signedTxn);
uncheckedAccessor = new SignedTxnAccessor(uncheckedSubTxn);
invalidUncheckedAccessor = new SignedTxnAccessor(invalidUncheckedSubTxn);
subject = new PlatformSubmissionManager(platform, recordCache, speedometers);
}
use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.
the class StakedAnswerFlow method satisfyUsing.
@Override
public Response satisfyUsing(final AnswerService service, final Query query) {
final var view = stateViews.get();
final var headerStatus = queryHeaderValidity.checkHeader(query);
if (headerStatus != OK) {
return service.responseGiven(query, view, headerStatus);
}
SignedTxnAccessor optionalPayment = null;
final var allegedPayment = service.extractPaymentFrom(query);
final var isPaymentRequired = service.requiresNodePayment(query);
if (isPaymentRequired && allegedPayment.isPresent()) {
final var signedTxn = allegedPayment.get().getSignedTxnWrapper();
final var paymentCheck = transactionPrecheck.performForQueryPayment(signedTxn);
final var paymentStatus = paymentCheck.getLeft().getValidity();
if (paymentStatus != OK) {
return service.responseGiven(query, view, paymentStatus);
} else {
optionalPayment = paymentCheck.getRight();
}
}
final var hygieneStatus = hygieneCheck(query, view, service, optionalPayment);
if (hygieneStatus != OK) {
return service.responseGiven(query, view, hygieneStatus);
}
final var bestGuessNow = (null != optionalPayment) ? optionalPayment.getTxnId().getTransactionValidStart() : asTimestamp(Instant.now());
final var usagePrices = resourceCosts.defaultPricesGiven(service.canonicalFunction(), bestGuessNow);
long fee = 0L;
final Map<String, Object> queryCtx = new HashMap<>();
if (isPaymentRequired && null != optionalPayment) {
fee = totalOf(fees.computePayment(query, usagePrices, view, bestGuessNow, queryCtx));
final var paymentStatus = tryToPay(optionalPayment, fee);
if (paymentStatus != OK) {
return service.responseGiven(query, view, paymentStatus, fee);
}
}
if (service.needsAnswerOnlyCost(query)) {
fee = totalOf(fees.estimatePayment(query, usagePrices, view, bestGuessNow, ANSWER_ONLY));
}
return service.responseGiven(query, view, OK, fee, queryCtx);
}
Aggregations