use of com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery in project hedera-services by hashgraph.
the class GetTopicInfoAnswer method responseGiven.
@Override
public Response responseGiven(Query query, StateView view, ResponseCodeEnum validity, long cost) {
ConsensusGetTopicInfoQuery op = query.getConsensusGetTopicInfo();
ConsensusGetTopicInfoResponse.Builder response = ConsensusGetTopicInfoResponse.newBuilder();
response.setTopicID(op.getTopicID());
ResponseType type = op.getHeader().getResponseType();
if (validity != OK) {
response.setHeader(header(validity, type, cost));
} else {
if (type == COST_ANSWER) {
response.setHeader(costAnswerHeader(OK, cost));
} else {
var optionalInfo = view.infoForTopic(op.getTopicID());
if (optionalInfo.isPresent()) {
response.setHeader(answerOnlyHeader(OK));
response.setTopicInfo(optionalInfo.get());
} else {
response.setHeader(answerOnlyHeader(INVALID_TOPIC_ID));
}
}
}
return Response.newBuilder().setConsensusGetTopicInfo(response).build();
}
use of com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery in project hedera-services by hashgraph.
the class GetMerkleTopicInfoAnswerTest method syntaxCheckValidatesTidIfPresent.
@Test
void syntaxCheckValidatesTidIfPresent() {
// setup:
TopicID tid = asTopic(idLit);
// given:
ConsensusGetTopicInfoQuery op = ConsensusGetTopicInfoQuery.newBuilder().setTopicID(tid).build();
Query query = Query.newBuilder().setConsensusGetTopicInfo(op).build();
// and:
given(optionValidator.queryableTopicStatus(tid, topics)).willReturn(TOPIC_EXPIRED);
// when:
ResponseCodeEnum status = subject.checkValidity(query, view);
// expect:
assertEquals(TOPIC_EXPIRED, status);
}
use of com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery in project hedera-services by hashgraph.
the class GetMerkleTopicInfoAnswerTest method syntaxCheckRequiresId.
@Test
void syntaxCheckRequiresId() {
// given:
ConsensusGetTopicInfoQuery op = ConsensusGetTopicInfoQuery.newBuilder().build();
Query query = Query.newBuilder().setConsensusGetTopicInfo(op).build();
// when:
ResponseCodeEnum status = subject.checkValidity(query, view);
// expect:
assertEquals(INVALID_TOPIC_ID, status);
}
use of com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery in project hedera-services by hashgraph.
the class GetMerkleTopicInfoAnswerTest method requiresOkMetaValidity.
@Test
void requiresOkMetaValidity() {
// setup:
TopicID id = asTopic(idLit);
// given:
ConsensusGetTopicInfoQuery op = ConsensusGetTopicInfoQuery.newBuilder().setTopicID(id).build();
Query query = Query.newBuilder().setConsensusGetTopicInfo(op).build();
// when:
Response response = subject.responseGiven(query, view, PLATFORM_NOT_ACTIVE);
ResponseCodeEnum status = response.getConsensusGetTopicInfo().getHeader().getNodeTransactionPrecheckCode();
// expect:
assertEquals(PLATFORM_NOT_ACTIVE, status);
assertEquals(id, response.getConsensusGetTopicInfo().getTopicID());
}
use of com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery in project hedera-services by hashgraph.
the class GetTopicInfoAnswer method checkValidity.
@Override
public ResponseCodeEnum checkValidity(Query query, StateView view) {
MerkleMap<EntityNum, MerkleTopic> topics = view.topics();
ConsensusGetTopicInfoQuery op = query.getConsensusGetTopicInfo();
return validityOf(op, topics);
}
Aggregations