Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the fix to make top 4 apis configurable #1673

Merged
merged 6 commits into from
Jun 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ void application_impl::set_api_limit() {
if(_options->count("api-limit-get-asset-holders")){
_app_options.api_limit_get_asset_holders = _options->at("api-limit-get-asset-holders").as<uint64_t>();
}
if(_options->count("api-limit-get-key-references")){
_app_options.api_limit_get_key_references = _options->at("api-limit-get-key-references").as<uint64_t>();
}
if(_options->count("api-limit-get-key-references")){
_app_options.api_limit_get_key_references = _options->at("api-limit-get-key-references").as<uint64_t>();
}
if(_options->count("api-limit-get-htlc-by")) {
_app_options.api_limit_get_htlc_by = _options->at("api-limit-get-htlc-by").as<uint64_t>();
}
Expand All @@ -358,6 +358,12 @@ void application_impl::set_api_limit() {
if(_options->count("api-limit-get-assets")) {
_app_options.api_limit_get_assets = _options->at("api-limit-get-assets").as<uint64_t>();
}
if(_options->count("api-limit-get-limit-orders")){
_app_options.api_limit_get_limit_orders = _options->at("api-limit-get-limit-orders").as<uint64_t>();
}
if(_options->count("api-limit-get-order-book")){
_app_options.api_limit_get_order_book = _options->at("api-limit-get-order-book").as<uint64_t>();
}
}

void application_impl::startup()
Expand Down Expand Up @@ -1033,8 +1039,8 @@ void application::set_program_options(boost::program_options::options_descriptio
"For history_api::get_account_history_by_operations to set its default limit value as 100")
("api-limit-get-asset-holders",boost::program_options::value<uint64_t>()->default_value(100),
"For asset_api::get_asset_holders to set its default limit value as 100")
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_key_references to set its default limit value as 100")
("api-limit-get-key-references",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_key_references to set its default limit value as 100")
("api-limit-get-htlc-by",boost::program_options::value<uint64_t>()->default_value(100),
"For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100")
("api-limit-get-full-accounts",boost::program_options::value<uint64_t>()->default_value(10),
Expand All @@ -1047,6 +1053,10 @@ void application::set_program_options(boost::program_options::options_descriptio
"For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300")
("api-limit-get-assets",boost::program_options::value<uint64_t>()->default_value(101),
"For database_api_impl::list_assets and get_assets_by_issuer to set its default limit values as 101")
("api-limit-get-limit-orders",boost::program_options::value<uint64_t>()->default_value(300),
"For database_api_impl::get_limit_orders to set its default limit value as 300")
("api-limit-get-order-book",boost::program_options::value<uint64_t>()->default_value(50),
"For database_api_impl::get_order_book to set its default limit value as 50")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down
9 changes: 6 additions & 3 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
}
vector<limit_order_object> get_limit_orders(const asset_id_type a, const asset_id_type b, const uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders;
FC_ASSERT( limit <= api_limit_get_limit_orders );

const auto& limit_order_idx = _db.get_index_type<limit_order_index>();
const auto& limit_price_idx = limit_order_idx.indices().get<by_price>();
Expand Down Expand Up @@ -1382,7 +1383,8 @@ vector<limit_order_object> database_api::get_limit_orders(std::string a, std::st
*/
vector<limit_order_object> database_api_impl::get_limit_orders(const std::string& a, const std::string& b, uint32_t limit)const
{
FC_ASSERT( limit <= 300 );
uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders;
FC_ASSERT( limit <= api_limit_get_limit_orders );

const asset_id_type asset_a_id = get_asset_from_string(a)->id;
const asset_id_type asset_b_id = get_asset_from_string(b)->id;
Expand Down Expand Up @@ -1643,7 +1645,8 @@ order_book database_api::get_order_book( const string& base, const string& quote
order_book database_api_impl::get_order_book( const string& base, const string& quote, unsigned limit )const
{
using boost::multiprecision::uint128_t;
FC_ASSERT( limit <= 50 );
uint64_t api_limit_get_order_book=_app_options->api_limit_get_order_book;
FC_ASSERT( limit <= api_limit_get_order_book );

order_book result;
result.base = base;
Expand Down
2 changes: 2 additions & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ namespace graphene { namespace app {
uint64_t api_limit_get_call_orders = 300;
uint64_t api_limit_get_settle_orders = 300;
uint64_t api_limit_get_assets = 101;
uint64_t api_limit_get_limit_orders = 300;
uint64_t api_limit_get_order_book = 50;
};

class application
Expand Down
33 changes: 32 additions & 1 deletion tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,35 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
options.insert(std::make_pair("api-limit-get-key-references", boost::program_options::variable_value((uint64_t)200, false)));
options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false)));
}
if(current_test_name =="api_limit_get_limit_orders")
{
options.insert(std::make_pair("api-limit-get-limit-orders", boost::program_options::variable_value(
(uint64_t)350, false)));
options.insert(std::make_pair("plugins", boost::program_options::variable_value(
string("account_history"), false)));
}
if(current_test_name =="api_limit_get_call_orders")
{
options.insert(std::make_pair("api-limit-get-call-orders", boost::program_options::variable_value(
(uint64_t)350, false)));
options.insert(std::make_pair("plugins", boost::program_options::variable_value(
string("account_history"), false)));
}
if(current_test_name =="api_limit_get_settle_orders")
{
options.insert(std::make_pair("api-limit-get-settle-orders", boost::program_options::variable_value(
(uint64_t)350, false)));
options.insert(std::make_pair("plugins", boost::program_options::variable_value(
string("account_history"), false)));
}
if(current_test_name =="api_limit_get_order_book")
{
options.insert(std::make_pair("api-limit-get-order-book", boost::program_options::variable_value(
(uint64_t)80, false)));
options.insert(std::make_pair("plugins", boost::program_options::variable_value(
string("account_history"), false)));
}

// add account tracking for ahplugin for special test case with track-account enabled
if( !options.count("track-account") && current_test_name == "track_account") {
std::vector<std::string> track_account;
Expand Down Expand Up @@ -208,7 +237,9 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp)
if (current_test_name == "api_limit_get_account_history_operations" || current_test_name == "api_limit_get_account_history"
|| current_test_name == "api_limit_get_grouped_limit_orders" || current_test_name == "api_limit_get_relative_account_history"
|| current_test_name == "api_limit_get_account_history_by_operations" || current_test_name =="api_limit_get_asset_holders"
|| current_test_name =="api_limit_get_key_references")
|| current_test_name =="api_limit_get_key_references" || current_test_name =="api_limit_get_limit_orders"
|| current_test_name =="api_limit_get_call_orders" || current_test_name =="api_limit_get_settle_orders"
|| current_test_name =="api_limit_get_order_book")
{
app.initialize(graphene::utilities::temp_directory_path(), options);
app.set_api_limit();
Expand Down
90 changes: 90 additions & 0 deletions tests/tests/database_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1288,4 +1288,94 @@ BOOST_AUTO_TEST_CASE( get_settle_orders_by_account ) {
}
}

BOOST_AUTO_TEST_CASE( api_limit_get_limit_orders ){
try{
graphene::app::database_api db_api( db, &( app.get_options() ));
//account_id_type() do 3 ops
create_bitasset("USD", account_id_type());
create_account("dan");
create_account("bob");
asset_id_type bit_jmj_id = create_bitasset("JMJBIT").id;
generate_block();
fc::usleep(fc::milliseconds(100));
GRAPHENE_CHECK_THROW(db_api.get_limit_orders(std::string(static_cast<object_id_type>(asset_id_type())),
std::string(static_cast<object_id_type>(bit_jmj_id)), 370), fc::exception);
vector<limit_order_object> limit_orders =db_api.get_limit_orders(std::string(
static_cast<object_id_type>(asset_id_type())),
std::string(static_cast<object_id_type>(bit_jmj_id)), 340);
BOOST_REQUIRE_EQUAL( limit_orders.size(), 0u);

}catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( api_limit_get_call_orders ){
try{
graphene::app::database_api db_api( db, &( app.get_options() ));
//account_id_type() do 3 ops
auto nathan_private_key = generate_private_key("nathan");
account_id_type nathan_id = create_account("nathan", nathan_private_key.get_public_key()).id;
transfer(account_id_type(), nathan_id, asset(100));
asset_id_type bitusd_id = create_bitasset(
"USDBIT", nathan_id, 100, disable_force_settle).id;
generate_block();
fc::usleep(fc::milliseconds(100));
BOOST_CHECK( bitusd_id(db).is_market_issued() );
GRAPHENE_CHECK_THROW(db_api.get_call_orders(std::string(static_cast<object_id_type>(bitusd_id)),
370), fc::exception);
vector< call_order_object> call_order =db_api.get_call_orders(std::string(
static_cast<object_id_type>(bitusd_id)), 340);
BOOST_REQUIRE_EQUAL( call_order.size(), 0u);
}catch (fc::exception& e) {
manikey123 marked this conversation as resolved.
Show resolved Hide resolved
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( api_limit_get_settle_orders ){
try{
graphene::app::database_api db_api( db, &( app.get_options() ));
//account_id_type() do 3 ops
auto nathan_private_key = generate_private_key("nathan");
account_id_type nathan_id = create_account("nathan", nathan_private_key.get_public_key()).id;
transfer(account_id_type(), nathan_id, asset(100));
asset_id_type bitusd_id = create_bitasset(
"USDBIT", nathan_id, 100, disable_force_settle).id;
generate_block();
fc::usleep(fc::milliseconds(100));
GRAPHENE_CHECK_THROW(db_api.get_settle_orders(
std::string(static_cast<object_id_type>(bitusd_id)), 370), fc::exception);
vector<force_settlement_object> result =db_api.get_settle_orders(
std::string(static_cast<object_id_type>(bitusd_id)), 340);
BOOST_REQUIRE_EQUAL( result.size(), 0u);
}catch (fc::exception& e) {
manikey123 marked this conversation as resolved.
Show resolved Hide resolved
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_CASE( api_limit_get_order_book ){
try{
graphene::app::database_api db_api( db, &( app.get_options() ));
auto nathan_private_key = generate_private_key("nathan");
auto dan_private_key = generate_private_key("dan");
account_id_type nathan_id = create_account("nathan", nathan_private_key.get_public_key()).id;
account_id_type dan_id = create_account("dan", dan_private_key.get_public_key()).id;
transfer(account_id_type(), nathan_id, asset(100));
transfer(account_id_type(), dan_id, asset(100));
asset_id_type bitusd_id = create_bitasset(
"USDBIT", nathan_id, 100, disable_force_settle).id;
asset_id_type bitdan_id = create_bitasset(
"DANBIT", dan_id, 100, disable_force_settle).id;
generate_block();
fc::usleep(fc::milliseconds(100));
GRAPHENE_CHECK_THROW(db_api.get_order_book(std::string(static_cast<object_id_type>(bitusd_id)),
std::string(static_cast<object_id_type>(bitdan_id)),89), fc::exception);
graphene::app::order_book result =db_api.get_order_book(std::string(
static_cast<object_id_type>(bitusd_id)), std::string(static_cast<object_id_type>(bitdan_id)),78);
BOOST_REQUIRE_EQUAL( result.bids.size(), 0u);
}catch (fc::exception& e) {
manikey123 marked this conversation as resolved.
Show resolved Hide resolved
edump((e.to_detail_string()));
throw;
}
}
BOOST_AUTO_TEST_SUITE_END()