Skip to content

Commit

Permalink
transfer add_asset_qty_test 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 Aug 23, 2019
1 parent ab3d668 commit 01af51b
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 358 deletions.
1 change: 1 addition & 0 deletions test/framework/common_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace common_constants {
const std::string kSameDomainUserId = kAnotherUser + "@" + kDomain;
const std::string kAnotherDomainUserId = kAnotherUser + "@" + kSecondDomain;
const std::string kAssetId = kAssetName + "#" + kDomain;
const std::string kSecondDomainAssetId = kAssetName + "#" + kSecondDomain;

// keypairs
const Keypair kAdminKeypair = DefaultCryptoAlgorithmType::generateKeypair();
Expand Down
1 change: 1 addition & 0 deletions test/framework/common_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace common_constants {
extern const std::string kSameDomainUserId;
extern const std::string kAnotherDomainUserId;
extern const std::string kAssetId;
extern const std::string kSecondDomainAssetId;

/// keypairs
extern const Keypair kAdminKeypair;
Expand Down
6 changes: 0 additions & 6 deletions test/integration/acceptance/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ target_link_libraries(grantable_permissions_fixture
integration_framework
)

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

addtest(add_peer_test add_peer_test.cpp)
target_link_libraries(add_peer_test
acceptance_fixture
Expand Down
137 changes: 0 additions & 137 deletions test/integration/acceptance/add_asset_qty_test.cpp

This file was deleted.

7 changes: 7 additions & 0 deletions test/integration/executor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,10 @@ add_library(executor_fixture_param_provider executor_fixture_param_provider.cpp)
target_link_libraries(executor_fixture_param_provider
executor_fixture_param_postgres
)

addtest(add_asset_qty_test add_asset_qty_test.cpp)
target_link_libraries(add_asset_qty_test
executor_fixture
executor_fixture_param_provider
common_test_constants
)
218 changes: 218 additions & 0 deletions test/integration/executor/add_asset_qty_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/**
* 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 "framework/result_gtest_checkers.hpp"
#include "integration/executor/executor_fixture_param_provider.hpp"
#include "interfaces/common_objects/amount.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 shared_model::interface::permissions::Grantable;
using shared_model::interface::permissions::Role;

using shared_model::interface::Amount;

static const Amount kAmount{std::string{"12.3"}};

using AddAssetQuantityBasicTest =
executor_testing::BasicExecutorTest<executor_testing::ExecutorTestBase>;

/**
* @given an asset in another domain and a user with kAddAssetQty permission
* @when execute AddAssetQuantity command from that user for that asset
* @then the command succeeds
* @and the asset quantity gets increased
*/
TEST_P(AddAssetQuantityBasicTest, Basic) {
getItf().createDomain(kSecondDomain);
createAsset(kAssetName, kSecondDomain, 1);
assertResultValue(getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {Role::kAddAssetQty}));

expectResultValue(getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kSecondDomainAssetId, kAmount),
kUserId,
true));

checkAssetQuantities(kUserId, {AssetQuantity{kSecondDomainAssetId, kAmount}});
}

/**
* @given a user with kAddDomainAssetQty permission and an asset in the same
* domain
* @when execute AddAssetQuantity command from that user for that asset
* @then the command succeeds
* @and the asset quantity gets increased
*/
TEST_P(AddAssetQuantityBasicTest, DomainPermValid) {
createAsset(kAssetName, kDomain, 1);
assertResultValue(getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {Role::kAddDomainAssetQty}));

expectResultValue(getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(kAssetId,
kAmount),
kUserId,
true));

checkAssetQuantities(kUserId, {AssetQuantity{kAssetId, kAmount}});
}

/**
* @given a user with kAddDomainAssetQty permission and an asset in another
* domain
* @when execute AddAssetQuantity command from that user for that asset
* @then the command fails
* @and the asset is not added to the user
*/
TEST_P(AddAssetQuantityBasicTest, DomainPermInvalid) {
getItf().createDomain(kSecondDomain);
createAsset(kAssetName, kSecondDomain, 1);
assertResultValue(getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {Role::kAddDomainAssetQty}));

checkCommandError(
getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kSecondDomainAssetId, kAmount),
kUserId,
true),
2);

checkAssetQuantities(kUserId, {});
}

/**
* @given a user without any permissions and an asset in the same domain
* @when execute AddAssetQuantity command from that user for that asset
* @then the command fails
* @and the asset is not added to the user
*/
TEST_P(AddAssetQuantityBasicTest, NoPermissions) {
createAsset(kAssetName, kDomain, 1);
assertResultValue(getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {}));

checkCommandError(
getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(kAssetId,
kAmount),
kUserId,
true),
2);

checkAssetQuantities(kUserId, {});
}

/**
* @given an asset in another domain and a user with root permission
* @when execute AddAssetQuantity command from that user for that asset
* @then the command succeeds
* @and the asset quantity gets increased
*/
TEST_P(AddAssetQuantityBasicTest, RootPermission) {
getItf().createDomain(kSecondDomain);
createAsset(kAssetName, kSecondDomain, 1);
assertResultValue(getItf().createUserWithPerms(
kUser, kDomain, kUserKeypair.publicKey(), {Role::kRoot}));

expectResultValue(getItf().executeCommandAsAccount(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kSecondDomainAssetId, kAmount),
kUserId,
true));

checkAssetQuantities(kUserId, {AssetQuantity{kSecondDomainAssetId, kAmount}});
}

/**
* @given a user with all related permissions
* @when execute AddAssetQuantity command from that user for nonexistent asset
* @then the command fails
* @and the asset is not added to the user
*/
TEST_P(AddAssetQuantityBasicTest, InvalidAsset) {
checkCommandError(
getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, kAmount)),
3);

checkAssetQuantities(kAdminId, {});
}

/**
* @given a user with all related permissions having the maximum amount of an
* asset with precision 1
* @when execute AddAssetQuantity command from that user for that asset that
* would overflow the asset quantity by:
* 1) minimum amount quantity of that asset precision
* 2) minimum amount quantity of less precision
* @then both commands fail
* @and the asset amount is not increased
*/
TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision1) {
createAsset(kAssetName, kDomain, 1);
assertResultValue(getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, kAmountPrec1Max)));
checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}});

checkCommandError(
getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, Amount{"0.1"})),
4);
checkCommandError(
getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, Amount{"1"})),
4);
checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec1Max}});
}

/**
* @given a user with all related permissions having the maximum amount of an
* asset with precision 2
* @when execute AddAssetQuantity command from that user for that asset that
* would overflow the asset quantity by:
* 1) minimum amount quantity of that asset precision
* 2) minimum amount quantity of less precision
* @then both commands fail
* @and the asset amount is not increased
*/
TEST_P(AddAssetQuantityBasicTest, DestOverflowPrecision2) {
createAsset(kAssetName, kDomain, 2);
assertResultValue(getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, kAmountPrec2Max)));
checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}});

checkCommandError(
getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, Amount{"0.01"})),
4);
checkCommandError(
getItf().executeMaintenanceCommand(
*getItf().getMockCommandFactory()->constructAddAssetQuantity(
kAssetId, Amount{"0.1"})),
4);
checkAssetQuantities(kAdminId, {AssetQuantity{kAssetId, kAmountPrec2Max}});
}

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

0 comments on commit 01af51b

Please sign in to comment.