Search in sources :

Example 1 with SigValueObj

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());
}
Also used : FeeBuilder.getFeeObject(com.hederahashgraph.fee.FeeBuilder.getFeeObject) FeeObject(com.hederahashgraph.fee.FeeObject) SigValueObj(com.hederahashgraph.fee.SigValueObj) Test(org.junit.jupiter.api.Test)

Example 2 with SigValueObj

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());
}
Also used : FeeBuilder.getFeeObject(com.hederahashgraph.fee.FeeBuilder.getFeeObject) FeeObject(com.hederahashgraph.fee.FeeObject) SigValueObj(com.hederahashgraph.fee.SigValueObj) Test(org.junit.jupiter.api.Test)

Example 3 with SigValueObj

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());
}
Also used : FeeBuilder.getFeeObject(com.hederahashgraph.fee.FeeBuilder.getFeeObject) FeeObject(com.hederahashgraph.fee.FeeObject) SigValueObj(com.hederahashgraph.fee.SigValueObj) Test(org.junit.jupiter.api.Test)

Example 4 with SigValueObj

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));
}
Also used : SigValueObj(com.hederahashgraph.fee.SigValueObj) Test(org.junit.jupiter.api.Test)

Example 5 with SigValueObj

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());
}
Also used : FeeBuilder.getFeeObject(com.hederahashgraph.fee.FeeBuilder.getFeeObject) FeeObject(com.hederahashgraph.fee.FeeObject) SigValueObj(com.hederahashgraph.fee.SigValueObj) Test(org.junit.jupiter.api.Test)

Aggregations

SigValueObj (com.hederahashgraph.fee.SigValueObj)6 Test (org.junit.jupiter.api.Test)5 FeeBuilder.getFeeObject (com.hederahashgraph.fee.FeeBuilder.getFeeObject)4 FeeObject (com.hederahashgraph.fee.FeeObject)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)1