LCOV - code coverage report
Current view: top level - shared_model/validators/protobuf - proto_query_validator.cpp (source / functions) Hit Total Coverage
Test: cleared_cor.info Lines: 26 26 100.0 %
Date: 2019-03-07 14:46:43 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /**
       2             :  * Copyright Soramitsu Co., Ltd. All Rights Reserved.
       3             :  * SPDX-License-Identifier: Apache-2.0
       4             :  */
       5             : 
       6             : #include "validators/protobuf/proto_query_validator.hpp"
       7             : 
       8             : #include "validators/validators_common.hpp"
       9             : 
      10             : namespace shared_model {
      11             :   namespace validation {
      12             : 
      13             :     void validatePaginationMeta(
      14             :         const iroha::protocol::TxPaginationMeta &paginationMeta,
      15             :         ReasonsGroupType &reason) {
      16          33 :       if (paginationMeta.opt_first_tx_hash_case()
      17          33 :           != iroha::protocol::TxPaginationMeta::OPT_FIRST_TX_HASH_NOT_SET) {
      18           4 :         if (not validateHexString(paginationMeta.first_tx_hash())) {
      19           2 :           reason.second.emplace_back(
      20             :               "First tx hash from pagination meta has invalid format");
      21           2 :         }
      22           4 :       }
      23          33 :     }
      24             : 
      25             :     Answer validateProtoQuery(const iroha::protocol::Query &qry) {
      26         170 :       Answer answer;
      27         170 :       std::string tx_reason_name = "Protobuf Query";
      28         170 :       ReasonsGroupType reason(tx_reason_name, GroupedReasons());
      29         171 :       switch (qry.payload().query_case()) {
      30             :         case iroha::protocol::Query_Payload::QUERY_NOT_SET: {
      31           1 :           reason.second.emplace_back("query is undefined");
      32           1 :           break;
      33             :         }
      34             :         case iroha::protocol::Query_Payload::kGetAccountTransactions: {
      35          17 :           const auto &gat = qry.payload().get_account_transactions();
      36          17 :           validatePaginationMeta(gat.pagination_meta(), reason);
      37          17 :           break;
      38             :         }
      39             :         case iroha::protocol::Query_Payload::kGetAccountAssetTransactions: {
      40          16 :           const auto &gaat = qry.payload().get_account_asset_transactions();
      41          16 :           validatePaginationMeta(gaat.pagination_meta(), reason);
      42          16 :           break;
      43             :         }
      44             :         default:
      45         136 :           break;
      46             :       }
      47         171 :       if (not reason.second.empty()) {
      48           3 :         answer.addReason(std::move(reason));
      49           3 :       }
      50         171 :       return answer;
      51         171 :     }
      52             : 
      53             :     Answer ProtoQueryValidator::validate(
      54             :         const iroha::protocol::Query &query) const {
      55         171 :       return validateProtoQuery(query);
      56             :     }
      57             : 
      58             :   }  // namespace validation
      59             : }  // namespace shared_model

Generated by: LCOV version 1.13