Search in sources :

Example 1 with ResponseCodeEnum

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

Example 2 with ResponseCodeEnum

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

Example 3 with ResponseCodeEnum

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

Example 4 with ResponseCodeEnum

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;
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TxnValidityAndFeeReq(com.hedera.services.context.domain.process.TxnValidityAndFeeReq) KeyPrefixMismatchException(com.hedera.services.legacy.exception.KeyPrefixMismatchException) InvalidAccountIDException(com.hedera.services.legacy.exception.InvalidAccountIDException)

Example 5 with ResponseCodeEnum

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()));
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum)

Aggregations

ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)52 Test (org.junit.jupiter.api.Test)38 Query (com.hederahashgraph.api.proto.java.Query)24 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)8 AccountID (com.hederahashgraph.api.proto.java.AccountID)6 Response (com.hederahashgraph.api.proto.java.Response)6 CryptoGetAccountBalanceResponse (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse)4 TransactionBody (com.hederahashgraph.api.proto.java.TransactionBody)4 SignedTxnAccessor (com.hedera.services.utils.SignedTxnAccessor)3 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)3 ContractID (com.hederahashgraph.api.proto.java.ContractID)3 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)3 AliasManager (com.hedera.services.ledger.accounts.AliasManager)2 HfsSigMetaLookup (com.hedera.services.sigs.metadata.lookups.HfsSigMetaLookup)2 EntityNum (com.hedera.services.utils.EntityNum)2 TopicID (com.hederahashgraph.api.proto.java.TopicID)2 TransactionID (com.hederahashgraph.api.proto.java.TransactionID)2 Instant (java.time.Instant)2 ByteString (com.google.protobuf.ByteString)1 EntityNumbers (com.hedera.services.config.EntityNumbers)1