Search in sources :

Example 11 with AccountID

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

Example 12 with AccountID

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;
}
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 13 with AccountID

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

Example 14 with AccountID

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());
}
Also used : SwirldTransaction(com.swirlds.common.SwirldTransaction) AccountID(com.hederahashgraph.api.proto.java.AccountID) Transaction(com.hederahashgraph.api.proto.java.Transaction) SignedTransaction(com.hederahashgraph.api.proto.java.SignedTransaction) SwirldTransaction(com.swirlds.common.SwirldTransaction) Test(org.junit.jupiter.api.Test)

Example 15 with AccountID

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

Aggregations

AccountID (com.hederahashgraph.api.proto.java.AccountID)71 Test (org.junit.jupiter.api.Test)24 List (java.util.List)21 ByteString (com.google.protobuf.ByteString)20 Assertions (org.junit.jupiter.api.Assertions)20 HapiApiSpec (com.hedera.services.bdd.spec.HapiApiSpec)17 LogManager (org.apache.logging.log4j.LogManager)17 Logger (org.apache.logging.log4j.Logger)17 HapiApiSuite (com.hedera.services.bdd.suites.HapiApiSuite)16 HapiApiSpec.defaultHapiSpec (com.hedera.services.bdd.spec.HapiApiSpec.defaultHapiSpec)15 QueryVerbs.getTxnRecord (com.hedera.services.bdd.spec.queries.QueryVerbs.getTxnRecord)15 SUCCESS (com.hederahashgraph.api.proto.java.ResponseCodeEnum.SUCCESS)15 QueryVerbs.getAccountInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountInfo)14 TransactionRecordAsserts.recordWith (com.hedera.services.bdd.spec.assertions.TransactionRecordAsserts.recordWith)13 QueryVerbs.getAccountBalance (com.hedera.services.bdd.spec.queries.QueryVerbs.getAccountBalance)13 TxnVerbs.cryptoCreate (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoCreate)13 TxnVerbs.cryptoTransfer (com.hedera.services.bdd.spec.transactions.TxnVerbs.cryptoTransfer)13 TxnVerbs.mintToken (com.hedera.services.bdd.spec.transactions.TxnVerbs.mintToken)13 HapiSpecSetup (com.hedera.services.bdd.spec.HapiSpecSetup)12 QueryVerbs.getScheduleInfo (com.hedera.services.bdd.spec.queries.QueryVerbs.getScheduleInfo)12