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

add cli wallet test framework #675

Merged
merged 13 commits into from
Mar 21, 2018
Merged

Conversation

jmjatlanta
Copy link
Contributor

These are tests and helper functions for testing wallet functionality. Please review and feel free to comment about improvements.

This was originally to test issue 576, but a new ticket was created (674) for cleanup of the test code.

@oxarbitrage oxarbitrage changed the title Issue 674 and 576 add cli wallet test framework Feb 19, 2018
@oxarbitrage
Copy link
Member

relating #576

@oxarbitrage
Copy link
Member

very useful!

@oxarbitrage oxarbitrage self-requested a review February 19, 2018 15:17
Copy link
Member

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please pass --seed-nodes "[]" to the start of the witness node to avoid connecting to the live blockchain seeds. this is a private testnet setup and need to pass empty seeds. thanks!

@oxarbitrage
Copy link
Member

with the empty seed-nodes the tests will be quicker as the node does not need to connect to those remote addresses.

init1_obj = wapiptr->get_witness("init1");

int init2_middle_votes = init2_obj.total_votes;
BOOST_CHECK(init2_middle_votes > init2_start_votes);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is failing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a check to make sure the maintenance interval is set to a low value for this test. Is there a way to adjust the maintenance interval at run time?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be done by another way, check for example:

https://github.com/bitshares/bitshares-core/blob/master/tests/tests/swan_tests.cpp#L114

in there, block production advances until a hardfork time, you can play with that in order to advance the chain to the time you need. it will be something like:

vote for witness
advance until next maintenance
check for vote

looking good :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at https://github.com/jmjatlanta/bitshares-core/blob/b6a6dc3a1f3b3af1f8b3e65f2392863fb306670c/tests/cli/main.cpp#L113

It is a modified version of what is in database_fixture. No more playing with the default maintenance interval


// 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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make test to check if the proxy changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, i think they should be separated test than the cli_vote_for_2_witnesses , something like proxy_update will do it.
in cli_vote_for_2_witnesses only add the needed stuff for that test. we will add more as we need them in different test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a new test for testing voting proxy

/**
* Start a server and connect using the same calls as the CLI
*/
BOOST_AUTO_TEST_CASE( cli_set_voting_proxy )
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separated the proxy into its own test

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));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer attempting to connect to seed nodes during test

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good, thanks.

oxarbitrage
oxarbitrage previously approved these changes Feb 26, 2018
Copy link
Member

@oxarbitrage oxarbitrage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me now John. thank you for the changes.

// 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);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please confirm the proxy is now nathan for jmatlanta with BOOST_CHECK. every change should be followed by a test if possible.

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good that the tests are working. However, it's best if we can abstract the common procedures for ease of future use.

@@ -0,0 +1,388 @@
/*
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO better replace Cryptonomex with your own name and replace year to 2018.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

app1->register_plugin< graphene::witness_plugin::witness_plugin >();
app1->startup_plugins();
boost::program_options::variables_map cfg;
cfg.emplace("rpc-endpoint", boost::program_options::variable_value(string("127.0.0.1:8090"), false));
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

boost::filesystem::path genesis_path = boost::filesystem::path{directory.path().generic_string()} / "genesis.json";
fc::path genesis_out = genesis_path;
graphene::chain::genesis_state_type genesis_state = graphene::app::detail::create_example_genesis();
std::cerr << "Creating example genesis state in file " << genesis_out.generic_string() << "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why output to std::cerr?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

// 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";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace the port with the chosen random port.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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 ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reuse the code. Almost every test case need to connect first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created a class that connects and provides all connectivity objects

fc::path genesis_out = genesis_path;
graphene::chain::genesis_state_type genesis_state = graphene::app::detail::create_example_genesis();
std::cerr << "Creating example genesis state in file " << genesis_out.generic_string() << "\n";
fc::json::save_to_file(genesis_state, genesis_out);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After generated the genesis file, please replace all Public keys with a new random key, then use it in later tests.

Copy link
Contributor Author

@jmjatlanta jmjatlanta Mar 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unfamiliar with the PKI architecture in Bitshares. I am working on familiarizing myself with this now.

Copy link
Member

@abitmore abitmore left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly good so far. May need to reorganize (e.g. split it to several files) in the future.

By the way, please resolve conflicts.

}

/***
* @brief Start the application, listening on port 8090
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace the 8090 here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

*/
bool generate_block(std::shared_ptr<graphene::app::application> app) {
try {
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the same method to generate a new key and replace the keys generated in genesis file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still working on this...

using namespace graphene::app;
std::shared_ptr<graphene::app::application> app1;
try {
fc::temp_directory app_dir ( graphene::utilities::temp_directory_path() );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace tabs with spaces.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 spaces for indentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again!?!??!! Cleaned up.

@@ -51,18 +51,49 @@
* Helper Methods
*********************/

// hack: import create_example_genesis() even though it's a way, way
// specific internal detail
/////////
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure whether Doxygen recognize this format. It does recognize /** */.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is recognized. https://www.stack.nl/~dimitri/doxygen/manual/docblocks.html

I prefer /* */, but some like // as it allows you to comment out big chunks of code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the link, maybe need 3 slashes?

/////////////
/// doc
///////////

Copy link
Contributor Author

@jmjatlanta jmjatlanta Mar 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you are correct. I have modified the areas that should be doxygen'd.

@abitmore abitmore merged commit 39cf1c3 into bitshares:develop Mar 21, 2018
@jmjatlanta jmjatlanta deleted the Issue_576 branch March 21, 2018 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants