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