use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class GetAccountBalanceAnswerTest method requiresOkMetaValidity.
@Test
void requiresOkMetaValidity() {
// setup:
AccountID id = asAccount(accountIdLit);
// given:
CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(id).build();
Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
// when:
Response response = subject.responseGiven(query, view, PLATFORM_NOT_ACTIVE);
ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
// expect:
assertEquals(PLATFORM_NOT_ACTIVE, status);
assertEquals(id, response.getCryptogetAccountBalance().getAccountID());
}
use of com.hederahashgraph.api.proto.java.AccountID 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.AccountID in project hedera-services by hashgraph.
the class ContractLogAsserts method accountAtBytes.
public ContractLogAsserts accountAtBytes(String account, int start) {
registerProvider((spec, o) -> {
byte[] data = dataFrom(o);
System.out.println("Length of event: " + data.length);
AccountID expected = spec.registry().getAccountID(account);
AccountID actual = accountFromBytes(data, start);
Assertions.assertEquals(expected, actual, "Bad account in log data, starting at byte " + start);
});
return this;
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class PlatformTxnAccessorTest method getsPayer.
@Test
void getsPayer() throws Exception {
// given:
AccountID payer = asAccount("0.0.2");
Transaction signedTxnWithBody = Transaction.newBuilder().setBodyBytes(someTxn.toByteString()).build();
SwirldTransaction platformTxn = new SwirldTransaction(signedTxnWithBody.toByteArray());
// when:
PlatformTxnAccessor subject = new PlatformTxnAccessor(platformTxn);
// then:
assertEquals(payer, subject.getPayer());
}
use of com.hederahashgraph.api.proto.java.AccountID in project hedera-services by hashgraph.
the class ContractCallSuite method payTestSelfDestructCall.
HapiApiSpec payTestSelfDestructCall() {
return defaultHapiSpec("payTestSelfDestructCall").given(cryptoCreate("payer").balance(1_000_000_000_000L).logged(), cryptoCreate("receiver").balance(1_000L), fileCreate("bytecode").path(ContractResources.PAY_TEST_SELF_DESTRUCT_BYTECODE_PATH), contractCreate("payTestSelfDestruct").bytecode("bytecode")).when(withOpContext((spec, opLog) -> {
var subop1 = contractCall("payTestSelfDestruct", ContractResources.DEPOSIT_ABI, 1_000L).payingWith("payer").gas(300_000L).via("deposit").sending(1_000L);
var subop2 = contractCall("payTestSelfDestruct", ContractResources.GET_BALANCE_ABI).payingWith("payer").gas(300_000L).via("getBalance");
AccountID contractAccountId = asId("payTestSelfDestruct", spec);
var subop3 = contractCall("payTestSelfDestruct", ContractResources.KILL_ME_ABI, contractAccountId.getAccountNum()).payingWith("payer").gas(300_000L).hasKnownStatus(OBTAINER_SAME_CONTRACT_ID);
var subop4 = contractCall("payTestSelfDestruct", ContractResources.KILL_ME_ABI, 999_999L).payingWith("payer").gas(300_000L).hasKnownStatus(INVALID_SOLIDITY_ADDRESS);
AccountID receiverAccountId = asId("receiver", spec);
var subop5 = contractCall("payTestSelfDestruct", ContractResources.KILL_ME_ABI, receiverAccountId.getAccountNum()).payingWith("payer").gas(300_000L).via("selfDestruct").hasKnownStatus(SUCCESS);
allRunFor(spec, subop1, subop2, subop3, subop4, subop5);
})).then(getTxnRecord("deposit"), getTxnRecord("getBalance").hasPriority(recordWith().contractCallResult(resultWith().resultThruAbi(ContractResources.GET_BALANCE_ABI, isLiteralResult(new Object[] { BigInteger.valueOf(1_000L) })))), getAccountBalance("receiver").hasTinyBars(2_000L));
}
Aggregations