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