Search in sources :

Example 1 with SignedTxnAccessor

use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.

the class ContextOptionValidatorTest method acceptsOk.

@Test
void acceptsOk() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.minusSeconds(validDuration - 1).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(OK, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 2 with SignedTxnAccessor

use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.

the class ContextOptionValidatorTest method recognizesFutureValidStartStart.

@Test
void recognizesFutureValidStartStart() {
    SignedTxnAccessor accessor = mock(SignedTxnAccessor.class);
    // given:
    long validDuration = 1_000L;
    Instant consensusTime = Instant.ofEpochSecond(1_234_567L);
    Instant validStart = Instant.ofEpochSecond(consensusTime.plusSeconds(1L).getEpochSecond());
    // and:
    TransactionID txnId = TransactionID.newBuilder().setTransactionValidStart(Timestamp.newBuilder().setSeconds(validStart.getEpochSecond())).build();
    TransactionBody txn = TransactionBody.newBuilder().setTransactionID(txnId).setTransactionValidDuration(Duration.newBuilder().setSeconds(validDuration)).build();
    // and:
    given(accessor.getTxn()).willReturn(txn);
    given(accessor.getTxnId()).willReturn(txnId);
    // when:
    ResponseCodeEnum status = subject.chronologyStatus(accessor, consensusTime);
    // then:
    assertEquals(INVALID_TRANSACTION_START, status);
    // and:
    assertEquals(INVALID_TRANSACTION_START, subject.chronologyStatusForTxn(validStart, validDuration, consensusTime));
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionBody(com.hederahashgraph.api.proto.java.TransactionBody) Instant(java.time.Instant) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Test(org.junit.jupiter.api.Test)

Example 3 with SignedTxnAccessor

use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.

the class UsageBasedFeeCalculatorTest method estimatesContractCreatePayerBalanceChanges.

@Test
void estimatesContractCreatePayerBalanceChanges() throws Throwable {
    // setup:
    long gas = 1_234L, initialBalance = 5_432L;
    signedTxn = newSignedContractCreate().payer(asAccountString(payer)).gas(gas).initialBalance(initialBalance).txnValidStart(at).get();
    accessor = new SignedTxnAccessor(signedTxn);
    given(exchange.rate(at)).willReturn(currentRate);
    given(usagePrices.pricesGiven(ContractCreate, at)).willReturn(currentPrices);
    given(usagePrices.defaultPricesGiven(ContractCreate, at)).willReturn(defaultCurrentPrices);
    // and:
    long expectedGasPrice = getTinybarsFromTinyCents(currentRate, mockFees.getGas() / FEE_DIVISOR_FACTOR);
    // expect:
    assertEquals(-(gas * expectedGasPrice + initialBalance), subject.estimatedNonFeePayerAdjustments(accessor, at));
}
Also used : SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test)

Example 4 with SignedTxnAccessor

use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.

the class UsageBasedFeeCalculatorTest method setup.

@BeforeEach
private void setup() throws Throwable {
    view = mock(StateView.class);
    query = mock(Query.class);
    payerKey = complexKey.asJKey();
    exchange = mock(HbarCentExchange.class);
    signedTxn = newSignedCryptoCreate().balance(balance).payerKt(complexKey).txnValidStart(at).get();
    accessor = new SignedTxnAccessor(signedTxn);
    usagePrices = mock(UsagePricesProvider.class);
    given(usagePrices.activePrices(accessor)).willReturn(currentPrices);
    correctOpEstimator = mock(TxnResourceUsageEstimator.class);
    incorrectOpEstimator = mock(TxnResourceUsageEstimator.class);
    correctQueryEstimator = mock(QueryResourceUsageEstimator.class);
    incorrectQueryEstimator = mock(QueryResourceUsageEstimator.class);
    autoRenewCalcs = mock(AutoRenewCalcs.class);
    pricedUsageCalculator = mock(PricedUsageCalculator.class);
    txnUsageEstimators = (Map<HederaFunctionality, List<TxnResourceUsageEstimator>>) mock(Map.class);
    subject = new UsageBasedFeeCalculator(autoRenewCalcs, exchange, mock(AutoCreationLogic.class), usagePrices, new NestedMultiplierSource(), pricedUsageCalculator, Set.of(incorrectQueryEstimator, correctQueryEstimator), txnUsageEstimators);
}
Also used : HederaFunctionality(com.hederahashgraph.api.proto.java.HederaFunctionality) Query(com.hederahashgraph.api.proto.java.Query) StateView(com.hedera.services.context.primitives.StateView) SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) HbarCentExchange(com.hedera.services.fees.HbarCentExchange) List(java.util.List) PricedUsageCalculator(com.hedera.services.fees.calculation.utils.PricedUsageCalculator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 5 with SignedTxnAccessor

use of com.hedera.services.utils.SignedTxnAccessor in project hedera-services by hashgraph.

the class UsageBasedFeeCalculatorTest method estimatesMiscNoNetChange.

@Test
void estimatesMiscNoNetChange() throws Throwable {
    // setup:
    signedTxn = newSignedFileCreate().payer(asAccountString(payer)).txnValidStart(at).get();
    accessor = new SignedTxnAccessor(signedTxn);
    // expect:
    assertEquals(0L, subject.estimatedNonFeePayerAdjustments(accessor, at));
}
Also used : SignedTxnAccessor(com.hedera.services.utils.SignedTxnAccessor) Test(org.junit.jupiter.api.Test)

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