Search in sources :

Example 6 with SignedTxnAccessor

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));
}
Also used : SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test)

Example 7 with SignedTxnAccessor

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));
}
Also used : SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test)

Example 8 with SignedTxnAccessor

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());
}
Also used : TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with SignedTxnAccessor

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);
}
Also used : Platform(com.swirlds.common.Platform) MiscSpeedometers(com.hedera.services.stats.MiscSpeedometers) RecordCache(com.hedera.services.records.RecordCache) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 10 with SignedTxnAccessor

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);
}
Also used : HashMap(java.util.HashMap) FeeObject(com.hederahashgraph.fee.FeeObject) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor)

Aggregations

SignedTxnAccessor (com.hedera.services.utils.SignedTxnAccessor)11 Test (org.junit.jupiter.api.Test)8 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)3 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)3 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)3 Instant (java.time.Instant)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 TxnValidityAndFeeReq (com.hedera.services.context.domain.process.TxnValidityAndFeeReq)1 StateView (com.hedera.services.context.primitives.StateView)1 HbarCentExchange (com.hedera.services.fees.HbarCentExchange)1 PricedUsageCalculator (com.hedera.services.fees.calculation.utils.PricedUsageCalculator)1 RecordCache (com.hedera.services.records.RecordCache)1 MiscSpeedometers (com.hedera.services.stats.MiscSpeedometers)1 HederaFunctionality (com.hederahashgraph.api.proto.java.HederaFunctionality)1 Query (com.hederahashgraph.api.proto.java.Query)1 FeeObject (com.hederahashgraph.fee.FeeObject)1 Platform (com.swirlds.common.Platform)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1