use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class FeeChargingPolicyTest method chargesServiceFeeForTriggeredTxn.
@Test
void chargesServiceFeeForTriggeredTxn() {
given(narratedCharging.isPayerWillingToCoverServiceFee()).willReturn(true);
given(narratedCharging.canPayerAffordServiceFee()).willReturn(true);
// when:
ResponseCodeEnum outcome = subject.applyForTriggered(fees);
// then:
verify(narratedCharging).setFees(fees);
verify(narratedCharging).chargePayerServiceFee();
// and:
assertEquals(OK, outcome);
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class FeeChargingPolicyTest method chargesNonServicePenaltyForUnwillingToCoverTotal.
@Test
void chargesNonServicePenaltyForUnwillingToCoverTotal() {
given(narratedCharging.isPayerWillingToCoverNetworkFee()).willReturn(true);
given(narratedCharging.canPayerAffordNetworkFee()).willReturn(true);
given(narratedCharging.isPayerWillingToCoverAllFees()).willReturn(false);
// when:
ResponseCodeEnum outcome = subject.apply(fees);
// then:
verify(narratedCharging).setFees(fees);
verify(narratedCharging).chargePayerNetworkAndUpToNodeFee();
// and:
assertEquals(INSUFFICIENT_TX_FEE, outcome);
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class FeeChargingPolicyTest method chargesNonServicePenaltyForUnableToCoverTotal.
@Test
void chargesNonServicePenaltyForUnableToCoverTotal() {
given(narratedCharging.isPayerWillingToCoverNetworkFee()).willReturn(true);
given(narratedCharging.canPayerAffordNetworkFee()).willReturn(true);
given(narratedCharging.isPayerWillingToCoverAllFees()).willReturn(true);
given(narratedCharging.canPayerAffordAllFees()).willReturn(false);
// when:
ResponseCodeEnum outcome = subject.apply(fees);
// then:
verify(narratedCharging).setFees(fees);
verify(narratedCharging).chargePayerNetworkAndUpToNodeFee();
// and:
assertEquals(INSUFFICIENT_PAYER_BALANCE, outcome);
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class SolvencyPrecheck method solvencyOfVerifiedPayer.
private TxnValidityAndFeeReq solvencyOfVerifiedPayer(SignedTxnAccessor accessor, boolean includeSvcFee) {
final var payerId = EntityNum.fromAccountId(accessor.getPayer());
final var payerAccount = accounts.get().get(payerId);
try {
final var now = accessor.getTxnId().getTransactionValidStart();
final var payerKey = payerAccount.getAccountKey();
final var estimatedFees = feeCalculator.estimateFee(accessor, payerKey, stateView.get(), now);
final var estimatedReqFee = totalOf(estimatedFees, includeSvcFee);
if (accessor.getTxn().getTransactionFee() < estimatedReqFee) {
return new TxnValidityAndFeeReq(INSUFFICIENT_TX_FEE, estimatedReqFee);
}
final var estimatedAdj = Math.min(0L, feeCalculator.estimatedNonFeePayerAdjustments(accessor, now));
final var requiredPayerBalance = estimatedReqFee - estimatedAdj;
final var payerBalance = payerAccount.getBalance();
ResponseCodeEnum finalStatus = OK;
if (payerBalance < requiredPayerBalance) {
final var isDetached = payerBalance == 0 && dynamicProperties.autoRenewEnabled() && !validator.isAfterConsensusSecond(payerAccount.getExpiry());
finalStatus = isDetached ? ACCOUNT_EXPIRED_AND_PENDING_REMOVAL : INSUFFICIENT_PAYER_BALANCE;
}
return new TxnValidityAndFeeReq(finalStatus, estimatedReqFee);
} catch (Exception suspicious) {
log.warn("Fee calculation failure may be justifiable due to an expiring payer, but...", suspicious);
return LOST_PAYER_EXPIRATION_RACE;
}
}
use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.
the class SyntaxPrecheck method validate.
public ResponseCodeEnum validate(TransactionBody txn) {
if (!txn.hasTransactionID()) {
return INVALID_TRANSACTION_ID;
}
var txnId = txn.getTransactionID();
if (txnId.getScheduled() || txnId.getNonce() != USER_TRANSACTION_NONCE) {
return TRANSACTION_ID_FIELD_NOT_ALLOWED;
}
if (recordCache.isReceiptPresent(txnId)) {
return DUPLICATE_TRANSACTION;
}
if (!validator.isPlausibleTxnFee(txn.getTransactionFee())) {
return INSUFFICIENT_TX_FEE;
}
if (!validator.isPlausibleAccount(txn.getTransactionID().getAccountID())) {
return PAYER_ACCOUNT_NOT_FOUND;
}
if (!validator.isThisNodeAccount(txn.getNodeAccountID())) {
return INVALID_NODE_ACCOUNT;
}
ResponseCodeEnum memoValidity = validator.memoCheck(txn.getMemo());
if (memoValidity != OK) {
return memoValidity;
}
var validForSecs = txn.getTransactionValidDuration().getSeconds();
if (!validator.isValidTxnDuration(validForSecs)) {
return INVALID_TRANSACTION_DURATION;
}
return validator.chronologyStatusForTxn(asCoercedInstant(txn.getTransactionID().getTransactionValidStart()), validForSecs - dynamicProperties.minValidityBuffer(), Instant.now(Clock.systemUTC()));
}
Aggregations