Skip to content

Commit

Permalink
Shared model/torii test (hyperledger-iroha#1202)
Browse files Browse the repository at this point in the history
* Remove old model from Torii test

Signed-off-by: Dumitru <[email protected]>

* Docs

Signed-off-by: Dumitru <[email protected]>

* Fix typo

Signed-off-by: Dumitru <[email protected]>

* Remove getError, refactor

Signed-off-by: Dumitru <[email protected]>
  • Loading branch information
x3medima17 authored Apr 12, 2018
1 parent a9f4923 commit f1db8a1
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#define IROHA_SHARED_MODEL_QUERY_ERROR_RESPONSE_HPP

#include <boost/variant.hpp>

#include "interfaces/base/primitive.hpp"
#include "interfaces/query_responses/error_responses/no_account_assets_error_response.hpp"
#include "interfaces/query_responses/error_responses/no_account_detail_error_response.hpp"
Expand All @@ -29,6 +30,7 @@
#include "interfaces/query_responses/error_responses/not_supported_error_response.hpp"
#include "interfaces/query_responses/error_responses/stateful_failed_error_response.hpp"
#include "interfaces/query_responses/error_responses/stateless_failed_error_response.hpp"
#include "utils/visitor_apply_for_all.hpp"

namespace shared_model {
namespace interface {
Expand Down
30 changes: 9 additions & 21 deletions test/module/irohad/torii/processor/query_processor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
* limitations under the License.
*/

#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/validation/validation_mocks.hpp"
#include "validators/permissions.hpp"

#include "framework/test_subscriber.hpp"
#include "model/queries/responses/error_response.hpp"
#include "model/query_execution.hpp"
#include "network/ordering_gate.hpp"
#include "torii/processor/query_processor_impl.hpp"

#include "backend/protobuf/query_responses/proto_error_query_response.hpp"
#include "builders/protobuf/common_objects/proto_account_builder.hpp"
#include "cryptography/crypto_provider/crypto_defaults.hpp"
#include "cryptography/keypair.hpp"
#include "framework/test_subscriber.hpp"
#include "model/query_execution.hpp"
#include "module/irohad/ametsuchi/ametsuchi_mocks.hpp"
#include "module/irohad/validation/validation_mocks.hpp"
#include "module/shared_model/builders/protobuf/test_query_builder.hpp"
#include "module/shared_model/builders/protobuf/test_query_response_builder.hpp"
#include "network/ordering_gate.hpp"
#include "torii/processor/query_processor_impl.hpp"
#include "validators/permissions.hpp"

using namespace iroha;
using namespace iroha::ametsuchi;
Expand All @@ -54,9 +52,6 @@ class QueryProcessorTest : public ::testing::Test {
shared_model::crypto::Keypair keypair =
shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();

decltype(shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair())
pair =
shared_model::crypto::DefaultCryptoAlgorithmType::generateKeypair();
std::vector<shared_model::interface::types::PubkeyType> signatories = {
keypair.publicKey()};
};
Expand All @@ -83,12 +78,9 @@ TEST_F(QueryProcessorTest, QueryProcessorWhereInvokeInvalidQuery) {
.build()
.signAndAddSignature(keypair);

auto qry_resp = std::make_shared<model::AccountResponse>();
auto account = model::Account();
account.account_id = account_id;
qry_resp->account = account;
std::shared_ptr<shared_model::interface::Account> shared_account = clone(
shared_model::proto::AccountBuilder().accountId(account_id).build());

auto role = "admin";
std::vector<std::string> roles = {role};
std::vector<std::string> perms = {
Expand Down Expand Up @@ -140,10 +132,6 @@ TEST_F(QueryProcessorTest, QueryProcessorWithWrongKey) {
shared_model::crypto::DefaultCryptoAlgorithmType::
generateKeypair());

auto qry_resp = std::make_shared<model::AccountResponse>();
auto account = model::Account();
account.account_id = account_id;
qry_resp->account = account;
std::shared_ptr<shared_model::interface::Account> shared_account = clone(
shared_model::proto::AccountBuilder().accountId(account_id).build());
auto role = "admin";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/

#include <boost/range/join.hpp>

#include "builders/protobuf/proposal.hpp"
#include "builders/protobuf/transaction.hpp"
#include "framework/test_subscriber.hpp"
Expand Down
44 changes: 25 additions & 19 deletions test/module/irohad/torii/query_service_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

#include "torii/query_service.hpp"
#include "backend/protobuf/query_responses/proto_query_response.hpp"
#include "builders/protobuf/common_objects/proto_account_builder.hpp"
#include "builders/protobuf/queries.hpp"
#include "module/irohad/torii/torii_mocks.hpp"
#include "module/shared_model/builders/protobuf/test_query_response_builder.hpp"
#include "utils/query_error_response_visitor.hpp"

using namespace torii;

Expand Down Expand Up @@ -48,19 +51,16 @@ class QueryServiceTest : public ::testing::Test {
shared_model::crypto::DefaultCryptoAlgorithmType::
generateKeypair()));

// TODO: IR-1041 Update to query response builders (kamilsa, 04.03.2018)
protocol::QueryResponse response;
response.set_query_hash(
shared_model::crypto::toBinaryString(query->hash()));
auto account_response = response.mutable_account_response();
account_response->add_account_roles("user");
auto account = account_response->mutable_account();
account->set_domain_id("ru");
account->set_account_id("a");
account->set_quorum(2);

model_response = std::make_shared<shared_model::proto::QueryResponse>(
std::move(response));
auto account = shared_model::proto::AccountBuilder()
.accountId("a")
.domainId("ru")
.quorum(2)
.build();

model_response = clone(TestQueryResponseBuilder()
.accountResponse(account, {"user"})
.queryHash(query->hash())
.build());
}

void init() {
Expand Down Expand Up @@ -99,8 +99,8 @@ TEST_F(QueryServiceTest, ValidWhenUniqueHash) {

protocol::QueryResponse response;
query_service->Find(query->getTransport(), response);
ASSERT_EQ(response.SerializeAsString(),
model_response->getTransport().SerializeAsString());
auto resp = shared_model::proto::QueryResponse(response);
ASSERT_EQ(resp, *model_response);
}

/**
Expand Down Expand Up @@ -129,8 +129,11 @@ TEST_F(QueryServiceTest, InvalidWhenUniqueHash) {
protocol::QueryResponse response;
query_service->Find(query->getTransport(), response);
ASSERT_TRUE(response.has_error_response());
ASSERT_EQ(response.error_response().reason(),
protocol::ErrorResponse::NOT_SUPPORTED);
auto resp = shared_model::proto::QueryResponse(response);
ASSERT_TRUE(boost::apply_visitor(
shared_model::interface::QueryErrorResponseChecker<
shared_model::interface::NotSupportedErrorResponse>(),
resp.get()));
}

/**
Expand All @@ -154,6 +157,9 @@ TEST_F(QueryServiceTest, InvalidWhenDuplicateHash) {
// second call of the same query
query_service->Find(query->getTransport(), response);
ASSERT_TRUE(response.has_error_response());
ASSERT_EQ(response.error_response().reason(),
protocol::ErrorResponse::STATELESS_INVALID);
auto resp = shared_model::proto::QueryResponse(response);
ASSERT_TRUE(boost::apply_visitor(
shared_model::interface::QueryErrorResponseChecker<
shared_model::interface::StatelessFailedErrorResponse>(),
resp.get()));
}
1 change: 1 addition & 0 deletions test/module/irohad/torii/torii_mocks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

namespace iroha {
namespace torii {

class MockQueryProcessor : public QueryProcessor {
public:
MOCK_METHOD1(queryHandle,
Expand Down
Loading

0 comments on commit f1db8a1

Please sign in to comment.