Search in sources :

Example 16 with FeeObject

use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.

the class UsageBasedFeeCalculatorTest method invokesQueryDelegateByTypeAsExpected.

@Test
void invokesQueryDelegateByTypeAsExpected() {
    // setup:
    FeeObject expectedFees = getFeeObject(currentPrices.get(SubType.DEFAULT), resourceUsage, currentRate);
    given(correctQueryEstimator.applicableTo(query)).willReturn(true);
    given(incorrectQueryEstimator.applicableTo(query)).willReturn(false);
    given(correctQueryEstimator.usageGivenType(query, view, ANSWER_ONLY)).willReturn(resourceUsage);
    given(incorrectQueryEstimator.usageGivenType(any(), any(), any())).willThrow(RuntimeException.class);
    given(exchange.rate(at)).willReturn(currentRate);
    // when:
    FeeObject fees = subject.estimatePayment(query, currentPrices.get(SubType.DEFAULT), view, at, ANSWER_ONLY);
    // 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) Test(org.junit.jupiter.api.Test)

Example 17 with FeeObject

use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.

the class FeeChargingPolicyTest method chargesDiscountedFeesAsExpectedForDuplicate.

@Test
void chargesDiscountedFeesAsExpectedForDuplicate() {
    // setup:
    ArgumentCaptor<FeeObject> captor = ArgumentCaptor.forClass(FeeObject.class);
    givenPayerWillingAndAbleForAllFees();
    // when:
    ResponseCodeEnum outcome = subject.applyForDuplicate(fees);
    // then:
    verify(narratedCharging).setFees(captor.capture());
    // and:
    assertEquals(feesForDuplicateTxn.getNodeFee(), captor.getValue().getNodeFee());
    assertEquals(feesForDuplicateTxn.getNetworkFee(), captor.getValue().getNetworkFee());
    assertEquals(feesForDuplicateTxn.getServiceFee(), captor.getValue().getServiceFee());
    // and:
    verify(narratedCharging).chargePayerAllFees();
    // and:
    assertEquals(OK, outcome);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) FeeObject(com.hederahashgraph.fee.FeeObject) Test(org.junit.jupiter.api.Test)

Example 18 with FeeObject

use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.

the class HTSPrecompiledContractTest method gasRequirementReturnsCorrectValueForMultipleCryptoTransfers.

@Test
void gasRequirementReturnsCorrectValueForMultipleCryptoTransfers() {
    // given
    givenFrameContext();
    given(input.getInt(0)).willReturn(ABI_ID_CRYPTO_TRANSFER);
    given(syntheticTxnFactory.createCryptoTransfer(any())).willReturn(TransactionBody.newBuilder().setCryptoTransfer(CryptoTransferTransactionBody.newBuilder().addTokenTransfers(TokenTransferList.newBuilder().build()).addTokenTransfers(TokenTransferList.newBuilder().build()).addTokenTransfers(TokenTransferList.newBuilder().build())));
    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 19 with FeeObject

use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.

the class HTSPrecompiledContractTest method gasRequirementReturnsCorrectValueForDissociateToken.

@Test
void gasRequirementReturnsCorrectValueForDissociateToken() {
    // given
    givenFrameContext();
    given(input.getInt(0)).willReturn(ABI_ID_DISSOCIATE_TOKEN);
    given(decoder.decodeDissociate(any(), any())).willReturn(dissociateToken);
    given(syntheticTxnFactory.createDissociate(any())).willReturn(TransactionBody.newBuilder().setTokenDissociate(TokenDissociateTransactionBody.newBuilder().build()));
    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));
    Mockito.verifyNoMoreInteractions(syntheticTxnFactory);
}
Also used : FeeObject(com.hederahashgraph.fee.FeeObject) Test(org.junit.jupiter.api.Test)

Example 20 with FeeObject

use of com.hederahashgraph.fee.FeeObject in project hedera-services by hashgraph.

the class HTSPrecompiledContractTest method gasRequirementReturnsCorrectValueForAssociateToken.

@Test
void gasRequirementReturnsCorrectValueForAssociateToken() {
    // given
    givenFrameContext();
    given(input.getInt(0)).willReturn(ABI_ID_ASSOCIATE_TOKEN);
    given(decoder.decodeAssociation(any(), any())).willReturn(associateOp);
    final var builder = TokenAssociateTransactionBody.newBuilder();
    builder.setAccount(associateOp.accountId());
    builder.addAllTokens(associateOp.tokenIds());
    given(syntheticTxnFactory.createAssociate(any())).willReturn(TransactionBody.newBuilder().setTokenAssociate(builder));
    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)

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