Skip to content

Commit 6e05a8f

Browse files
authored
Merge pull request #1179 from jmjatlanta/1176-cli-account-his
Test of account history pagination
2 parents 1833a94 + 3bca92b commit 6e05a8f

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

tests/cli/main.cpp

+86
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ std::shared_ptr<graphene::app::application> start_application(fc::temp_directory
9595
cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false));
9696
app1->initialize(app_dir.path(), cfg);
9797

98+
app1->initialize_plugins(cfg);
99+
app1->startup_plugins();
100+
98101
app1->startup();
99102
fc::usleep(fc::milliseconds(500));
100103
return app1;
@@ -483,3 +486,86 @@ BOOST_AUTO_TEST_CASE( cli_confidential_tx_test )
483486
}
484487
app1->shutdown();
485488
}
489+
490+
/******
491+
* Check account history pagination (see bitshares-core/issue/1176)
492+
*/
493+
BOOST_AUTO_TEST_CASE( account_history_pagination )
494+
{
495+
using namespace graphene::chain;
496+
using namespace graphene::app;
497+
std::shared_ptr<graphene::app::application> app1;
498+
try {
499+
fc::temp_directory app_dir ( graphene::utilities::temp_directory_path() );
500+
501+
int server_port_number = 0;
502+
app1 = start_application(app_dir, server_port_number);
503+
504+
// connect to the server
505+
client_connection con(app1, app_dir, server_port_number);
506+
507+
// set wallet password
508+
BOOST_TEST_MESSAGE("Setting wallet password");
509+
con.wallet_api_ptr->set_password("supersecret");
510+
con.wallet_api_ptr->unlock("supersecret");
511+
512+
// import Nathan account
513+
BOOST_TEST_MESSAGE("Importing nathan key");
514+
std::vector<std::string> nathan_keys{"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"};
515+
BOOST_CHECK_EQUAL(nathan_keys[0], "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3");
516+
BOOST_CHECK(con.wallet_api_ptr->import_key("nathan", nathan_keys[0]));
517+
518+
BOOST_TEST_MESSAGE("Importing nathan's balance");
519+
std::vector<signed_transaction> import_txs = con.wallet_api_ptr->import_balance("nathan", nathan_keys, true);
520+
account_object nathan_acct_before_upgrade = con.wallet_api_ptr->get_account("nathan");
521+
522+
// upgrade nathan
523+
BOOST_TEST_MESSAGE("Upgrading Nathan to LTM");
524+
signed_transaction upgrade_tx = con.wallet_api_ptr->upgrade_account("nathan", true);
525+
account_object nathan_acct_after_upgrade = con.wallet_api_ptr->get_account("nathan");
526+
527+
// verify that the upgrade was successful
528+
BOOST_CHECK_PREDICATE( std::not_equal_to<uint32_t>(),
529+
(nathan_acct_before_upgrade.membership_expiration_date.sec_since_epoch())
530+
(nathan_acct_after_upgrade.membership_expiration_date.sec_since_epoch()) );
531+
BOOST_CHECK(nathan_acct_after_upgrade.is_lifetime_member());
532+
533+
// create a new account
534+
graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key();
535+
BOOST_CHECK(!bki.brain_priv_key.empty());
536+
signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(
537+
bki.brain_priv_key, "jmjatlanta", "nathan", "nathan", true);
538+
// save the private key for this new account in the wallet file
539+
BOOST_CHECK(con.wallet_api_ptr->import_key("jmjatlanta", bki.wif_priv_key));
540+
con.wallet_api_ptr->save_wallet_file(con.wallet_filename);
541+
542+
// attempt to give jmjatlanta some bitsahres
543+
BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to jmjatlanta");
544+
for(int i = 1; i <= 200; i++)
545+
{
546+
signed_transaction transfer_tx = con.wallet_api_ptr->transfer("nathan", "jmjatlanta", std::to_string(i),
547+
"1.3.0", "Here are some BTS for your new account", true);
548+
}
549+
550+
BOOST_CHECK(generate_block(app1));
551+
552+
// now get account history and make sure everything is there (and no duplicates)
553+
std::vector<graphene::wallet::operation_detail> history = con.wallet_api_ptr->get_account_history("jmjatlanta", 300);
554+
BOOST_CHECK_EQUAL(201, history.size() );
555+
556+
std::set<object_id_type> operation_ids;
557+
558+
for(auto op : history)
559+
{
560+
if (operation_ids.find(op.op.id) != operation_ids.end())
561+
BOOST_FAIL("Duplicate found");
562+
operation_ids.insert(op.op.id);
563+
}
564+
565+
} catch( fc::exception& e ) {
566+
edump((e.to_detail_string()));
567+
throw;
568+
}
569+
app1->shutdown();
570+
571+
}

0 commit comments

Comments
 (0)