Search in sources :

Example 1 with ConsensusGetTopicInfoQuery

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();
}
Also used : ConsensusGetTopicInfoQuery(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery) ConsensusGetTopicInfoResponse(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoResponse) ResponseType(com.hederahashgraph.api.proto.java.ResponseType)

Example 2 with ConsensusGetTopicInfoQuery

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

Example 3 with ConsensusGetTopicInfoQuery

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

Example 4 with ConsensusGetTopicInfoQuery

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

Example 5 with ConsensusGetTopicInfoQuery

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);
}
Also used : ConsensusGetTopicInfoQuery(com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery) MerkleTopic(com.hedera.services.state.merkle.MerkleTopic) EntityNum(com.hedera.services.utils.EntityNum)

Aggregations

ConsensusGetTopicInfoQuery (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoQuery)5 Query (com.hederahashgraph.api.proto.java.Query)3 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)3 Test (org.junit.jupiter.api.Test)3 ConsensusGetTopicInfoResponse (com.hederahashgraph.api.proto.java.ConsensusGetTopicInfoResponse)2 TopicID (com.hederahashgraph.api.proto.java.TopicID)2 MerkleTopic (com.hedera.services.state.merkle.MerkleTopic)1 EntityNum (com.hedera.services.utils.EntityNum)1 Response (com.hederahashgraph.api.proto.java.Response)1 ResponseType (com.hederahashgraph.api.proto.java.ResponseType)1