-
Notifications
You must be signed in to change notification settings - Fork 648
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
add cli wallet test framework #675
Changes from 1 commit
5b3ee10
8f2d468
bc6c470
c544f5a
4f6b0f8
f545941
218a073
b6a6dc3
11fae0a
9bd3e5b
aaee5ad
adde3fa
f8edc28
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ std::shared_ptr<graphene::app::application> start_application(fc::temp_directory | |
boost::program_options::variables_map cfg; | ||
cfg.emplace("rpc-endpoint", boost::program_options::variable_value(string("127.0.0.1:8090"), false)); | ||
cfg.emplace("genesis-json", boost::program_options::variable_value(create_genesis_file(app_dir), false)); | ||
cfg.emplace("seed-nodes", boost::program_options::variable_value(string("[]"), false)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer attempting to connect to seed nodes during test There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good, thanks. |
||
app1->initialize(app_dir.path(), cfg); | ||
|
||
app1->startup(); | ||
|
@@ -229,6 +230,7 @@ BOOST_AUTO_TEST_CASE( cli_vote_for_2_witnesses ) | |
|
||
// wait for a maintenance interval | ||
// NOTE: For this to work consistently, your maintenance interval must be less than 20 seconds | ||
// see libraries/chain/include/graphene/chain/config.hpp:L50 GRAPHENE_DEFAULT_MAINTENANCE_INTERVAL (seconds) | ||
fc::usleep(fc::seconds(20)); | ||
// send a block to trigger maintenance interval | ||
BOOST_CHECK(generate_block(*app1.get())); | ||
|
@@ -268,3 +270,96 @@ BOOST_AUTO_TEST_CASE( cli_vote_for_2_witnesses ) | |
} | ||
app1->shutdown(); | ||
} | ||
|
||
/** | ||
* Start a server and connect using the same calls as the CLI | ||
*/ | ||
BOOST_AUTO_TEST_CASE( cli_set_voting_proxy ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separated the proxy into its own test |
||
{ | ||
using namespace graphene::chain; | ||
using namespace graphene::app; | ||
std::shared_ptr<graphene::app::application> app1; | ||
try { | ||
|
||
fc::temp_directory app_dir( graphene::utilities::temp_directory_path() ); | ||
|
||
app1 = start_application(app_dir); | ||
|
||
// connect to the server | ||
graphene::wallet::wallet_data wdata; | ||
wdata.chain_id = app1->chain_database()->get_chain_id(); | ||
wdata.ws_server = "ws://127.0.0.1:8090"; | ||
wdata.ws_user = ""; | ||
wdata.ws_password = ""; | ||
fc::http::websocket_client client; | ||
auto con = client.connect( wdata.ws_server ); | ||
|
||
auto apic = std::make_shared<fc::rpc::websocket_api_connection>(*con); | ||
|
||
auto remote_api = apic->get_remote_api< login_api >(1); | ||
BOOST_CHECK(remote_api->login( wdata.ws_user, wdata.ws_password ) ); | ||
|
||
auto wapiptr = std::make_shared<graphene::wallet::wallet_api>(wdata, remote_api); | ||
std::stringstream wallet_filename; | ||
wallet_filename << app_dir.path().generic_string() << "/wallet.json"; | ||
wapiptr->set_wallet_filename(wallet_filename.str()); | ||
|
||
fc::api<graphene::wallet::wallet_api> wapi(wapiptr); | ||
|
||
auto wallet_cli = std::make_shared<fc::rpc::cli>(); | ||
for( auto& name_formatter : wapiptr->get_result_formatters() ) | ||
wallet_cli->format_result( name_formatter.first, name_formatter.second ); | ||
|
||
boost::signals2::scoped_connection closed_connection(con->closed.connect([=]{ | ||
cerr << "Server has disconnected us.\n"; | ||
wallet_cli->stop(); | ||
})); | ||
(void)(closed_connection); | ||
|
||
BOOST_TEST_MESSAGE("Setting wallet password"); | ||
wapiptr->set_password("supersecret"); | ||
wapiptr->unlock("supersecret"); | ||
|
||
// import Nathan account | ||
BOOST_TEST_MESSAGE("Importing nathan key"); | ||
std::vector<std::string> nathan_keys{"5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"}; | ||
BOOST_CHECK_EQUAL(nathan_keys[0], "5KQwrPbwdL6PhXujxW37FSSQZ1JiwsST4cqQzDeyXtP79zkvFD3"); | ||
BOOST_CHECK(wapiptr->import_key("nathan", nathan_keys[0])); | ||
|
||
BOOST_TEST_MESSAGE("Importing nathan's balance"); | ||
std::vector<signed_transaction> import_txs = wapiptr->import_balance("nathan", nathan_keys, true); | ||
account_object nathan_acct_before_upgrade = wapiptr->get_account("nathan"); | ||
|
||
// upgrade nathan | ||
BOOST_TEST_MESSAGE("Upgrading Nathan to LTM"); | ||
signed_transaction upgrade_tx = wapiptr->upgrade_account("nathan", true); | ||
account_object nathan_acct_after_upgrade = wapiptr->get_account("nathan"); | ||
|
||
// verify that the upgrade was successful | ||
BOOST_CHECK_PREDICATE( std::not_equal_to<uint32_t>(), (nathan_acct_before_upgrade.membership_expiration_date.sec_since_epoch())(nathan_acct_after_upgrade.membership_expiration_date.sec_since_epoch()) ); | ||
BOOST_CHECK(nathan_acct_after_upgrade.is_lifetime_member()); | ||
|
||
// create a new account | ||
graphene::wallet::brain_key_info bki = wapiptr->suggest_brain_key(); | ||
BOOST_CHECK(!bki.brain_priv_key.empty()); | ||
signed_transaction create_acct_tx = wapiptr->create_account_with_brain_key(bki.brain_priv_key, "jmjatlanta", "nathan", "nathan", true); | ||
// save the private key for this new account in the wallet file | ||
BOOST_CHECK(wapiptr->import_key("jmjatlanta", bki.wif_priv_key)); | ||
wapiptr->save_wallet_file(wallet_filename.str()); | ||
|
||
// attempt to give jmjatlanta some bitsahres | ||
BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to jmjatlanta"); | ||
signed_transaction transfer_tx = wapiptr->transfer("nathan", "jmjatlanta", "10000", "BTS", "Here are some BTS for your new account", true); | ||
|
||
// set the voting proxy to nathan | ||
BOOST_TEST_MESSAGE("About to set voting proxy."); | ||
signed_transaction voting_tx = wapiptr->set_voting_proxy("jmjatlanta", "nathan", true); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please confirm the proxy is now |
||
// wait for everything to finish up | ||
fc::usleep(fc::seconds(1)); | ||
} catch( fc::exception& e ) { | ||
edump((e.to_detail_string())); | ||
throw; | ||
} | ||
app1->shutdown(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use an available random port.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done