Search in sources :

Example 6 with CryptoGetAccountBalanceQuery

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

the class GetAccountBalanceAnswerTest method answersWithAccountBalance.

@Test
void answersWithAccountBalance() {
    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, OK);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    long answer = response.getCryptogetAccountBalance().getBalance();
    // expect:
    assertTrue(response.getCryptogetAccountBalance().hasHeader(), "Missing response header!");
    assertEquals(List.of(tokenBalanceWith(aToken, aBalance, 1), tokenBalanceWith(bToken, bBalance, 2), tokenBalanceWith(cToken, cBalance, 123), tokenBalanceWith(dToken, dBalance, 0)), response.getCryptogetAccountBalance().getTokenBalancesList());
    assertEquals(OK, status);
    assertEquals(balance, answer);
    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 7 with CryptoGetAccountBalanceQuery

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

the class GetAccountBalanceAnswerTest method syntaxCheckValidatesCidIfPresent.

@Test
void syntaxCheckValidatesCidIfPresent() {
    // setup:
    ContractID cid = asContract(contractIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setContractID(cid).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // and:
    given(optionValidator.queryableContractStatus(cid, accounts)).willReturn(CONTRACT_DELETED);
    // when:
    ResponseCodeEnum status = subject.checkValidity(query, view);
    // expect:
    assertEquals(CONTRACT_DELETED, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) ContractID(com.hederahashgraph.api.proto.java.ContractID) Test(org.junit.jupiter.api.Test)

Example 8 with CryptoGetAccountBalanceQuery

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

the class GetAccountBalanceAnswerTest method syntaxCheckRequiresId.

@Test
void syntaxCheckRequiresId() {
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // when:
    ResponseCodeEnum status = subject.checkValidity(query, view);
    // expect:
    assertEquals(INVALID_ACCOUNT_ID, status);
}
Also used : ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) 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 9 with CryptoGetAccountBalanceQuery

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

the class GetAccountBalanceAnswerTest method syntaxCheckValidatesIdIfPresent.

@Test
void syntaxCheckValidatesIdIfPresent() {
    // setup:
    AccountID id = asAccount(accountIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(id).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // and:
    given(optionValidator.queryableAccountStatus(id, accounts)).willReturn(ACCOUNT_DELETED);
    // when:
    ResponseCodeEnum status = subject.checkValidity(query, view);
    // expect:
    assertEquals(ACCOUNT_DELETED, status);
}
Also used : 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 10 with CryptoGetAccountBalanceQuery

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

the class GetAccountBalanceAnswerTest method resolvesAliasIfExtant.

@Test
void resolvesAliasIfExtant() {
    final var aliasId = AccountID.newBuilder().setAlias(ByteString.copyFromUtf8("nope")).build();
    final var wellKnownId = EntityNum.fromLong(12345L);
    given(aliasManager.lookupIdBy(aliasId.getAlias())).willReturn(wellKnownId);
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(aliasId).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    Response response = subject.responseGiven(query, view, OK);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    long answer = response.getCryptogetAccountBalance().getBalance();
    assertTrue(response.getCryptogetAccountBalance().hasHeader(), "Missing response header!");
    assertEquals(List.of(tokenBalanceWith(aToken, aBalance, 1), tokenBalanceWith(bToken, bBalance, 2), tokenBalanceWith(cToken, cBalance, 123), tokenBalanceWith(dToken, dBalance, 0)), response.getCryptogetAccountBalance().getTokenBalancesList());
    assertEquals(OK, status);
    assertEquals(balance, answer);
    assertEquals(wellKnownId.toGrpcAccountId(), 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) 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)

Aggregations

CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)10 Query (com.hederahashgraph.api.proto.java.Query)8 Test (org.junit.jupiter.api.Test)8 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)7 CryptoGetAccountBalanceResponse (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse)5 Response (com.hederahashgraph.api.proto.java.Response)4 AccountID (com.hederahashgraph.api.proto.java.AccountID)3 MerkleAccount (com.hedera.services.state.merkle.MerkleAccount)2 EntityNum (com.hedera.services.utils.EntityNum)2 ContractID (com.hederahashgraph.api.proto.java.ContractID)2 TokenID (com.hederahashgraph.api.proto.java.TokenID)1