-
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
Conversation
relating #576 |
very useful! |
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 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!
with the empty seed-nodes the tests will be quicker as the node does not need to connect to those remote addresses. |
tests/cli/main.cpp
Outdated
init1_obj = wapiptr->get_witness("init1"); | ||
|
||
int init2_middle_votes = init2_obj.total_votes; | ||
BOOST_CHECK(init2_middle_votes > init2_start_votes); |
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.
this test is failing.
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.
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?
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.
this can be done by another way, check for example:
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 :)
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.
It is a modified version of what is in database_fixture. No more playing with the default maintenance interval
tests/cli/main.cpp
Outdated
|
||
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
make test to check if the proxy changed.
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.
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.
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.
Created a new test for testing voting proxy
2cc12d9
to
4f6b0f8
Compare
tests/cli/main.cpp
Outdated
/** | ||
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Separated the proxy into its own test
tests/cli/main.cpp
Outdated
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
good, thanks.
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.
looks good to me now John. thank you for the changes.
tests/cli/main.cpp
Outdated
// 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 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.
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.
It's good that the tests are working. However, it's best if we can abstract the common procedures for ease of future use.
tests/cli/main.cpp
Outdated
@@ -0,0 +1,388 @@ | |||
/* | |||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors. |
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.
IMHO better replace Cryptonomex with your own name and replace year to 2018.
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
tests/cli/main.cpp
Outdated
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)); |
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
tests/cli/main.cpp
Outdated
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"; |
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.
Why output to std::cerr
?
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.
Removed
tests/cli/main.cpp
Outdated
// 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"; |
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.
Replace the port with the chosen 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
tests/cli/main.cpp
Outdated
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 ) ); |
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 reuse the code. Almost every test case need to connect first.
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.
Created a class that connects and provides all connectivity objects
tests/cli/main.cpp
Outdated
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); |
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.
After generated the genesis file, please replace all Public keys with a new random key, then use it in later tests.
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.
I am unfamiliar with the PKI architecture in Bitshares. I am working on familiarizing myself with this now.
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.
Mostly good so far. May need to reorganize (e.g. split it to several files) in the future.
By the way, please resolve conflicts.
tests/cli/main.cpp
Outdated
} | ||
|
||
/*** | ||
* @brief Start the application, listening on port 8090 |
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 replace the 8090
here.
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
tests/cli/main.cpp
Outdated
*/ | ||
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"))); |
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.
Can use the same method to generate a new key and replace the keys generated in genesis file.
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.
Still working on this...
tests/cli/main.cpp
Outdated
using namespace graphene::app; | ||
std::shared_ptr<graphene::app::application> app1; | ||
try { | ||
fc::temp_directory app_dir ( graphene::utilities::temp_directory_path() ); |
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 replace tabs with spaces.
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.
3 spaces for indentation.
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.
Again!?!??!! Cleaned up.
tests/cli/main.cpp
Outdated
@@ -51,18 +51,49 @@ | |||
* Helper Methods | |||
*********************/ | |||
|
|||
// hack: import create_example_genesis() even though it's a way, way | |||
// specific internal detail | |||
///////// |
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.
I'm not sure whether Doxygen recognize this format. It does recognize /** */
.
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.
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.
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.
According to the link, maybe need 3 slashes?
/////////////
/// doc
///////////
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.
Yes, you are correct. I have modified the areas that should be doxygen'd.
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.