use of com.hederahashgraph.fee.SigValueObj 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.SigValueObj 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.SigValueObj 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());
}
use of com.hederahashgraph.fee.SigValueObj in project hedera-services by hashgraph.
the class UsageBasedFeeCalculatorTest method failsWithIseGivenApplicableButUnusableCalculator.
@Test
void failsWithIseGivenApplicableButUnusableCalculator() throws InvalidTxBodyException {
// setup:
SigValueObj expectedSigUsage = new SigValueObj(FeeBuilder.getSignatureCount(signedTxn), 9, FeeBuilder.getSignatureSize(signedTxn));
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))).willThrow(InvalidTxBodyException.class);
// when:
assertThrows(IllegalArgumentException.class, () -> subject.computeFee(accessor, payerKey, view, consensusNow));
}
use of com.hederahashgraph.fee.SigValueObj 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());
}
Aggregations