From dfba08536b0c66e5e8b77fc7f115f9900f26d21d Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Wed, 4 Sep 2019 12:45:43 +0530 Subject: [PATCH 1/3] Fixed duplicate ops returned from get_account_history --- libraries/wallet/wallet.cpp | 40 +++++++++++++++++++++++++++++-------- tests/cli/main.cpp | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 0df82e7d..6acbacf0 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -3449,30 +3449,54 @@ asset wallet_api::get_lottery_balance( asset_id_type lottery_id )const return my->_remote_db->get_lottery_balance( lottery_id ); } -vector wallet_api::get_account_history(string name, int limit)const +vector wallet_api::get_account_history(string name, int limit) const { vector result; auto account_id = get_account(name).get_id(); - while( limit > 0 ) + while (limit > 0) { + bool skip_first_row = false; operation_history_id_type start; - if( result.size() ) + if (result.size()) { start = result.back().op.id; - start = start + 1; + if (start == operation_history_id_type()) // no more data + break; + start = start + (-1); + if (start == operation_history_id_type()) // will return most recent history if directly call remote API with this + { + start = start + 1; + skip_first_row = true; + } } + int page_limit = skip_first_row ? std::min(100, limit + 1) : std::min(100, limit); - vector current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), std::min(100,limit), start); - for( auto& o : current ) { + vector current = my->_remote_hist->get_account_history(account_id, operation_history_id_type(), + page_limit, start); + bool first_row = true; + for (auto &o : current) + { + if (first_row) + { + first_row = false; + if (skip_first_row) + { + continue; + } + } std::stringstream ss; auto memo = o.op.visit(detail::operation_printer(ss, *my, o.result)); - result.push_back( operation_detail{ memo, ss.str(), o } ); + result.push_back(operation_detail{memo, ss.str(), o}); } - if( (int)current.size() < std::min(100,limit) ) + + if (int(current.size()) < page_limit) break; + limit -= current.size(); + if (skip_first_row) + ++limit; } return result; diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index 82adb1c5..b94e1b1a 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -438,3 +438,42 @@ BOOST_FIXTURE_TEST_CASE( cli_vote_for_2_witnesses, cli_fixture ) throw; } } + +/////////////////////// +// Check account history pagination (see peerplay-core/issue/1176) +/////////////////////// +BOOST_FIXTURE_TEST_CASE( account_history_pagination, cli_fixture ) +{ + try + { + INVOKE(create_new_account); + + // attempt to give jmjatlanta some peerplay + BOOST_TEST_MESSAGE("Transferring peerplay from Nathan to jmjatlanta"); + for(int i = 1; i <= 199; i++) + { + signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "jmjatlanta", std::to_string(i), + "1.3.0", "Here are some CORE token for your new account", true); + } + + BOOST_CHECK(generate_block(app1)); + + // now get account history and make sure everything is there (and no duplicates) + std::vector history = con.wallet_api_ptr->get_account_history("jmjatlanta", 300); + BOOST_CHECK_EQUAL(201u, history.size() ); + + std::set operation_ids; + + for(auto& op : history) + { + if( operation_ids.find(op.op.id) != operation_ids.end() ) + { + BOOST_FAIL("Duplicate found"); + } + operation_ids.insert(op.op.id); + } + } catch( fc::exception& e ) { + edump((e.to_detail_string())); + throw; + } +} \ No newline at end of file From 12ef66731232f8e2079c8ecd7522c1fb243b3923 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Sat, 14 Sep 2019 14:26:42 +0530 Subject: [PATCH 2/3] Fixed account_history_pagination test --- tests/cli/main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index b94e1b1a..aea501b6 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -117,6 +118,7 @@ std::shared_ptr start_application(fc::temp_directory std::shared_ptr app1(new graphene::app::application{}); app1->register_plugin< graphene::bookie::bookie_plugin>(); + app1->register_plugin(); app1->startup_plugins(); boost::program_options::variables_map cfg; #ifdef _WIN32 From 5a00e4fab33fe3f7d6917179d5d0081411a33f74 Mon Sep 17 00:00:00 2001 From: Sandip Patel Date: Wed, 18 Sep 2019 10:17:44 +0530 Subject: [PATCH 3/3] Removed unrelated comment --- tests/cli/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index aea501b6..e5b6dbcf 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -442,7 +442,7 @@ BOOST_FIXTURE_TEST_CASE( cli_vote_for_2_witnesses, cli_fixture ) } /////////////////////// -// Check account history pagination (see peerplay-core/issue/1176) +// Check account history pagination /////////////////////// BOOST_FIXTURE_TEST_CASE( account_history_pagination, cli_fixture ) {