use of com.hederahashgraph.api.proto.java.Response 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.Response 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());
}
use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.
the class GetAccountInfoAnswerTest method getsTheAccountInfo.
@Test
void getsTheAccountInfo() throws Throwable {
given(token.hasKycKey()).willReturn(true);
given(token.hasFreezeKey()).willReturn(true);
given(token.decimals()).willReturn(1).willReturn(2).willReturn(3).willReturn(1).willReturn(2).willReturn(3);
given(deletedToken.decimals()).willReturn(4);
given(tokenStore.exists(firstToken)).willReturn(true);
given(tokenStore.exists(secondToken)).willReturn(true);
given(tokenStore.exists(thirdToken)).willReturn(true);
given(tokenStore.exists(fourthToken)).willReturn(true);
given(tokenStore.exists(missingToken)).willReturn(false);
given(tokenStore.get(firstToken)).willReturn(token);
given(tokenStore.get(secondToken)).willReturn(token);
given(tokenStore.get(thirdToken)).willReturn(token);
given(tokenStore.get(fourthToken)).willReturn(deletedToken);
given(token.symbol()).willReturn("HEYMA");
given(deletedToken.symbol()).willReturn("THEWAY");
given(accounts.get(EntityNum.fromAccountId(asAccount(target)))).willReturn(payerAccount);
given(networkInfo.ledgerId()).willReturn(ledgerId);
// setup:
Query query = validQuery(ANSWER_ONLY, fee, target);
// when:
Response response = subject.responseGiven(query, view, OK, fee);
// then:
assertTrue(response.hasCryptoGetInfo());
assertTrue(response.getCryptoGetInfo().hasHeader(), "Missing response header!");
assertEquals(OK, response.getCryptoGetInfo().getHeader().getNodeTransactionPrecheckCode());
assertEquals(ANSWER_ONLY, response.getCryptoGetInfo().getHeader().getResponseType());
assertEquals(0, response.getCryptoGetInfo().getHeader().getCost());
// and:
CryptoGetInfoResponse.AccountInfo info = response.getCryptoGetInfo().getAccountInfo();
assertEquals(asAccount(payer), info.getAccountID());
String address = CommonUtils.hex(asEvmAddress(0, 0L, 12_345L));
assertEquals(address, info.getContractAccountID());
assertEquals(payerAccount.getBalance(), info.getBalance());
assertEquals(payerAccount.getAutoRenewSecs(), info.getAutoRenewPeriod().getSeconds());
assertEquals(payerAccount.getProxy(), EntityId.fromGrpcAccountId(info.getProxyAccountID()));
assertEquals(JKey.mapJKey(payerAccount.getAccountKey()), info.getKey());
assertEquals(payerAccount.isReceiverSigRequired(), info.getReceiverSigRequired());
assertEquals(payerAccount.getExpiry(), info.getExpirationTime().getSeconds());
assertEquals(memo, info.getMemo());
assertEquals(1, info.getGrantedCryptoAllowancesCount());
assertEquals(1, info.getGrantedTokenAllowancesCount());
assertEquals(1, info.getGrantedNftAllowancesCount());
assertEquals(GrantedCryptoAllowance.newBuilder().setAmount(10L).setSpender(EntityNum.fromLong(1L).toGrpcAccountId()).build(), info.getGrantedCryptoAllowances(0));
assertEquals(GrantedTokenAllowance.newBuilder().setAmount(20L).setSpender(EntityNum.fromLong(2000L).toGrpcAccountId()).setTokenId(EntityNum.fromLong(1000L).toGrpcTokenId()).build(), info.getGrantedTokenAllowances(0));
assertEquals(GrantedNftAllowance.newBuilder().setApprovedForAll(false).addAllSerialNumbers(List.of(1L, 2L)).setSpender(EntityNum.fromLong(2000L).toGrpcAccountId()).setTokenId(EntityNum.fromLong(1000L).toGrpcTokenId()).build(), info.getGrantedNftAllowances(0));
// and:
assertEquals(List.of(new RawTokenRelationship(firstBalance, 0, 0, firstToken.getTokenNum(), true, true, true).asGrpcFor(token), new RawTokenRelationship(secondBalance, 0, 0, secondToken.getTokenNum(), false, false, true).asGrpcFor(token), new RawTokenRelationship(thirdBalance, 0, 0, thirdToken.getTokenNum(), true, true, false).asGrpcFor(token), new RawTokenRelationship(fourthBalance, 0, 0, fourthToken.getTokenNum(), false, false, true).asGrpcFor(deletedToken), new RawTokenRelationship(missingBalance, 0, 0, missingToken.getTokenNum(), false, false, false).asGrpcFor(REMOVED_TOKEN)), info.getTokenRelationshipsList());
}
use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.
the class GetAccountInfoAnswerTest method getsInvalidResponse.
@Test
void getsInvalidResponse() throws Throwable {
// setup:
Query query = validQuery(COST_ANSWER, fee, target);
// when:
Response response = subject.responseGiven(query, view, ACCOUNT_DELETED, fee);
// then:
assertTrue(response.hasCryptoGetInfo());
assertEquals(ACCOUNT_DELETED, response.getCryptoGetInfo().getHeader().getNodeTransactionPrecheckCode());
assertEquals(COST_ANSWER, response.getCryptoGetInfo().getHeader().getResponseType());
assertEquals(fee, response.getCryptoGetInfo().getHeader().getCost());
}
use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.
the class GetAccountInfoAnswerTest method identifiesFailInvalid.
@Test
void identifiesFailInvalid() throws Throwable {
// setup:
Query query = validQuery(ANSWER_ONLY, fee, target);
// and:
StateView view = mock(StateView.class);
given(view.infoForAccount(any(), any())).willReturn(Optional.empty());
// when:
Response response = subject.responseGiven(query, view, OK, fee);
// then:
assertTrue(response.hasCryptoGetInfo());
assertEquals(FAIL_INVALID, response.getCryptoGetInfo().getHeader().getNodeTransactionPrecheckCode());
assertEquals(ANSWER_ONLY, response.getCryptoGetInfo().getHeader().getResponseType());
}
Aggregations