-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transfer add_asset_qty_test to ExecutorItf
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
- Loading branch information
Showing
8 changed files
with
231 additions
and
358 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.