Search in sources :

Example 11 with Query

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

the class GetTxnReceiptAnswerTest method expectsNonDefaultTransactionId.

@Test
void expectsNonDefaultTransactionId() {
    // setup:
    Query nonsenseQuery = queryWith(TransactionID.getDefaultInstance());
    Query sensibleQuery = queryWith(validTxnId);
    // expect:
    assertEquals(OK, subject.checkValidity(sensibleQuery, view));
    assertEquals(INVALID_TRANSACTION_ID, subject.checkValidity(nonsenseQuery, view));
}
Also used : Query(com.hederahashgraph.api.proto.java.Query) TransactionGetReceiptQuery(com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery) Test(org.junit.jupiter.api.Test)

Example 12 with Query

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

the class GetTxnReceiptAnswerTest method returnsChildrenIfRequested.

@Test
void returnsChildrenIfRequested() {
    // setup:
    Query sensibleQuery = queryWith(validTxnId, ANSWER_ONLY, false, true);
    var childReceipts = List.of(duplicateReceipt.toGrpc(), unclassifiableReceipt.toGrpc());
    given(recordCache.getPriorityReceipt(validTxnId)).willReturn(receipt);
    given(recordCache.getChildReceipts(validTxnId)).willReturn(childReceipts);
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK, 0L);
    // then:
    TransactionGetReceiptResponse opResponse = response.getTransactionGetReceipt();
    assertTrue(opResponse.hasHeader(), "Missing response header!");
    assertEquals(OK, opResponse.getHeader().getNodeTransactionPrecheckCode());
    assertEquals(ANSWER_ONLY, opResponse.getHeader().getResponseType());
    assertEquals(receipt.toGrpc(), opResponse.getReceipt());
    assertEquals(childReceipts, opResponse.getChildTransactionReceiptsList());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TransactionGetReceiptResponse(com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse) Query(com.hederahashgraph.api.proto.java.Query) TransactionGetReceiptQuery(com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery) TransactionGetReceiptResponse(com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse) Test(org.junit.jupiter.api.Test)

Example 13 with Query

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

the class GetTxnReceiptAnswerTest method rejectsQueryForMissingReceipt.

@Test
void rejectsQueryForMissingReceipt() {
    // setup:
    Query sensibleQuery = queryWith(validTxnId);
    given(recordCache.getPriorityReceipt(validTxnId)).willReturn(null);
    // when:
    Response response = subject.responseGiven(sensibleQuery, view, OK, 0L);
    // then:
    TransactionGetReceiptResponse opResponse = response.getTransactionGetReceipt();
    assertEquals(RECEIPT_NOT_FOUND, opResponse.getHeader().getNodeTransactionPrecheckCode());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) TransactionGetReceiptResponse(com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse) Query(com.hederahashgraph.api.proto.java.Query) TransactionGetReceiptQuery(com.hederahashgraph.api.proto.java.TransactionGetReceiptQuery) TransactionGetReceiptResponse(com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse) Test(org.junit.jupiter.api.Test)

Example 14 with Query

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

the class GetAccountBalanceAnswerTest method requiresNothing.

@Test
void requiresNothing() {
    // setup:
    CryptoGetAccountBalanceQuery costAnswerOp = CryptoGetAccountBalanceQuery.newBuilder().setHeader(QueryHeader.newBuilder().setResponseType(ResponseType.COST_ANSWER)).build();
    Query costAnswerQuery = Query.newBuilder().setCryptogetAccountBalance(costAnswerOp).build();
    CryptoGetAccountBalanceQuery answerOnlyOp = CryptoGetAccountBalanceQuery.newBuilder().setHeader(QueryHeader.newBuilder().setResponseType(ResponseType.ANSWER_ONLY)).build();
    Query answerOnlyQuery = Query.newBuilder().setCryptogetAccountBalance(answerOnlyOp).build();
    // expect:
    assertFalse(subject.requiresNodePayment(costAnswerQuery));
    assertFalse(subject.requiresNodePayment(answerOnlyQuery));
    assertFalse(subject.needsAnswerOnlyCost(answerOnlyQuery));
    assertFalse(subject.needsAnswerOnlyCost(costAnswerQuery));
}
Also used : CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Test(org.junit.jupiter.api.Test)

Example 15 with Query

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

the class GetAccountBalanceAnswerTest method requiresOkMetaValidity.

@Test
void requiresOkMetaValidity() {
    // setup:
    AccountID id = asAccount(accountIdLit);
    // given:
    CryptoGetAccountBalanceQuery op = CryptoGetAccountBalanceQuery.newBuilder().setAccountID(id).build();
    Query query = Query.newBuilder().setCryptogetAccountBalance(op).build();
    // when:
    Response response = subject.responseGiven(query, view, PLATFORM_NOT_ACTIVE);
    ResponseCodeEnum status = response.getCryptogetAccountBalance().getHeader().getNodeTransactionPrecheckCode();
    // expect:
    assertEquals(PLATFORM_NOT_ACTIVE, status);
    assertEquals(id, response.getCryptogetAccountBalance().getAccountID());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) CryptoGetAccountBalanceResponse(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceResponse) ResponseCodeEnum(com.hederahashgraph.api.proto.java.ResponseCodeEnum) AccountID(com.hederahashgraph.api.proto.java.AccountID) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) Query(com.hederahashgraph.api.proto.java.Query) CryptoGetAccountBalanceQuery(com.hederahashgraph.api.proto.java.CryptoGetAccountBalanceQuery) 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