-
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 get_signatories_test to ExecutorItf
Signed-off-by: Mikhail Boldyrev <miboldyrev@gmail.com>
- Loading branch information
Showing
7 changed files
with
124 additions
and
283 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
78 changes: 0 additions & 78 deletions
78
test/integration/acceptance/query_permission_test_signatories.cpp
This file was deleted.
Oops, something went wrong.
51 changes: 0 additions & 51 deletions
51
test/integration/acceptance/query_permission_test_signatories.hpp
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,112 @@ | ||
/** | ||
* Copyright Soramitsu Co., Ltd. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "integration/executor/executor_fixture.hpp" | ||
|
||
#include <vector> | ||
|
||
#include <gtest/gtest.h> | ||
#include <boost/format.hpp> | ||
#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::SignatoriesResponse; | ||
using shared_model::interface::permissions::Role; | ||
|
||
struct GetSignatoriesTest : public ExecutorTestBase { | ||
/** | ||
* Generate a public key in format `public_key_NNNN', where NNNN is | ||
* a zero-padded serial number. | ||
*/ | ||
PubkeyType makePubKey(size_t n) { | ||
return PubkeyType{(boost::format("public_key_%04d") % n).str()}; | ||
} | ||
|
||
/** | ||
* Add the given number of signatories to the default account. | ||
* Signatories' public keys are generated with @see makePubKey with the number | ||
* in the order of creation. | ||
*/ | ||
void addSignatories(size_t n) { | ||
SCOPED_TRACE("addSignatories"); | ||
for (size_t i = 0; i < n; ++i) { | ||
signatories_.emplace_back(makePubKey(i)); | ||
assertResultValue(getItf().executeMaintenanceCommand( | ||
*getItf().getMockCommandFactory()->constructAddSignatory( | ||
signatories_.back(), kUserId))); | ||
} | ||
} | ||
|
||
void prepareState(size_t n) { | ||
SCOPED_TRACE("prepareState"); | ||
getItf().createDomain(kSecondDomain); | ||
assertResultValue(getItf().createUserWithPerms( | ||
kUser, kDomain, kUserKeypair.publicKey(), {})); | ||
addSignatories(n); | ||
} | ||
|
||
/// Check the response. | ||
void validateResponse(const SignatoriesResponse &response) { | ||
EXPECT_THAT(response.keys(), | ||
::testing::UnorderedElementsAreArray(signatories_)); | ||
} | ||
|
||
/// Query account signatories. | ||
QueryExecutorResult query(AccountIdType command_issuer = kAdminId) { | ||
return getItf().executeQuery( | ||
*getItf().getMockQueryFactory()->constructGetSignatories(kUserId), | ||
command_issuer); | ||
} | ||
|
||
/// The signatories of the default account. | ||
std::vector<PubkeyType> signatories_{{kUserKeypair.publicKey()}}; | ||
}; | ||
|
||
using GetSignatoriesBasicTest = BasicExecutorTest<GetSignatoriesTest>; | ||
|
||
/** | ||
* @given a user with all related permissions | ||
* @when GetSignatories is queried on a nonexistent user | ||
* @then there is an error | ||
*/ | ||
TEST_P(GetSignatoriesBasicTest, InvalidNoAccount) { | ||
checkQueryError<shared_model::interface::NoSignatoriesErrorResponse>( | ||
getItf().executeQuery( | ||
*getItf().getMockQueryFactory()->constructGetSignatories(kUserId)), | ||
error_codes::kNoStatefulError); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P(Base, | ||
GetSignatoriesBasicTest, | ||
executor_testing::getExecutorTestParams(), | ||
executor_testing::paramToString); | ||
|
||
using GetSignatoriesPermissionTest = | ||
query_permission_test::QueryPermissionTest<GetSignatoriesTest>; | ||
|
||
TEST_P(GetSignatoriesPermissionTest, QueryPermissionTest) { | ||
ASSERT_NO_FATAL_FAILURE(prepareState({})); | ||
addSignatories(2); | ||
checkResponse<SignatoriesResponse>( | ||
query(getSpectator()), [this](const SignatoriesResponse &response) { | ||
this->validateResponse(response); | ||
}); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P( | ||
Common, | ||
GetSignatoriesPermissionTest, | ||
query_permission_test::getParams({Role::kGetMySignatories}, | ||
{Role::kGetDomainSignatories}, | ||
{Role::kGetAllSignatories}), | ||
query_permission_test::paramToString); |
Oops, something went wrong.