diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 5421fbc6bd..d1f972ac0d 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -349,6 +349,39 @@ void application_impl::set_api_limit() { if(_options->count("api-limit-list-htlcs")){ _app_options.api_limit_list_htlcs = _options->at("api-limit-list-htlcs").as(); } + if(_options->count("api-limit-lookup-accounts")) { + _app_options.api_limit_lookup_accounts = _options->at("api-limit-lookup-accounts").as(); + } + if(_options->count("api-limit-lookup-witness-accounts")) { + _app_options.api_limit_lookup_witness_accounts = _options->at("api-limit-lookup-witness-accounts").as(); + } + if(_options->count("api-limit-lookup-committee-member-accounts")) { + _app_options.api_limit_lookup_committee_member_accounts = _options->at("api-limit-lookup-committee-member-accounts").as(); + } + if(_options->count("api-limit-lookup-vote-ids")) { + _app_options.api_limit_lookup_vote_ids = _options->at("api-limit-lookup-vote-ids").as(); + } + if(_options->count("api-limit-get-account-limit-orders")) { + _app_options.api_limit_get_account_limit_orders = _options->at("api-limit-get-account-limit-orders").as(); + } + if(_options->count("api-limit-get-collateral-bids")) { + _app_options.api_limit_get_collateral_bids = _options->at("api-limit-get-collateral-bids").as(); + } + if(_options->count("api-limit-get-top-markets")) { + _app_options.api_limit_get_top_markets = _options->at("api-limit-get-top-markets").as(); + } + if(_options->count("api-limit-get-trade-history")) { + _app_options.api_limit_get_trade_history = _options->at("api-limit-get-trade-history").as(); + } + if(_options->count("api-limit-get-trade-history-by-sequence")) { + _app_options.api_limit_get_trade_history_by_sequence = _options->at("api-limit-get-trade-history-by-sequence").as(); + } + if(_options->count("api-limit-get-withdraw-permissions-by-giver")) { + _app_options.api_limit_get_withdraw_permissions_by_giver = _options->at("api-limit-get-withdraw-permissions-by-giver").as(); + } + if(_options->count("api-limit-get-withdraw-permissions-by-recipient")) { + _app_options.api_limit_get_withdraw_permissions_by_recipient = _options->at("api-limit-get-withdraw-permissions-by-recipient").as(); + } } void application_impl::startup() @@ -1015,35 +1048,57 @@ void application::set_program_options(boost::program_options::options_descriptio "Whether to enable tracking of votes of standby witnesses and committee members. " "Set it to true to provide accurate data to API clients, set to false for slightly better performance.") ("api-limit-get-account-history-operations",boost::program_options::value()->default_value(100), - "For history_api::get_account_history_operations to set its default limit value as 100") + "For history_api::get_account_history_operations to set max limit value") ("api-limit-get-account-history",boost::program_options::value()->default_value(100), - "For history_api::get_account_history to set its default limit value as 100") + "For history_api::get_account_history to set max limit value") ("api-limit-get-grouped-limit-orders",boost::program_options::value()->default_value(101), - "For orders_api::get_grouped_limit_orders to set its default limit value as 101") + "For orders_api::get_grouped_limit_orders to set max limit value") ("api-limit-get-relative-account-history",boost::program_options::value()->default_value(100), - "For history_api::get_relative_account_history to set its default limit value as 100") + "For history_api::get_relative_account_history to set max limit value") ("api-limit-get-account-history-by-operations",boost::program_options::value()->default_value(100), - "For history_api::get_account_history_by_operations to set its default limit value as 100") + "For history_api::get_account_history_by_operations to set max limit value") ("api-limit-get-asset-holders",boost::program_options::value()->default_value(100), - "For asset_api::get_asset_holders to set its default limit value as 100") + "For asset_api::get_asset_holders to set max limit value") ("api-limit-get-key-references",boost::program_options::value()->default_value(100), - "For database_api_impl::get_key_references to set its default limit value as 100") + "For database_api_impl::get_key_references to set max limit value") ("api-limit-get-htlc-by",boost::program_options::value()->default_value(100), - "For database_api_impl::get_htlc_by_from and get_htlc_by_to to set its default limit value as 100") + "For database_api_impl::get_htlc_by_from and get_htlc_by_to to set max limit value") ("api-limit-get-full-accounts",boost::program_options::value()->default_value(10), - "For database_api_impl::get_full_accounts to set its account default limit values as 10") + "For database_api_impl::get_full_accounts to set max limit value") ("api-limit-get-full-accounts-lists",boost::program_options::value()->default_value(100), - "For database_api_impl::get_full_accounts to set its lists default limit values as 100") + "For database_api_impl::get_full_accounts to set max limit value") ("api-limit-get-call-orders",boost::program_options::value()->default_value(300), - "For database_api_impl::get_call_orders and get_call_orders_by_account to set its default limit values as 300") + "For database_api_impl::get_call_orders and get_call_orders_by_account to set max limit value") ("api-limit-get-settle-orders",boost::program_options::value()->default_value(300), - "For database_api_impl::get_settle_orders and get_settle_orders_by_account to set its default limit values as 300") + "For database_api_impl::get_settle_orders and get_settle_orders_by_account to set max limit value") ("api-limit-get-assets",boost::program_options::value()->default_value(101), - "For database_api_impl::list_assets and get_assets_by_issuer to set its default limit values as 101") + "For database_api_impl::list_assets and get_assets_by_issuer to set max limit value") ("api-limit-get-limit-orders",boost::program_options::value()->default_value(300), - "For database_api_impl::get_limit_orders to set its default limit value as 300") + "For database_api_impl::get_limit_orders to set max limit value") ("api-limit-get-order-book",boost::program_options::value()->default_value(50), - "For database_api_impl::get_order_book to set its default limit value as 50") + "For database_api_impl::get_order_book to set max limit value") + ("api-limit-lookup-accounts",boost::program_options::value()->default_value(1000), + "For database_api_impl::lookup_accounts to set max limit value") + ("api-limit-lookup-witness-accounts",boost::program_options::value()->default_value(1000), + "For database_api_impl::lookup_witness_accounts to set max limit value") + ("api-limit-lookup-committee-member-accounts",boost::program_options::value()->default_value(1000), + "For database_api_impl::lookup_committee_member_accounts to set max limit value") + ("api-limit-lookup-vote-ids",boost::program_options::value()->default_value(1000), + "For database_api_impl::lookup_vote_ids to set max limit value") + ("api-limit-get-account-limit-orders",boost::program_options::value()->default_value(101), + "For database_api_impl::get_account_limit_orders to set max limit value") + ("api-limit-get-collateral-bids",boost::program_options::value()->default_value(100), + "For database_api_impl::get_collateral_bids to set max limit value") + ("api-limit-get-top-markets",boost::program_options::value()->default_value(100), + "For database_api_impl::get_top_markets to set max limit value") + ("api-limit-get-trade-history",boost::program_options::value()->default_value(100), + "For database_api_impl::get_trade_history to set max limit value") + ("api-limit-get-trade-history-by-sequence",boost::program_options::value()->default_value(100), + "For database_api_impl::get_trade_history_by_sequence to set max limit value") + ("api-limit-get-withdraw-permissions-by-giver",boost::program_options::value()->default_value(101), + "For database_api_impl::get_withdraw_permissions_by_giver to set max limit value") + ("api-limit-get-withdraw-permissions-by-recipient",boost::program_options::value()->default_value(101), + "For database_api_impl::get_withdraw_permissions_by_recipient to set max limit value") ; command_line_options.add(configuration_file_options); command_line_options.add_options() diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d19a8daae2..adbe87fc7f 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -684,7 +684,7 @@ map database_api_impl::lookup_accounts( const string& lo uint32_t limit, optional subscribe )const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= _app_options->api_limit_lookup_accounts ); const auto& accounts_by_name = _db.get_index_type().indices().get(); map result; @@ -982,7 +982,7 @@ vector database_api_impl::get_account_limit_orders( const string& account_name_or_id, const string &base, const string "e, uint32_t limit, optional ostart_id, optional ostart_price ) { - FC_ASSERT( limit <= 101 ); + FC_ASSERT( limit <= _app_options->api_limit_get_account_limit_orders ); vector results; uint32_t count = 0; @@ -1197,7 +1197,7 @@ vector database_api::get_collateral_bids( const std::stri vector database_api_impl::get_collateral_bids( const std::string& asset, uint32_t limit, uint32_t skip )const { try { - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= _app_options->api_limit_get_collateral_bids ); const asset_id_type asset_id = get_asset_from_string(asset)->id; const asset_object& swan = asset_id(_db); FC_ASSERT( swan.is_market_issued() ); @@ -1313,9 +1313,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 { - uint64_t api_limit_get_order_book=_app_options->api_limit_get_order_book; - FC_ASSERT( limit <= api_limit_get_order_book ); - + FC_ASSERT( limit <= _app_options->api_limit_get_order_book ); + order_book result; result.base = base; result.quote = quote; @@ -1364,7 +1363,7 @@ vector database_api_impl::get_top_markets(uint32_t limit)const { FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." ); - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= _app_options->api_limit_get_top_markets ); const auto& volume_idx = _db.get_index_type().indices().get(); auto itr = volume_idx.rbegin(); @@ -1402,7 +1401,7 @@ vector database_api_impl::get_trade_history( const string& base, { FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." ); - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= _app_options->api_limit_get_trade_history ); auto assets = lookup_asset_symbols( {base, quote} ); FC_ASSERT( assets[0], "Invalid base asset symbol: ${s}", ("s",base) ); @@ -1494,7 +1493,7 @@ vector database_api_impl::get_trade_history_by_sequence( { FC_ASSERT( _app_options && _app_options->has_market_history_plugin, "Market history plugin is not enabled." ); - FC_ASSERT( limit <= 100 ); + FC_ASSERT( limit <= _app_options->api_limit_get_trade_history_by_sequence ); FC_ASSERT( start >= 0 ); int64_t start_seq = -start; @@ -1628,7 +1627,7 @@ map database_api::lookup_witness_accounts( const string map database_api_impl::lookup_witness_accounts( const string& lower_bound_name, uint32_t limit )const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= _app_options->api_limit_lookup_witness_accounts ); const auto& witnesses_by_id = _db.get_index_type().indices().get(); // we want to order witnesses by account name, but that name is in the account object @@ -1710,7 +1709,7 @@ map database_api::lookup_committee_member_acco map database_api_impl::lookup_committee_member_accounts( const string& lower_bound_name, uint32_t limit )const { - FC_ASSERT( limit <= 1000 ); + FC_ASSERT( limit <= _app_options->api_limit_lookup_committee_member_accounts ); const auto& committee_members_by_id = _db.get_index_type().indices().get(); // we want to order committee_members by account name, but that name is in the account object @@ -1808,7 +1807,7 @@ vector database_api::lookup_vote_ids( const vector& votes vector database_api_impl::lookup_vote_ids( const vector& votes )const { - FC_ASSERT( votes.size() < 1000, "Only 1000 votes can be queried at a time" ); + FC_ASSERT( votes.size() < _app_options->api_limit_lookup_vote_ids ); const auto& witness_idx = _db.get_index_type().indices().get(); const auto& committee_idx = _db.get_index_type().indices().get(); @@ -2204,7 +2203,7 @@ vector database_api_impl::get_withdraw_permissions_b withdraw_permission_id_type start, uint32_t limit)const { - FC_ASSERT( limit <= 101 ); + FC_ASSERT( limit <= _app_options->api_limit_get_withdraw_permissions_by_giver ); vector result; const auto& withdraw_idx = _db.get_index_type().indices().get(); @@ -2233,7 +2232,7 @@ vector database_api_impl::get_withdraw_permissions_b withdraw_permission_id_type start, uint32_t limit)const { - FC_ASSERT( limit <= 101 ); + FC_ASSERT( limit <= _app_options->api_limit_get_withdraw_permissions_by_recipient ); vector result; const auto& withdraw_idx = _db.get_index_type().indices().get(); diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index a9b6655cc3..b9c37fb6c6 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -56,6 +56,17 @@ namespace graphene { namespace app { uint64_t api_limit_get_limit_orders = 300; uint64_t api_limit_get_order_book = 50; uint64_t api_limit_list_htlcs = 100; + uint64_t api_limit_lookup_accounts = 1000; + uint64_t api_limit_lookup_witness_accounts = 1000; + uint64_t api_limit_lookup_committee_member_accounts = 1000; + uint64_t api_limit_lookup_vote_ids = 1000; + uint64_t api_limit_get_account_limit_orders = 101; + uint64_t api_limit_get_collateral_bids = 100; + uint64_t api_limit_get_top_markets = 100; + uint64_t api_limit_get_trade_history = 100; + uint64_t api_limit_get_trade_history_by_sequence = 100; + uint64_t api_limit_get_withdraw_permissions_by_giver = 101; + uint64_t api_limit_get_withdraw_permissions_by_recipient = 101; }; class application diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index e25b4f76e0..0b0be3fc2e 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -134,76 +134,125 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-account-history-operations", boost::program_options::variable_value((uint64_t)300, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false))); } if(current_test_name =="api_limit_get_account_history") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-account-history", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false))); } if(current_test_name =="api_limit_get_grouped_limit_orders") { options.insert(std::make_pair("api-limit-get-grouped-limit-orders", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("grouped_orders"), false))); } if(current_test_name =="api_limit_get_relative_account_history") { options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false))); options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false))); } if(current_test_name =="api_limit_get_account_history_by_operations") { options.insert(std::make_pair("api-limit-get-account-history-by-operations", boost::program_options::variable_value((uint64_t)250, false))); options.insert(std::make_pair("api-limit-get-relative-account-history", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false))); } if(current_test_name =="api_limit_get_asset_holders") { options.insert(std::make_pair("api-limit-get-asset-holders", boost::program_options::variable_value((uint64_t)250, false))); - options.insert(std::make_pair("plugins", boost::program_options::variable_value(string("account_history"), false))); } if(current_test_name =="api_limit_get_key_references") { 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))); } if( current_test_name == "asset_in_collateral" ) { options.insert( std::make_pair( "plugins", boost::program_options::variable_value( string("api_helper_indexes"), false ) ) ); } - - // add account tracking for ahplugin for special test case with track-account enabled + if(current_test_name =="api_limit_lookup_accounts") + { + options.insert(std::make_pair("api-limit-lookup-accounts", boost::program_options::variable_value + ((uint64_t)200, false))); + } + if(current_test_name =="api_limit_lookup_witness_accounts") + { + options.insert(std::make_pair("api-limit-lookup-witness-accounts", boost::program_options::variable_value + ((uint64_t)200, false))); + } + if(current_test_name =="api_limit_lookup_committee_member_accounts") + { + options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value + ((uint64_t)200, false))); + } + if(current_test_name =="api_limit_lookup_committee_member_accounts") + { + options.insert(std::make_pair("api-limit-lookup-committee-member-accounts", boost::program_options::variable_value + ((uint64_t)200, false))); + } + if(current_test_name =="api_limit_lookup_vote_ids") + { + options.insert(std::make_pair("api-limit-lookup-vote-ids", boost::program_options::variable_value + ((uint64_t)3, false))); + } + if(current_test_name =="api_limit_get_account_limit_orders") + { + options.insert(std::make_pair("api-limit-get-account-limit-orders", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_collateral_bids") + { + options.insert(std::make_pair("api-limit-get-collateral-bids", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_top_markets") + { + options.insert(std::make_pair("api-limit-get-top-markets", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_trade_history") + { + options.insert(std::make_pair("api-limit-get-trade-history", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_trade_history_by_sequence") + { + options.insert(std::make_pair("api-limit-get-trade-history-by-sequence", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_withdraw_permissions_by_giver") + { + options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-giver", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_withdraw_permissions_by_recipient") + { + options.insert(std::make_pair("api-limit-get-withdraw-permissions-by-recipient", boost::program_options::variable_value + ((uint64_t)250, false))); + } + if(current_test_name =="api_limit_get_full_accounts2") + { + options.insert(std::make_pair("api-limit-get-full-accounts", boost::program_options::variable_value + ((uint64_t)200, 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 track_account; std::string track = "\"1.2.17\""; @@ -248,12 +297,8 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) ahplugin->plugin_set_app(&app); ahplugin->plugin_initialize(options); ahplugin->plugin_startup(); - 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_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") + + if(validation_current_test_name_for_setting_api_limit(current_test_name)) { app.initialize(graphene::utilities::temp_directory_path(), options); app.set_api_limit(); @@ -385,7 +430,30 @@ string database_fixture::generate_anon_acct_name() // to workaround issue #46 return "anon-acct-x" + std::to_string( anon_acct_count++ ); } +bool database_fixture::validation_current_test_name_for_setting_api_limit(string & current_test_name) const +{ + vector valid_testcase {"api_limit_get_account_history_operations","api_limit_get_account_history" + ,"api_limit_get_grouped_limit_orders","api_limit_get_relative_account_history" + ,"api_limit_get_account_history_by_operations","api_limit_get_asset_holders" + ,"api_limit_get_key_references","api_limit_get_limit_orders" + ,"api_limit_get_call_orders","api_limit_get_settle_orders" + ,"api_limit_get_order_book","api_limit_lookup_accounts" + ,"api_limit_lookup_witness_accounts","api_limit_lookup_committee_member_accounts" + ,"api_limit_lookup_vote_ids","api_limit_get_account_limit_orders" + ,"api_limit_get_collateral_bids","api_limit_get_top_markets" + ,"api_limit_get_trade_history", "api_limit_get_trade_history_by_sequence" + ,"api_limit_get_withdraw_permissions_by_giver","api_limit_get_withdraw_permissions_by_recipient" + ,"api_limit_get_full_accounts2"}; + for(string i_valid_testcase: valid_testcase) + { + if(i_valid_testcase.compare(current_test_name)==0) + { + return true; + } + } + return false; +} void database_fixture::verify_asset_supplies( const database& db ) { //wlog("*** Begin asset supply verification ***"); diff --git a/tests/common/database_fixture.hpp b/tests/common/database_fixture.hpp index eeecdcb5a6..136d25ea46 100644 --- a/tests/common/database_fixture.hpp +++ b/tests/common/database_fixture.hpp @@ -371,6 +371,7 @@ struct database_fixture { vector< operation_history_object > get_operation_history( account_id_type account_id )const; vector< graphene::market_history::order_history_object > get_market_order_history( asset_id_type a, asset_id_type b )const; + bool validation_current_test_name_for_setting_api_limit (string & current_test_name) const; /**** * @brief return htlc fee parameters diff --git a/tests/tests/database_api_tests.cpp b/tests/tests/database_api_tests.cpp index 00f7ef4ca9..a577f7a281 100644 --- a/tests/tests/database_api_tests.cpp +++ b/tests/tests/database_api_tests.cpp @@ -1087,6 +1087,7 @@ BOOST_AUTO_TEST_CASE( subscription_notification_test ) BOOST_AUTO_TEST_CASE( lookup_vote_ids ) { try { + graphene::app::database_api db_api( db, &( app.get_options() )); ACTORS( (connie)(whitney)(wolverine) ); fund(connie); @@ -1100,8 +1101,6 @@ BOOST_AUTO_TEST_CASE( lookup_vote_ids ) const auto& witness = create_witness( whitney ); const auto& worker = create_worker( wolverine_id ); - graphene::app::database_api db_api(db); - std::vector votes; votes.push_back( committee.vote_id ); votes.push_back( witness.vote_id ); @@ -1113,7 +1112,7 @@ BOOST_AUTO_TEST_CASE( lookup_vote_ids ) BOOST_AUTO_TEST_CASE(get_account_limit_orders) { try { - + graphene::app::database_api db_api( db, &( app.get_options() )); ACTORS((seller)); const auto& bitcny = create_bitasset("CNY"); @@ -1135,7 +1134,6 @@ BOOST_AUTO_TEST_CASE(get_account_limit_orders) BOOST_CHECK(create_sell_order(seller, core.amount(100), bitcny.amount(250 - i))); } - graphene::app::database_api db_api(db); std::vector results; limit_order_object o; @@ -1785,5 +1783,292 @@ BOOST_AUTO_TEST_CASE( asset_in_collateral ) BOOST_CHECK_EQUAL( 1000, assets[1].total_backing_collateral->value ); } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE( api_limit_lookup_accounts ) { + try{ + graphene::app::database_api db_api( db, &( app.get_options() )); + ACTOR(bob); + GRAPHENE_CHECK_THROW(db_api.lookup_accounts("bob",220), fc::exception); + map result =db_api.lookup_accounts("bob",190); + BOOST_REQUIRE_EQUAL( result.size(), 17u); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( api_limit_lookup_witness_accounts ) { + try{ + graphene::app::database_api db_api( db, &( app.get_options() )); + ACTORS((bob)) ; + GRAPHENE_CHECK_THROW(db_api.lookup_witness_accounts("bob",220), fc::exception); + map result =db_api.lookup_witness_accounts("bob",190); + BOOST_REQUIRE_EQUAL( result.size(), 10u); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( api_limit_get_full_accounts2 ) { + + try { + graphene::app::database_api db_api(db, &(this->app.get_options())); + vector accounts; + for (int i=0; i<201; i++) { + std::string acct_name = "mytempacct" + std::to_string(i); + const account_object& account_name=create_account(acct_name); + accounts.push_back(account_name.name); + } + GRAPHENE_CHECK_THROW(db_api.get_full_accounts(accounts, false), fc::exception); + accounts.erase(accounts.begin()); + auto full_accounts = db_api.get_full_accounts(accounts, false); + BOOST_REQUIRE_EQUAL(full_accounts.size(), 200u); + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_withdraw_permissions_by_recipient){ + try{ + graphene::app::database_api db_api( db, &app.get_options()); + ACTORS((bob)) ; + withdraw_permission_id_type withdraw_permission; + GRAPHENE_CHECK_THROW(db_api.get_withdraw_permissions_by_recipient( + "bob",withdraw_permission, 251), fc::exception); + vector result =db_api.get_withdraw_permissions_by_recipient( + "bob",withdraw_permission,250); + BOOST_REQUIRE_EQUAL( result.size(), 0u); + }catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_withdraw_permissions_by_giver){ + try{ + graphene::app::database_api db_api( db, &app.get_options()); + ACTORS((bob)) ; + withdraw_permission_id_type withdraw_permission; + GRAPHENE_CHECK_THROW(db_api.get_withdraw_permissions_by_giver( + "bob",withdraw_permission, 251), fc::exception); + vector result =db_api.get_withdraw_permissions_by_giver( + "bob",withdraw_permission,250); + BOOST_REQUIRE_EQUAL( result.size(), 0u); + }catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_trade_history_by_sequence){ + try{ + app.enable_plugin("market_history"); + graphene::app::application_options opt=app.get_options(); + opt.has_market_history_plugin = true; + graphene::app::database_api db_api( db, &opt); + const auto& bitusd = create_bitasset("USDBIT"); + asset_id_type asset_1, asset_2; + asset_1 = bitusd.id; + asset_2 = asset_id_type(); + GRAPHENE_CHECK_THROW(db_api.get_trade_history_by_sequence( + std::string( static_cast(asset_1)), + std::string( static_cast(asset_2)), + 0,fc::time_point_sec(), 251), fc::exception); + vector result =db_api.get_trade_history_by_sequence( + std::string( static_cast(asset_1)), + std::string( static_cast(asset_2)), + 0,fc::time_point_sec(),250); + BOOST_REQUIRE_EQUAL( result.size(), 0u); + }catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_trade_history){ + try{ + app.enable_plugin("market_history"); + graphene::app::application_options opt=app.get_options(); + opt.has_market_history_plugin = true; + graphene::app::database_api db_api( db, &opt); + const auto& bitusd = create_bitasset("USDBIT"); + asset_id_type asset_1, asset_2; + asset_1 = bitusd.id; + asset_2 = asset_id_type(); + GRAPHENE_CHECK_THROW(db_api.get_trade_history( + std::string( static_cast(asset_1)), + std::string( static_cast(asset_2)), + fc::time_point_sec(),fc::time_point_sec(), + 251), fc::exception); + vector result =db_api.get_trade_history( + std::string( static_cast(asset_1)), + std::string( static_cast(asset_2)), + fc::time_point_sec(),fc::time_point_sec(),250); + BOOST_REQUIRE_EQUAL( result.size(), 0u); + }catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_top_markets){ + try{ + app.enable_plugin("market_history"); + graphene::app::application_options opt=app.get_options(); + opt.has_market_history_plugin = true; + graphene::app::database_api db_api( db, &opt); + const auto& bitusd = create_bitasset("USDBIT"); + asset_id_type asset_1, asset_2; + asset_1 = bitusd.id; + asset_2 = asset_id_type(); + GRAPHENE_CHECK_THROW(db_api.get_top_markets(251), fc::exception); + vector result =db_api.get_top_markets(250); + BOOST_REQUIRE_EQUAL( result.size(), 0u); + }catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_collateral_bids) { + try { + graphene::app::database_api db_api( db, &( app.get_options() )); + + int64_t init_balance = 10000; + ///account_id_type borrower, borrower2, feedproducer; + asset_id_type swan, back; + ACTORS((borrower) (borrower2) (feedproducer)) ; + const auto& bitusd = create_bitasset("USDBIT", feedproducer_id); + swan = bitusd.id; + back = asset_id_type(); + update_feed_producers(swan(db), {feedproducer_id}); + transfer(committee_account, borrower_id, asset(init_balance)); + transfer(committee_account, borrower2_id, asset(init_balance)); + + generate_blocks( HARDFORK_CORE_216_TIME ); + generate_block(); + + price_feed feed; + feed.maintenance_collateral_ratio = 1750; // need to set this explicitly, testnet has a different default + feed.settlement_price = swan(db).amount(1) / back(db).amount(1); + publish_feed(swan(db), feedproducer_id(db), feed); + // start out with 2:1 collateral + borrow(borrower_id(db), swan(db).amount(10), back(db).amount(2*10)); + borrow(borrower2_id(db), swan(db).amount(10), back(db).amount(4*10)); + //feed 1: 2 + feed.settlement_price = swan(db).amount(1) / back(db).amount(2); + publish_feed(swan(db), feedproducer_id(db), feed); + + // this sell order is designed to trigger a black swan + + create_sell_order( borrower2_id(db), swan(db).amount(1), back(db).amount(3) )->id; + BOOST_CHECK( swan(db).bitasset_data(db).has_settlement() ); + //making 3 collateral bids + for (int i=0; i<3; i++) { + + std::string acct_name = "mytempacct" + std::to_string(i); + account_id_type account_id=create_account(acct_name).id; + transfer(committee_account, account_id, asset(init_balance)); + bid_collateral(account_id(db), back(db).amount(10), swan(db).amount(1)); + } + auto swan_symbol = swan(db).symbol; + + + //validating normal case; total_bids =3 ; result_bids=3 + vector result_bids = db_api.get_collateral_bids(swan_symbol, 250, 0); + BOOST_CHECK_EQUAL( 3u, result_bids.size() ); + + //verify skip /// inefficient code test + //skip < total_bids; skip=1; total_bids =3 ; result_bids=2 + result_bids = db_api.get_collateral_bids(swan_symbol, 250, 1); + BOOST_CHECK_EQUAL( 2u, result_bids.size() ); + //skip= total_bids; skip=3; total_bids =3 ; result_bids=0 + result_bids = db_api.get_collateral_bids(swan_symbol, 250, 3); + BOOST_CHECK_EQUAL( 0u, result_bids.size() ); + //skip> total_bids; skip=4; total_bids =3 ; result_bids=0 + result_bids = db_api.get_collateral_bids(swan_symbol, 250, 4); + BOOST_CHECK_EQUAL( 0u, result_bids.size() ); + + //verify limit // inefficient code test + //limit= api_limit + for (int i=3; i<255; i++) { + std::string acct_name = "mytempacct" + std::to_string(i); + account_id_type account_id=create_account(acct_name).id; + transfer(committee_account, account_id, asset(init_balance)); + bid_collateral(account_id(db), back(db).amount(10), swan(db).amount(1)); + } + result_bids=db_api.get_collateral_bids(swan_symbol, 250, 0); + BOOST_CHECK_EQUAL( 250u, result_bids.size() ); + //limit> api_limit throw error + GRAPHENE_CHECK_THROW(db_api.get_collateral_bids(swan_symbol, 253, 3), fc::exception); + + } + catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE(api_limit_get_account_limit_orders) { + try { + graphene::app::database_api db_api( db, &( app.get_options() )); + ACTORS((seller)); + const auto &bitcny = create_bitasset("CNY"); + const auto &core = asset_id_type()(db); + + int64_t init_balance(10000000); + transfer(committee_account, seller_id, asset(init_balance)); + + /// Create versatile orders + for (size_t i = 0; i < 250; ++i) { + BOOST_CHECK(create_sell_order(seller, core.amount(100), bitcny.amount(250+i))); + } + + + std::vector results=db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY",250); + BOOST_REQUIRE_EQUAL( results.size(), 250u); + GRAPHENE_CHECK_THROW( db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY",251), fc::exception); + + } + catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} +BOOST_AUTO_TEST_CASE( api_limit_lookup_vote_ids ) { + try{ + graphene::app::database_api db_api( db, &( app.get_options() )); + ACTORS( (connie)(whitney)(wolverine) ); + fund(connie); + upgrade_to_lifetime_member(connie); + fund(whitney); + upgrade_to_lifetime_member(whitney); + fund(wolverine); + upgrade_to_lifetime_member(wolverine); + const auto& committee = create_committee_member( connie ); + const auto& witness = create_witness( whitney ); + const auto& worker = create_worker( wolverine_id ); + std::vector votes; + votes.push_back( committee.vote_id ); + votes.push_back( witness.vote_id ); + const auto results = db_api.lookup_vote_ids( votes ); + BOOST_REQUIRE_EQUAL( results.size(), 2u); + votes.push_back( worker.vote_for ); + GRAPHENE_CHECK_THROW(db_api.lookup_vote_ids(votes), fc::exception); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} + +BOOST_AUTO_TEST_CASE( api_limit_lookup_committee_member_accounts ) { + try{ + graphene::app::database_api db_api( db, &( app.get_options() )); + ACTORS((bob)); + GRAPHENE_CHECK_THROW(db_api.lookup_committee_member_accounts("bob",220), fc::exception); + std::map result =db_api.lookup_committee_member_accounts("bob",190); + BOOST_REQUIRE_EQUAL( result.size(), 10u); + + } catch (fc::exception& e) { + edump((e.to_detail_string())); + throw; + } +} BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/tests/swan_tests.cpp b/tests/tests/swan_tests.cpp index 54f233c66a..d5aff8b996 100644 --- a/tests/tests/swan_tests.cpp +++ b/tests/tests/swan_tests.cpp @@ -380,7 +380,7 @@ BOOST_AUTO_TEST_CASE( recollateralize ) bid_collateral( borrower2(), back().amount(2100), swan().amount(1399) ); // check get_collateral_bids - graphene::app::database_api db_api(db); + graphene::app::database_api db_api( db, &( app.get_options() )); GRAPHENE_REQUIRE_THROW( db_api.get_collateral_bids(back().symbol, 100, 0), fc::assert_exception ); auto swan_symbol = _swan(db).symbol; vector bids = db_api.get_collateral_bids(swan_symbol, 100, 1); @@ -501,7 +501,7 @@ BOOST_AUTO_TEST_CASE( revive_empty_with_bid ) // revive wait_for_maintenance(); BOOST_CHECK( !swan().bitasset_data(db).has_settlement() ); - graphene::app::database_api db_api(db); + graphene::app::database_api db_api( db, &( app.get_options() )); auto swan_symbol = _swan(db).symbol; vector bids = db_api.get_collateral_bids(swan_symbol, 100, 0); BOOST_CHECK( bids.empty() );