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

Fix #782: Change hard-coded limitations in API's to configurable #1513

Merged
merged 26 commits into from
Mar 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
cb5250f
Merge pull request #1 from bitshares/develop
manikey123 Dec 20, 2018
a4afb7c
Merge pull request #2 from bitshares/develop
manikey123 Jan 4, 2019
a22e850
added test case for 782 part1
manikey123 Jan 4, 2019
b4195aa
Update history_api_tests.cpp
manikey123 Jan 8, 2019
1829a9a
updated based on review comment received
manikey123 Jan 9, 2019
d66f15b
updated based on review comment received1
manikey123 Jan 9, 2019
ab7b44a
Update history_api_tests.cpp
manikey123 Jan 9, 2019
c3db2db
Update application.cpp
manikey123 Jan 9, 2019
43a743b
updating uint64_t
manikey123 Jan 9, 2019
9a9a8f8
782 pt 1 and 2
manikey123 Jan 13, 2019
3aecf1f
782 pt 1 and 2 edit
manikey123 Jan 13, 2019
a724f9d
Merge pull request #3 from bitshares/develop
manikey123 Jan 15, 2019
3066629
782 chnages based on review comments
manikey123 Jan 15, 2019
9d6b06f
782 changes based on travis build and review comments
manikey123 Jan 15, 2019
884a6b4
782 changes based on travis build and review comments
manikey123 Jan 15, 2019
f6f6cde
Update group_order_api_tests.cpp
manikey123 Jan 15, 2019
f85b46d
Update api.hpp
manikey123 Jan 15, 2019
8d59ea3
782 changes based on get_key_references
manikey123 Jan 15, 2019
f928f90
Update application.hpp
manikey123 Jan 15, 2019
097a8e6
changes for 782 to correct spacing issue
manikey123 Jan 15, 2019
782bbba
Merge branch '782_test_p1' of https://github.com/manikey123/bitshares…
manikey123 Jan 15, 2019
ba3a895
Update database_api_tests.cpp
manikey123 Jan 15, 2019
a4108e0
Update as per the review comments 1513
manikey123 Jan 15, 2019
3014c38
Merge branch 'develop' into 782_test_p1
manikey123 Mar 18, 2019
df514ac
Update asset_api_tests.cpp
manikey123 Mar 18, 2019
78cb2c7
updated api.cpp for build failures
manikey123 Mar 19, 2019
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
3 changes: 2 additions & 1 deletion libraries/app/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ namespace graphene { namespace app {
{
FC_ASSERT( _app.chain_database() );
const auto& db = *_app.chain_database();
FC_ASSERT( limit <= 100 );
uint32_t max_account_history_operations_limit=_app.get_options().max_account_history_operations_limit;
FC_ASSERT(limit <= max_account_history_operations_limit);
vector<operation_history_object> result;
account_id_type account;
try {
Expand Down
11 changes: 11 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ void application_impl::startup()
if ( _options->count("enable-subscribe-to-all") )
_app_options.enable_subscribe_to_all = _options->at( "enable-subscribe-to-all" ).as<bool>();

if ( _options->count("max-account-history-operations-limit") )
{
_app_options.max_account_history_operations_limit = _options->at("max-account-history-operations-limit").as<uint32_t>();
}

if( _active_plugins.find( "market_history" ) != _active_plugins.end() )
_app_options.has_market_history_plugin = true;

Expand Down Expand Up @@ -982,6 +987,8 @@ void application::set_program_options(boost::program_options::options_descriptio
("enable-standby-votes-tracking", bpo::value<bool>()->implicit_value(true),
"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.")
("max-account-history-operations-limit",boost::program_options::value<uint32_t>()->default_value(100),
"for history_api::get_account_history_operations to set its limit value default ass 100")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down Expand Up @@ -1096,6 +1103,10 @@ void application::set_block_production(bool producing_blocks)
{
my->_is_block_producer = producing_blocks;
}
void application::set_options_max_account_history_operations_limit(const uint64_t& max_limit)
{
my->_app_options.max_account_history_operations_limit=max_limit;
}

optional< api_access_info > application::get_api_access_info( const string& username )const
{
Expand Down
3 changes: 2 additions & 1 deletion libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace graphene { namespace app {
public:
bool enable_subscribe_to_all = false;
bool has_market_history_plugin = false;
uint64_t max_account_history_operations_limit=100;
};

class application
Expand Down Expand Up @@ -87,7 +88,7 @@ namespace graphene { namespace app {

net::node_ptr p2p_node();
std::shared_ptr<chain::database> chain_database()const;

void set_options_max_account_history_operations_limit(const uint64_t& max_limit);
void set_block_production(bool producing_blocks);
fc::optional< api_access_info > get_api_access_info( const string& username )const;
void set_api_access_info(const string& username, api_access_info&& permissions);
Expand Down
5 changes: 5 additions & 0 deletions tests/common/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ database_fixture::database_fixture()
{
options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)75, false)));
}
if (current_test_name == "setting_max_operation_limit_get_account_history_operations")
{
options.insert(std::make_pair("max-ops-per-account", boost::program_options::variable_value((uint64_t)125, false)));
app.set_options_max_account_history_operations_limit(300);
pmconrad marked this conversation as resolved.
Show resolved Hide resolved
}
// 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
70 changes: 70 additions & 0 deletions tests/tests/history_api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,5 +604,75 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) {
throw;
}
}
//new test case for increasing the limit based on the config file
BOOST_AUTO_TEST_CASE(setting_max_operation_limit_get_account_history_operations) {
try {
graphene::app::history_api hist_api(app);

//account_id_type() do 3 ops
create_bitasset("CNY", account_id_type());
create_account("sam");
create_account("alice");

generate_block();
fc::usleep(fc::milliseconds(2000));

int asset_create_op_id = operation::tag<asset_create_operation>::value;
int account_create_op_id = operation::tag<account_create_operation>::value;
int transfer_op_id = operation::tag<graphene::chain::transfer_operation>::value;
manikey123 marked this conversation as resolved.
Show resolved Hide resolved

//account_id_type() did 1 asset_create op
vector<operation_history_object> histories = hist_api.get_account_history_operations(
"committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 200);
BOOST_CHECK_EQUAL(histories.size(), 1);
BOOST_CHECK_EQUAL(histories[0].id.instance(), 0);
BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id);

//account_id_type() did 2 account_create ops
histories = hist_api.get_account_history_operations(
"committee-account", account_create_op_id, operation_history_id_type(), operation_history_id_type(), 200);
BOOST_CHECK_EQUAL(histories.size(), 2);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);

// No asset_create op larger than id1
histories = hist_api.get_account_history_operations(
"committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(1), 200);
BOOST_CHECK_EQUAL(histories.size(), 0);

// Limit 1 returns 1 result
histories = hist_api.get_account_history_operations(
"committee-account", account_create_op_id, operation_history_id_type(),operation_history_id_type(), 1);
BOOST_CHECK_EQUAL(histories.size(), 1);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);

// alice has 1 op
histories = hist_api.get_account_history_operations(
"alice", account_create_op_id, operation_history_id_type(),operation_history_id_type(), 200);
BOOST_CHECK_EQUAL(histories.size(), 1);
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);

// create a bunch of accounts
for(int i = 0; i < 126; ++i)
{
std::string acct_name = "mytempacct" + std::to_string(i);
create_account(acct_name);
}
generate_block();

// history is set to limit transactions to 125 (see database_fixture.hpp)
// so asking for more should only return 125 (and not throw exception,
// see https://github.com/bitshares/bitshares-core/issues/1490
histories = hist_api.get_account_history_operations(
"committee-account", account_create_op_id, operation_history_id_type(), operation_history_id_type(), 125);
BOOST_CHECK_EQUAL(histories.size(), 125);
if (histories.size() > 0)
manikey123 marked this conversation as resolved.
Show resolved Hide resolved
BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id);


} catch (fc::exception &e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_SUITE_END()