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