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);
}
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));
}
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));
}
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);
}
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));
}
Aggregations