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