use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method invokesQueryDelegateAsExpected.
@Test
void invokesQueryDelegateAsExpected() {
// setup:
FeeObject expectedFees = getFeeObject(currentPrices.get(SubType.DEFAULT), resourceUsage, currentRate);
given(correctQueryEstimator.applicableTo(query)).willReturn(true);
given(incorrectQueryEstimator.applicableTo(query)).willReturn(false);
given(correctQueryEstimator.usageGiven(argThat(query::equals), argThat(view::equals), any())).willReturn(resourceUsage);
given(incorrectQueryEstimator.usageGiven(any(), any())).willThrow(RuntimeException.class);
given(exchange.rate(at)).willReturn(currentRate);
// when:
FeeObject fees = subject.computePayment(query, currentPrices.get(SubType.DEFAULT), view, at, Collections.emptyMap());
// 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 RecordCreationSuite method submittingNodeChargedNetworkFeeForIgnoringPayerUnwillingness.
private HapiApiSpec submittingNodeChargedNetworkFeeForIgnoringPayerUnwillingness() {
final String comfortingMemo = "This is ok, it's fine, it's whatever.";
final AtomicReference<FeeObject> feeObs = new AtomicReference<>();
return defaultHapiSpec("SubmittingNodeChargedNetworkFeeForIgnoringPayerUnwillingness").given(cryptoTransfer(tinyBarsFromTo(GENESIS, "0.0.3", ONE_HBAR)).payingWith(GENESIS), cryptoCreate("payer"), cryptoTransfer(tinyBarsFromTo(GENESIS, FUNDING, 1L)).memo(comfortingMemo).exposingFeesTo(feeObs).payingWith("payer"), usableTxnIdNamed("txnId").payerId("payer")).when(balanceSnapshot("before", "0.0.3"), balanceSnapshot("fundingBefore", "0.0.98"), sourcing(() -> uncheckedSubmit(cryptoTransfer(tinyBarsFromTo(GENESIS, FUNDING, 1L)).memo(comfortingMemo).fee(feeObs.get().getNetworkFee() - 1L).payingWith("payer").txnId("txnId")).payingWith(GENESIS)), sleepFor(SLEEP_MS)).then(sourcing(() -> getAccountBalance("0.0.3").hasTinyBars(changeFromSnapshot("before", -feeObs.get().getNetworkFee()))), sourcing(() -> getAccountBalance("0.0.98").hasTinyBars(changeFromSnapshot("fundingBefore", +feeObs.get().getNetworkFee()))), sourcing(() -> getTxnRecord("txnId").assertingNothingAboutHashes().hasPriority(recordWith().transfers(includingDeduction(() -> 3L, feeObs.get().getNetworkFee())).status(INSUFFICIENT_TX_FEE)).logged()));
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class RecordCreationSuite method submittingNodeChargedNetworkFeeForLackOfDueDiligence.
private HapiApiSpec submittingNodeChargedNetworkFeeForLackOfDueDiligence() {
final String comfortingMemo = "This is ok, it's fine, it's whatever.";
final String disquietingMemo = "\u0000his is ok, it's fine, it's whatever.";
final AtomicReference<FeeObject> feeObs = new AtomicReference<>();
return defaultHapiSpec("SubmittingNodeChargedNetworkFeeForLackOfDueDiligence").given(cryptoTransfer(tinyBarsFromTo(GENESIS, "0.0.3", ONE_HBAR)).payingWith(GENESIS), cryptoCreate("payer"), cryptoTransfer(tinyBarsFromTo(GENESIS, FUNDING, 1L)).memo(comfortingMemo).exposingFeesTo(feeObs).payingWith("payer"), usableTxnIdNamed("txnId").payerId("payer")).when(balanceSnapshot("before", "0.0.3"), balanceSnapshot("fundingBefore", "0.0.98"), uncheckedSubmit(cryptoTransfer(tinyBarsFromTo(GENESIS, FUNDING, 1L)).memo(disquietingMemo).payingWith("payer").txnId("txnId")).payingWith(GENESIS), sleepFor(SLEEP_MS)).then(sourcing(() -> getAccountBalance("0.0.3").hasTinyBars(changeFromSnapshot("before", -feeObs.get().getNetworkFee()))), sourcing(() -> getAccountBalance("0.0.98").hasTinyBars(changeFromSnapshot("fundingBefore", +feeObs.get().getNetworkFee()))), sourcing(() -> getTxnRecord("txnId").assertingNothingAboutHashes().hasPriority(recordWith().transfers(includingDeduction(() -> 3L, feeObs.get().getNetworkFee())).status(INVALID_ZERO_BYTE_IN_STRING)).logged()));
}
use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method usesMultiplierAsExpected.
@Test
void usesMultiplierAsExpected() throws Exception {
// setup:
long multiplier = 5L;
SigValueObj expectedSigUsage = new SigValueObj(FeeBuilder.getSignatureCount(signedTxn), 9, FeeBuilder.getSignatureSize(signedTxn));
FeeObject expectedFees = getFeeObject(currentPrices.get(SubType.DEFAULT), resourceUsage, currentRate, multiplier);
suggestedMultiplier.set(multiplier);
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 invokesAccessorBasedUsagesForTxnInHandle.
void invokesAccessorBasedUsagesForTxnInHandle(final Transaction signedTxn, final HederaFunctionality function, final SubType subType, final TokenType tokenType) throws Throwable {
accessor = SignedTxnAccessor.uncheckedFrom(signedTxn);
// and:
final var expectedFees = getFeeObject(currentPrices.get(subType), resourceUsage, currentRate);
given(pricedUsageCalculator.supports(function)).willReturn(true);
given(exchange.activeRate(consensusNow)).willReturn(currentRate);
given(usagePrices.activePrices(accessor)).willReturn(currentPrices);
given(pricedUsageCalculator.inHandleFees(accessor, currentPrices.get(subType), currentRate, payerKey)).willReturn(expectedFees);
given(view.tokenType(tokenId)).willReturn(Optional.of(tokenType));
// when:
FeeObject fees = subject.computeFee(accessor, payerKey, view, consensusNow);
// then:
assertNotNull(fees);
assertEquals(fees.getNodeFee(), expectedFees.getNodeFee());
assertEquals(fees.getNetworkFee(), expectedFees.getNetworkFee());
assertEquals(fees.getServiceFee(), expectedFees.getServiceFee());
}
Aggregations