Skip to content

Commit

Permalink
transfer GetAssetInfo tests to ExecutorItf
Browse files Browse the repository at this point in the history
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
  • Loading branch information
MBoldyrev committed Oct 29, 2019
1 parent 046262d commit 9d06e7d
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 255 deletions.
8 changes: 0 additions & 8 deletions test/integration/acceptance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,6 @@ target_link_libraries(remove_signatory_test
integration_framework
)

addtest(get_asset_info_test
get_asset_info_test.cpp
)
target_link_libraries(get_asset_info_test
acceptance_fixture
integration_framework
)

addtest(get_role_permissions_test
get_role_permissions_test.cpp
)
Expand Down
160 changes: 0 additions & 160 deletions test/integration/acceptance/get_asset_info_test.cpp

This file was deleted.

8 changes: 8 additions & 0 deletions test/integration/executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ target_link_libraries(get_account_detail_test
query_permission_test
)

addtest(get_asset_info_test get_asset_info_test.cpp)
target_link_libraries(get_asset_info_test
executor_fixture
executor_fixture_param_provider
common_test_constants
query_permission_test
)

add_library(query_permission_test query_permission_test.cpp)
target_link_libraries(query_permission_test
executor_fixture
Expand Down
80 changes: 80 additions & 0 deletions test/integration/executor/get_asset_info_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright Soramitsu Co., Ltd. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#include "integration/executor/executor_fixture.hpp"

#include <gtest/gtest.h>
#include "framework/common_constants.hpp"
#include "integration/executor/query_permission_test.hpp"
#include "module/shared_model/mock_objects_factories/mock_command_factory.hpp"
#include "module/shared_model/mock_objects_factories/mock_query_factory.hpp"

using namespace common_constants;
using namespace executor_testing;
using namespace framework::expected;
using namespace shared_model::interface::types;

using iroha::ametsuchi::QueryExecutorResult;
using shared_model::interface::AssetResponse;
using shared_model::interface::permissions::Role;

constexpr PrecisionType kAssetPrecision(1);

struct GetAssetInfoTest : public ExecutorTestBase {
void prepareAsset() {
SCOPED_TRACE("GetAssetInfoTest::prepareAsset");
createAsset(kAssetName, kDomain, kAssetPrecision);
}

/// Check the response.
void validateResponse(const AssetResponse &response) {
EXPECT_EQ(response.asset().assetId(), kAssetId);
EXPECT_EQ(response.asset().domainId(), kDomain);
EXPECT_EQ(response.asset().precision(), kAssetPrecision);
}

/// Query asset info.
QueryExecutorResult query(AccountIdType command_issuer = kAdminId) {
return getItf().executeQuery(
*getItf().getMockQueryFactory()->constructGetAssetInfo(kAssetId),
command_issuer);
}
};

using GetAssetInfoBasicTest = BasicExecutorTest<GetAssetInfoTest>;

/**
* @given a user with all related permissions
* @when GetAssetInfo is queried on a nonexistent asset
* @then there is an error
*/
TEST_P(GetAssetInfoBasicTest, InvalidNoAsset) {
checkQueryError<shared_model::interface::NoAssetErrorResponse>(
query(), error_codes::kNoStatefulError);
}

INSTANTIATE_TEST_CASE_P(Base,
GetAssetInfoBasicTest,
executor_testing::getExecutorTestParams(),
executor_testing::paramToString);

using GetAssetInfoPermissionTest =
query_permission_test::QueryPermissionTest<GetAssetInfoTest>;

TEST_P(GetAssetInfoPermissionTest, QueryPermissionTest) {
ASSERT_NO_FATAL_FAILURE(prepareState({}));
prepareAsset();
checkResponse<AssetResponse>(query(getSpectator()),
[this](const AssetResponse &response) {
this->validateResponse(response);
});
}

INSTANTIATE_TEST_CASE_P(Common,
GetAssetInfoPermissionTest,
query_permission_test::getParams({boost::none},
{boost::none},
{Role::kReadAssets}),
query_permission_test::paramToString);
87 changes: 0 additions & 87 deletions test/module/irohad/ametsuchi/postgres_query_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,93 +761,6 @@ namespace iroha {
});
}

class GetAssetInfoExecutorTest : public QueryExecutorTest {
public:
void SetUp() override {
QueryExecutorTest::SetUp();
}

void createAsset() {
execute(
*mock_command_factory->constructCreateAsset("coin", domain_id, 1),
true);
}
const std::string asset_id = "coin#domain";
};

/**
* @given initialized storage, permission to read all system assets
* @when get asset info
* @then Return asset
*/
TEST_F(GetAssetInfoExecutorTest, Valid) {
addPerms({shared_model::interface::permissions::Role::kReadAssets});
createAsset();
auto query = TestQueryBuilder()
.creatorAccountId(account_id)
.getAssetInfo(asset_id)
.build();
auto result = executeQuery(query);
checkSuccessfulResult<shared_model::interface::AssetResponse>(
std::move(result), [this](const auto &cast_resp) {
ASSERT_EQ(cast_resp.asset().assetId(), asset_id);
ASSERT_EQ(cast_resp.asset().domainId(), domain_id);
ASSERT_EQ(cast_resp.asset().precision(), 1);
});
}

/**
* @given initialized storage, all permissions
* @when get asset info of non existing asset
* @then Error
*/
TEST_F(GetAssetInfoExecutorTest, InvalidNoAsset) {
addPerms({shared_model::interface::permissions::Role::kReadAssets});
auto query = TestQueryBuilder()
.creatorAccountId(account_id)
.getAssetInfo("some#domain")
.build();
auto result = executeQuery(query);
checkStatefulError<shared_model::interface::NoAssetErrorResponse>(
std::move(result), kNoStatefulError);
}

/**
* @given initialized storage, no permissions
* @when get asset info
* @then Error
*/
TEST_F(GetAssetInfoExecutorTest, Invalid) {
auto query = TestQueryBuilder()
.creatorAccountId(account_id)
.getAssetInfo(asset_id)
.build();
auto result = executeQuery(query);
checkStatefulError<shared_model::interface::StatefulFailedErrorResponse>(
std::move(result), kNoPermissions);
}

/**
* @given initialized storage, root permission
* @when get asset info
* @then Return asset
*/
TEST_F(GetAssetInfoExecutorTest, ValidWithRoot) {
addPerms({shared_model::interface::permissions::Role::kRoot});
createAsset();
auto query = TestQueryBuilder()
.creatorAccountId(account_id)
.getAssetInfo(asset_id)
.build();
auto result = executeQuery(query);
checkSuccessfulResult<shared_model::interface::AssetResponse>(
std::move(result), [this](const auto &cast_resp) {
ASSERT_EQ(cast_resp.asset().assetId(), asset_id);
ASSERT_EQ(cast_resp.asset().domainId(), domain_id);
ASSERT_EQ(cast_resp.asset().precision(), 1);
});
}

class GetTransactionsExecutorTest : public QueryExecutorTest {
public:
void SetUp() override {
Expand Down

0 comments on commit 9d06e7d

Please sign in to comment.