Search in sources :

Example 26 with Response

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

the class GetTokenInfoAnswerTest method getsCostAnswerResponse.

@Test
void getsCostAnswerResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, tokenId);
    // when:
    Response response = subject.responseGiven(query, view, OK, fee);
    // then:
    assertTrue(response.hasTokenGetInfo());
    assertEquals(OK, response.getTokenGetInfo().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, response.getTokenGetInfo().getHeader().getResponseType());
    assertEquals(fee, response.getTokenGetInfo().getHeader().getCost());
}
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) Test(org.junit.jupiter.api.Test)

Example 27 with Response

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

the class GetTokenNftInfoAnswerTest method validatesEmptyInfo.

@Test
void validatesEmptyInfo() throws Throwable {
    // setup:
    Query sensibleQuery = validQuery(ANSWER_ONLY, 5L, nftId);
    given(view.infoForNft(nftId)).willReturn(Optional.empty());
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK);
    // then:
    var opResponse = response.getTokenGetNftInfo();
    assertTrue(opResponse.hasHeader(), "Missing response header!");
    assertEquals(INVALID_NFT_ID, opResponse.getHeader().getNodeTransactionPrecheckCode());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TokenGetNftInfoResponse(com.hederahashgraph.api.proto.java.TokenGetNftInfoResponse) TokenGetNftInfoQuery(com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Example 28 with Response

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

the class GetTokenNftInfoAnswerTest method getsInfoFromCtxWhenAvailable.

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

Example 29 with Response

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

the class QueryUtils method reflectForHeaderField.

private static Object reflectForHeaderField(Response response, String field) throws Throwable {
    String getterName = Arrays.stream(Response.class.getDeclaredMethods()).map(Method::getName).filter(name -> !"hashCode".equals(name) && name.startsWith("has")).filter(name -> {
        try {
            return (Boolean) Response.class.getMethod(name).invoke(response);
        } catch (Exception ignore) {
        }
        return false;
    }).map(name -> name.replace("has", "get")).findAny().get();
    Method getter = Response.class.getMethod(getterName);
    Class<?> getterClass = getter.getReturnType();
    Method headerMethod = getterClass.getMethod("getHeader");
    ResponseHeader header = (ResponseHeader) headerMethod.invoke(getter.invoke(response));
    Method fieldGetter = ResponseHeader.class.getMethod(asGetter(field));
    return fieldGetter.invoke(header);
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) ResponseHeader(com.hederahashgraph.api.proto.java.ResponseHeader) Transaction(com.hederahashgraph.api.proto.java.Transaction) Arrays(java.util.Arrays) QueryHeader(com.hederahashgraph.api.proto.java.QueryHeader) ANSWER_ONLY(com.hederahashgraph.api.proto.java.ResponseType.ANSWER_ONLY) Query(com.hederahashgraph.api.proto.java.Query) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) TransactionID(com.hederahashgraph.api.proto.java.TransactionID) Response(com.hederahashgraph.api.proto.java.Response) COST_ANSWER(com.hederahashgraph.api.proto.java.ResponseType.COST_ANSWER) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) TransactionGetReceiptQuery(com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery) HapiApiSpec(com.hedera.services.bdd.spec.HapiApiSpec) Method(java.lang.reflect.Method) ResponseHeader(com.hederahashgraph.api.proto.java.ResponseHeader) PropertySource.asAccountString(com.hedera.services.bdd.spec.PropertySource.asAccountString) Method(java.lang.reflect.Method)

Example 30 with Response

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

the class HapiContractCallLocal method lookupCostWith.

@Override
protected long lookupCostWith(HapiApiSpec spec, Transaction payment) throws Throwable {
    Query query = getContractCallLocal(spec, payment, true);
    Response response = spec.clients().getScSvcStub(targetNodeFor(spec), useTls).contractCallLocalMethod(query);
    return costFrom(response);
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) Query(com.hederahashgraph.api.proto.java.Query) ContractCallLocalQuery(com.hederahashgraph.api.proto.java.ContractCallLocalQuery)

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