Search in sources :

Example 6 with FeeObject

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

Example 7 with FeeObject

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

Example 8 with FeeObject

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());
}
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 9 with FeeObject

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());
}
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 10 with FeeObject

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

FeeObject (com.hederahashgraph.fee.FeeObject)23 Test (org.junit.jupiter.api.Test)19 FeeBuilder.getFeeObject (com.hederahashgraph.fee.FeeBuilder.getFeeObject)7 SigValueObj (com.hederahashgraph.fee.SigValueObj)4 ByteString (com.google.protobuf.ByteString)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)1