use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class HTSPrecompiledContractTest method gasRequirementReturnsCorrectValueForTransferNfts.
@Test
void gasRequirementReturnsCorrectValueForTransferNfts() {
// given
givenFrameContext();
given(input.getInt(0)).willReturn(ABI_ID_TRANSFER_NFTS);
given(syntheticTxnFactory.createCryptoTransfer(any())).willReturn(TransactionBody.newBuilder().setCryptoTransfer(CryptoTransferTransactionBody.newBuilder()));
given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(new FeeObject(TEST_NODE_FEE, TEST_NETWORK_FEE, TEST_SERVICE_FEE));
given(feeCalculator.estimatedGasPriceInTinybars(any(), any())).willReturn(DEFAULT_GAS_PRICE);
subject.prepareFields(messageFrame);
subject.prepareComputation(input, а -> а);
subject.computeGasRequirement(TEST_CONSENSUS_TIME);
// then
assertEquals(Gas.of(EXPECTED_GAS_PRICE), subject.gasRequirement(input));
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class HTSPrecompiledContractTest method gasRequirementReturnsCorrectValueForTransferMultipleTokens.
@Test
void gasRequirementReturnsCorrectValueForTransferMultipleTokens() {
// given
givenFrameContext();
given(input.getInt(0)).willReturn(ABI_ID_TRANSFER_TOKENS);
given(syntheticTxnFactory.createCryptoTransfer(any())).willReturn(TransactionBody.newBuilder().setCryptoTransfer(CryptoTransferTransactionBody.newBuilder()));
given(feeCalculator.computeFee(any(), any(), any(), any())).willReturn(new FeeObject(TEST_NODE_FEE, TEST_NETWORK_FEE, TEST_SERVICE_FEE));
given(feeCalculator.estimatedGasPriceInTinybars(any(), any())).willReturn(DEFAULT_GAS_PRICE);
subject.prepareFields(messageFrame);
subject.prepareComputation(input, а -> а);
subject.computeGasRequirement(TEST_CONSENSUS_TIME);
// then
assertEquals(Gas.of(EXPECTED_GAS_PRICE), subject.gasRequirement(input));
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method invokesOpDelegateAsExpectedWithOneOption.
@Test
void invokesOpDelegateAsExpectedWithOneOption() throws Exception {
// setup:
SigValueObj expectedSigUsage = new SigValueObj(FeeBuilder.getSignatureCount(signedTxn), 9, FeeBuilder.getSignatureSize(signedTxn));
FeeObject expectedFees = getFeeObject(currentPrices.get(SubType.DEFAULT), resourceUsage, currentRate);
given(correctOpEstimator.applicableTo(accessor.getTxn())).willReturn(true);
given(txnUsageEstimators.get(CryptoCreate)).willReturn(List.of(correctOpEstimator));
given(correctOpEstimator.usageGiven(argThat(accessor.getTxn()::equals), argThat(factory.apply(expectedSigUsage)), argThat(view::equals))).willReturn(resourceUsage);
given(exchange.activeRate(consensusNow)).willReturn(currentRate);
// when:
FeeObject fees = subject.computeFee(accessor, payerKey, view, consensusNow);
// then:
assertEquals(fees.getNodeFee(), expectedFees.getNodeFee());
assertEquals(fees.getNetworkFee(), expectedFees.getNetworkFee());
assertEquals(fees.getServiceFee(), expectedFees.getServiceFee());
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method invokesOpDelegateAsExpectedWithTwoOptions.
@Test
void invokesOpDelegateAsExpectedWithTwoOptions() throws Exception {
// setup:
SigValueObj expectedSigUsage = new SigValueObj(FeeBuilder.getSignatureCount(signedTxn), 9, FeeBuilder.getSignatureSize(signedTxn));
FeeObject expectedFees = getFeeObject(currentPrices.get(SubType.DEFAULT), resourceUsage, currentRate);
given(correctOpEstimator.applicableTo(accessor.getTxn())).willReturn(true);
given(incorrectOpEstimator.applicableTo(accessor.getTxn())).willReturn(false);
given(txnUsageEstimators.get(CryptoCreate)).willReturn(List.of(incorrectOpEstimator, correctOpEstimator));
given(correctOpEstimator.usageGiven(argThat(accessor.getTxn()::equals), argThat(factory.apply(expectedSigUsage)), argThat(view::equals))).willReturn(resourceUsage);
given(incorrectOpEstimator.usageGiven(any(), any(), any())).willThrow(RuntimeException.class);
given(exchange.rate(at)).willReturn(currentRate);
given(usagePrices.activePrices(accessor)).willThrow(RuntimeException.class);
given(usagePrices.pricesGiven(CryptoCreate, at)).willReturn(currentPrices);
// when:
FeeObject fees = subject.estimateFee(accessor, payerKey, view, at);
// then:
assertEquals(fees.getNodeFee(), expectedFees.getNodeFee());
assertEquals(fees.getNetworkFee(), expectedFees.getNetworkFee());
assertEquals(fees.getServiceFee(), expectedFees.getServiceFee());
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method invokesOpDelegateAsExpectedForEstimateOfUnrecognizable.
@Test
void invokesOpDelegateAsExpectedForEstimateOfUnrecognizable() throws Exception {
// setup:
SigValueObj expectedSigUsage = new SigValueObj(FeeBuilder.getSignatureCount(signedTxn), 9, FeeBuilder.getSignatureSize(signedTxn));
FeeObject expectedFees = getFeeObject(DEFAULT_RESOURCE_PRICES.get(SubType.DEFAULT), resourceUsage, currentRate);
given(txnUsageEstimators.get(CryptoCreate)).willReturn(List.of(correctOpEstimator));
given(correctOpEstimator.applicableTo(accessor.getTxn())).willReturn(true);
given(correctOpEstimator.usageGiven(argThat(accessor.getTxn()::equals), argThat(factory.apply(expectedSigUsage)), argThat(view::equals))).willReturn(resourceUsage);
given(exchange.rate(at)).willReturn(currentRate);
given(usagePrices.pricesGiven(CryptoCreate, at)).willThrow(RuntimeException.class);
// when:
FeeObject fees = subject.estimateFee(accessor, payerKey, view, at);
// then:
assertEquals(fees.getNodeFee(), expectedFees.getNodeFee());
assertEquals(fees.getNetworkFee(), expectedFees.getNetworkFee());
assertEquals(fees.getServiceFee(), expectedFees.getServiceFee());
}
Aggregations