Search in sources :

Example 21 with Query

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

the class GetScheduleInfoAnswerTest method recognizesMissingInfoWhenNoCtxGiven.

@Test
void recognizesMissingInfoWhenNoCtxGiven() throws Throwable {
    // setup:
    Query sensibleQuery = validQuery(ANSWER_ONLY, 5L, scheduleID);
    given(view.infoForSchedule(scheduleID)).willReturn(Optional.empty());
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK, 0L);
    // then:
    ScheduleGetInfoResponse opResponse = response.getScheduleGetInfo();
    assertTrue(opResponse.hasHeader(), "Missing response header!");
    assertEquals(INVALID_SCHEDULE_ID, opResponse.getHeader().getNodeTransactionPrecheckCode());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) ScheduleGetInfoResponse(com.hederahashgraph.api.proto.java.ScheduleGetInfoResponse) Query(com.hederahashgraph.api.proto.java.Query) ScheduleGetInfoQuery(com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery) ScheduleGetInfoResponse(com.hederahashgraph.api.proto.java.ScheduleGetInfoResponse) Test(org.junit.jupiter.api.Test)

Example 22 with Query

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

the class GetScheduleInfoAnswerTest method getsExpectedPayment.

@Test
void getsExpectedPayment() throws Throwable {
    // given:
    Query query = validQuery(COST_ANSWER, fee, scheduleID);
    // expect:
    assertEquals(paymentTxn, subject.extractPaymentFrom(query).get().getSignedTxnWrapper());
}
Also used : Query(com.hederahashgraph.api.proto.java.Query) ScheduleGetInfoQuery(com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery) Test(org.junit.jupiter.api.Test)

Example 23 with Query

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

the class GetAccountNftInfosAnswerTest method respectsTypeOfUnsupportedQuery.

@Test
void respectsTypeOfUnsupportedQuery() {
    // given:
    Query costAnswer = getQuery(COST_ANSWER);
    Query answerOnly = getQuery(ANSWER_ONLY);
    // when:
    Response costAnswerResponse = subject.responseGiven(costAnswer, StateView.EMPTY_VIEW, OK, 0L);
    Response answerOnlyResponse = subject.responseGiven(answerOnly, StateView.EMPTY_VIEW, OK, 0L);
    // then:
    assertEquals(COST_ANSWER, costAnswerResponse.getTokenGetAccountNftInfos().getHeader().getResponseType());
    assertEquals(ANSWER_ONLY, answerOnlyResponse.getTokenGetAccountNftInfos().getHeader().getResponseType());
    // and:
    assertEquals(NOT_SUPPORTED, subject.extractValidityFrom(costAnswerResponse));
    assertEquals(NOT_SUPPORTED, subject.extractValidityFrom(answerOnlyResponse));
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TokenGetAccountNftInfosResponse(com.hederahashgraph.api.proto.java.TokenGetAccountNftInfosResponse) Query(com.hederahashgraph.api.proto.java.Query) TokenGetAccountNftInfosQuery(com.hederahashgraph.api.proto.java.TokenGetAccountNftInfosQuery) Test(org.junit.jupiter.api.Test)

Example 24 with Query

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

the class GetTokenInfoAnswerTest method getsInfoFromCtxWhenAvailable.

@Test
void getsInfoFromCtxWhenAvailable() throws Throwable {
    // setup:
    Query sensibleQuery = validQuery(ANSWER_ONLY, 5L, tokenId);
    Map<String, Object> ctx = new HashMap<>();
    // given:
    ctx.put(GetTokenInfoAnswer.TOKEN_INFO_CTX_KEY, info);
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK, 0L, ctx);
    // then:
    var opResponse = response.getTokenGetInfo();
    assertTrue(opResponse.hasHeader(), "Missing response header!");
    assertEquals(OK, opResponse.getHeader().getNodeTransactionPrecheckCode());
    assertSame(info, opResponse.getTokenInfo());
    // and:
    verify(view, never()).infoForToken(any());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TokenGetInfoResponse(com.hederahashgraph.api.proto.java.TokenGetInfoResponse) TokenGetInfoQuery(com.hederahashgraph.api.proto.java.TokenGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test)

Example 25 with Query

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

the class GetTokenInfoAnswerTest method recognizesMissingInfoWhenNoCtxGiven.

@Test
void recognizesMissingInfoWhenNoCtxGiven() throws Throwable {
    // setup:
    Query sensibleQuery = validQuery(ANSWER_ONLY, 5L, tokenId);
    given(view.infoForToken(tokenId)).willReturn(Optional.empty());
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK, 0L);
    // then:
    TokenGetInfoResponse opResponse = response.getTokenGetInfo();
    assertTrue(opResponse.hasHeader(), "Missing response header!");
    assertEquals(INVALID_TOKEN_ID, opResponse.getHeader().getNodeTransactionPrecheckCode());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TokenGetInfoResponse(com.hederahashgraph.api.proto.java.TokenGetInfoResponse) TokenGetInfoResponse(com.hederahashgraph.api.proto.java.TokenGetInfoResponse) TokenGetInfoQuery(com.hederahashgraph.api.proto.java.TokenGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Aggregations

Query (com.hederahashgraph.api.proto.java.Query)152 Test (org.junit.jupiter.api.Test)108 Response (com.hederahashgraph.api.proto.java.Response)95 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)24 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)13 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)13 ContractGetInfoQuery (com.hederahashgraph.api.proto.java.ContractGetInfoQuery)11 ByteString (com.google.protobuf.ByteString)10 ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)10 ScheduleGetInfoQuery (com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery)10 TokenGetInfoQuery (com.hederahashgraph.api.proto.java.TokenGetInfoQuery)10 CryptoGetAccountBalanceQuery (com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery)9 CryptoGetInfoQuery (com.hederahashgraph.api.proto.java.CryptoGetInfoQuery)9 FileGetInfoQuery (com.hederahashgraph.api.proto.java.FileGetInfoQuery)8 NetworkGetExecutionTimeQuery (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeQuery)8 HashMap (java.util.HashMap)8 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)7 ContractGetBytecodeQuery (com.hederahashgraph.api.proto.java.ContractGetBytecodeQuery)7 FileGetContentsQuery (com.hederahashgraph.api.proto.java.FileGetContentsQuery)7 FileGetInfoResponse (com.hederahashgraph.api.proto.java.FileGetInfoResponse)7