Search in sources :

Example 71 with Response

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());
}
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 72 with Response

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

Example 73 with Response

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());
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) Response(com.hederahashgraph.api.proto.java.Response) CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) ByteString(com.google.protobuf.ByteString) RawTokenRelationship(com.hedera.services.state.submerkle.RawTokenRelationship) Test(org.junit.jupiter.api.Test)

Example 74 with Response

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

Example 75 with Response

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());
}
Also used : CryptoGetInfoResponse(com.hederahashgraph.api.proto.java.CryptoGetInfoResponse) Response(com.hederahashgraph.api.proto.java.Response) CryptoGetInfoQuery(com.hederahashgraph.api.proto.java.CryptoGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) StateView(com.hedera.services.context.primitives.StateView) Test(org.junit.jupiter.api.Test)

Aggregations

Response (com.hederahashgraph.api.proto.java.Response)114 Query (com.hederahashgraph.api.proto.java.Query)96 Test (org.junit.jupiter.api.Test)87 FileGetInfoResponse (com.hederahashgraph.api.proto.java.FileGetInfoResponse)9 ByteString (com.google.protobuf.ByteString)8 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)8 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)8 TokenGetNftInfoResponse (com.hederahashgraph.api.proto.java.TokenGetNftInfoResponse)8 TransactionGetReceiptResponse (com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse)8 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)7 ContractGetInfoQuery (com.hederahashgraph.api.proto.java.ContractGetInfoQuery)7 ContractGetInfoResponse (com.hederahashgraph.api.proto.java.ContractGetInfoResponse)7 NetworkGetExecutionTimeQuery (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeQuery)7 NetworkGetExecutionTimeResponse (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeResponse)7 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)7 ScheduleGetInfoQuery (com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery)7 ScheduleGetInfoResponse (com.hederahashgraph.api.proto.java.ScheduleGetInfoResponse)7 TokenGetInfoQuery (com.hederahashgraph.api.proto.java.TokenGetInfoQuery)7 TokenGetInfoResponse (com.hederahashgraph.api.proto.java.TokenGetInfoResponse)7 HashMap (java.util.HashMap)7