Skip to content

Commit

Permalink
revert wallet api and change test to nonparallelizable_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
allenhan2 committed May 27, 2020
1 parent e1b4f6d commit 8e42a66
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 40 deletions.
12 changes: 0 additions & 12 deletions plugins/http_plugin/include/eosio/http_plugin/http_plugin.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,6 @@ namespace eosio {
}
} EOS_RETHROW_EXCEPTIONS(chain::invalid_http_request, "Unable to parse valid input from POST body");
}
template<typename T1, typename T2>
struct two_params {
T1 p1;
T2 p2;
};

template<typename T1, typename T2, typename T3>
struct three_params {
T1 p1;
T2 p2;
T3 p3;
};
}

FC_REFLECT(eosio::error_results::error_info::error_detail, (message)(file)(line_number)(method))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <eosio/wallet_plugin/wallet_plugin.hpp>
#include <eosio/http_plugin/http_plugin.hpp>
#include <fc/reflect/reflect.hpp>

#include <appbase/application.hpp>

Expand All @@ -29,15 +28,4 @@ class wallet_api_plugin : public plugin<wallet_api_plugin> {
private:
};

typedef two_params<std::string, std::string> two_string_params;
typedef two_params<chain::digest_type, chain::public_key_type> two_params_sign_digest;
typedef three_params<std::string, std::string, std::string> three_string_params;
typedef three_params<chain::signed_transaction, chain::flat_set<chain::public_key_type>, chain::chain_id_type> three_params_sign_trx;

}

FC_REFLECT( eosio::two_string_params, (p1)(p2) )
FC_REFLECT( eosio::two_params_sign_digest, (p1)(p2) )
FC_REFLECT( eosio::three_string_params, (p1)(p2)(p3) )
FC_REFLECT( eosio::three_params_sign_trx, (p1)(p2)(p3) )

27 changes: 18 additions & 9 deletions plugins/wallet_api_plugin/wallet_api_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ using namespace eosio;
auto result = api_handle.call_name( std::move(params) );

#define INVOKE_R_R_R(api_handle, call_name, in_param0, in_param1) \
const auto& params = parse_params<two_params<in_param0, in_param1>, http_params_types::params_required>(body);\
auto result = api_handle.call_name(params.p1, params.p2);
const auto& params = parse_params<fc::variants, http_params_types::params_required>(body);\
if (params.size() != 2) { \
EOS_THROW(chain::invalid_http_request, "Missing valid input from POST body"); \
} \
auto result = api_handle.call_name(params.at(0).as<in_param0>(), params.at(1).as<in_param1>());

// chain_id_type does not have default constructor, keep it unchanged
#define INVOKE_R_R_R_R(api_handle, call_name, in_param0, in_param1, in_param2) \
const auto& vs = parse_params<fc::variants, http_params_types::params_required>(body);\
if (vs.size() != 3) { \
const auto& params = parse_params<fc::variants, http_params_types::params_required>(body);\
if (params.size() != 3) { \
EOS_THROW(chain::invalid_http_request, "Missing valid input from POST body"); \
} \
auto result = api_handle.call_name(vs.at(0).as<in_param0>(), vs.at(1).as<in_param1>(), vs.at(2).as<in_param2>());
auto result = api_handle.call_name(params.at(0).as<in_param0>(), params.at(1).as<in_param1>(), params.at(2).as<in_param2>());

#define INVOKE_R_V(api_handle, call_name) \
body = parse_params<std::string, http_params_types::no_params_required>(body); \
Expand All @@ -57,13 +60,19 @@ using namespace eosio;
eosio::detail::wallet_api_plugin_empty result;

#define INVOKE_V_R_R(api_handle, call_name, in_param0, in_param1) \
const auto& params = parse_params<two_params<in_param0, in_param1>, http_params_types::params_required>(body);\
api_handle.call_name(params.p1, params.p2); \
const auto& params = parse_params<fc::variants, http_params_types::params_required>(body);\
if (params.size() != 2) { \
EOS_THROW(chain::invalid_http_request, "Missing valid input from POST body"); \
} \
api_handle.call_name(params.at(0).as<in_param0>(), params.at(1).as<in_param1>()); \
eosio::detail::wallet_api_plugin_empty result;

#define INVOKE_V_R_R_R(api_handle, call_name, in_param0, in_param1, in_param2) \
const auto& params = parse_params<three_params<in_param0, in_param1, in_param2>, http_params_types::params_required>(body);\
api_handle.call_name(params.p1, params.p2, params.p3); \
const auto& params = parse_params<fc::variants, http_params_types::params_required>(body);\
if (params.size() != 3) { \
EOS_THROW(chain::invalid_http_request, "Missing valid input from POST body"); \
} \
api_handle.call_name(params.at(0).as<in_param0>(), params.at(1).as<in_param1>(), params.at(2).as<in_param2>()); \
eosio::detail::wallet_api_plugin_empty result;

#define INVOKE_V_V(api_handle, call_name) \
Expand Down
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ set_property(TEST nodeos_repeat_transaction_lr_test PROPERTY LABELS long_running
add_test(NAME cli_test COMMAND tests/cli_test.py WORKING_DIRECTORY ${CMAKE_BINARY_DIR})

add_test(NAME plugin_http_api_test COMMAND tests/plugin_http_api_test.py -v --clean-run --dump-error-detail WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
set_tests_properties(plugin_http_api_test PROPERTIES TIMEOUT 3000)
set_property(TEST plugin_http_api_test PROPERTY LABELS plugin_http_api_tests)
set_tests_properties(plugin_http_api_test PROPERTIES TIMEOUT 40)
set_property(TEST plugin_http_api_test PROPERTY LABELS nonparallelizable_tests)

add_subdirectory(se_tests)

Expand Down
10 changes: 5 additions & 5 deletions tests/plugin_http_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def test_WalletApi(self) :
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# unlock with valid parameter
valid_cmd = default_cmd + self.http_post_str + ("'{\"name\":\"auser\", \"password\":\"nopassword\"}'")
valid_cmd = default_cmd + self.http_post_str + ("'[\"auser\", \"nopassword\"]'")
ret_json = Utils.runCmdReturnJson(valid_cmd)
self.assertEqual(ret_json["code"], 500)

Expand All @@ -983,7 +983,7 @@ def test_WalletApi(self) :
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# import_key with valid parameter
valid_cmd = default_cmd + self.http_post_str + ("{'\"name\":\"auser\", \"wif_key\":\"nokey\"'}")
valid_cmd = default_cmd + self.http_post_str + ("'[\"auser\", \"nokey\"]'")
ret_json = Utils.runCmdReturnJson(valid_cmd)
self.assertEqual(ret_json["code"], 500)

Expand All @@ -998,7 +998,7 @@ def test_WalletApi(self) :
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# remove_key with valid parameter
valid_cmd = default_cmd + self.http_post_str + ("{'\"name\":\"auser\", \"password\":\"none\", \"key\":\"none\"'}")
valid_cmd = default_cmd + self.http_post_str + ("'[\"auser\", \"none\", \"none\"]'")
ret_json = Utils.runCmdReturnJson(valid_cmd)
self.assertEqual(ret_json["code"], 500)

Expand All @@ -1013,7 +1013,7 @@ def test_WalletApi(self) :
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# create_key with valid parameter
valid_cmd = default_cmd + self.http_post_str + ("{'\"name\":\"auser\", \"key_type\":\"none\"'}")
valid_cmd = default_cmd + self.http_post_str + ("'[\"auser\", \"none\", \"none\"]'")
ret_json = Utils.runCmdReturnJson(valid_cmd)
self.assertEqual(ret_json["code"], 500)

Expand All @@ -1038,7 +1038,7 @@ def test_WalletApi(self) :
self.assertEqual(ret_json["code"], 400)
self.assertEqual(ret_json["error"]["code"], 3200006)
# list_keys with valid parameter
valid_cmd = default_cmd + self.http_post_str + ("{'\"name\":\"auser\", \"pw\":\"unknownkey\"'}")
valid_cmd = default_cmd + self.http_post_str + ("'[\"auser\", \"unknownkey\"]'")
ret_json = Utils.runCmdReturnJson(valid_cmd)
self.assertEqual(ret_json["code"], 500)

Expand Down

0 comments on commit 8e42a66

Please sign in to comment.