Search in sources :

Example 16 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class GetTokenNftInfoAnswerTest method usesViewToValidate.

@Test
void usesViewToValidate() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, nftId);
    given(view.nftExists(nftId)).willReturn(false);
    // when:
    ResponseCodeEnum validity = subject.checkValidity(query, view);
    // then:
    assertEquals(INVALID_NFT_ID, validity);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenGetNftInfoQuery(com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Example 17 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class GetTokenNftInfoAnswerTest method validatesInexistingTokenId.

@Test
void validatesInexistingTokenId() throws Throwable {
    // setup:
    nftId = NftID.newBuilder().setSerialNumber(2).build();
    Query query = validQuery(COST_ANSWER, fee, nftId);
    // when:
    ResponseCodeEnum validity = subject.checkValidity(query, view);
    // then:
    assertEquals(INVALID_TOKEN_ID, validity);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TokenGetNftInfoQuery(com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Example 18 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class HapiGetAccountBalance method submitWith.

@Override
protected void submitWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getAccountBalanceQuery(spec, payment, false);
    response = spec.clients().getCryptoSvcStub(targetNodeFor(spec), useTls).cryptoGetBalance(query);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    if (status == ResponseCodeEnum.ACCOUNT_DELETED) {
        log.info(spec.logPrefix() + repr + " was actually deleted!");
    } else {
        long balance = response.getCryptogetAccountBalance().getBalance();
        long TINYBARS_PER_HBAR = 100_000_000L;
        long hBars = balance / TINYBARS_PER_HBAR;
        if (!loggingOff) {
            log.info(spec.logPrefix() + "balance for '" + repr + "': " + balance + " tinyBars (" + hBars + "ħ)");
        }
        if (yahcliLogger) {
            COMMON_MESSAGES.info(String.format("%20s | %20d |", repr, balance));
        }
    }
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query)

Example 19 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class QueryFeeCheck method validateQueryPaymentTransfers.

/**
 * Validates query payment transfer transaction before reaching consensus.
 * Validate each payer has enough balance that is needed for transfer.
 * If one of the payer for query is also paying transactionFee validate the payer has balance to pay both
 *
 * @param txn the transaction body to validate
 * @return the corresponding {@link ResponseCodeEnum} after the validation
 */
public ResponseCodeEnum validateQueryPaymentTransfers(TransactionBody txn) {
    AccountID transactionPayer = txn.getTransactionID().getAccountID();
    TransferList transferList = txn.getCryptoTransfer().getTransfers();
    List<AccountAmount> transfers = transferList.getAccountAmountsList();
    long transactionFee = txn.getTransactionFee();
    final var currentAccounts = accounts.get();
    ResponseCodeEnum status;
    for (AccountAmount accountAmount : transfers) {
        var id = accountAmount.getAccountID();
        long amount = accountAmount.getAmount();
        if (amount < 0) {
            amount = -1 * amount;
            if (id.equals(transactionPayer)) {
                try {
                    amount = Math.addExact(amount, transactionFee);
                } catch (ArithmeticException e) {
                    return INSUFFICIENT_PAYER_BALANCE;
                }
            }
            if ((status = balanceCheck(currentAccounts.get(fromAccountId(id)), amount)) != OK) {
                return status;
            }
        }
    }
    return OK;
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) TransferList(com.hederahashgraph.api.proto.java.TransferList) AccountAmount(com.hederahashgraph.api.proto.java.AccountAmount)

Example 20 with ResponseCodeEnum

use of com.hederahashgraph.api.proto.java.ResponseCodeEnum in project hedera-services by hashgraph.

the class GetBytecodeAnswerTest method usesValidator.

@Test
void usesValidator() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    given(optionValidator.queryableContractStatus(EntityNum.fromLong(123), contracts)).willReturn(CONTRACT_DELETED);
    // when:
    ResponseCodeEnum validity = subject.checkValidity(query, view);
    // then:
    assertEquals(CONTRACT_DELETED, validity);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) Query(com.hederahashgraph.api.proto.java.Query) ContractGetBytecodeQuery(com.hederahashgraph.api.proto.java.ContractGetBytecodeQuery) Test(org.junit.jupiter.api.Test)

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