-
Notifications
You must be signed in to change notification settings - Fork 649
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
Refactor cli_test #1192 #1243
Refactor cli_test #1192 #1243
Conversation
This is ready for testing. Valera mentioned his original estimate of 4 hours was too few. Now estimating 10 hours. Core Team: please assist me with revising the estimation based on the original Issue, comments, development and resulting PR. |
I've spent even more than 10 hours, so guys specify your estimation please and I will agree with it, because I'm still new dev in BitShares Core and my estimation maybe wrong for you ;-) you know better than me how many hours it would take for you ... |
tests/cli/main.cpp
Outdated
using namespace graphene::chain; | ||
using namespace graphene::app; | ||
//using namespace graphene::chain; | ||
//using namespace graphene::app; |
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.
pls remove comments.
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.
sure ! removed ! 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, tested and works as expected. well done.
Thanks ! |
can we merge this PR and close related issue ? or this is not still ready and need some changes and improvements ? if YES, then which changes and improvements in your opinion ? Thanks ! |
I'd say split it into smaller files. |
tests/cli/main.cpp
Outdated
} | ||
app1->shutdown(); | ||
try | ||
{ |
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 changed the indentation to 4 white spaces (both above and below)?
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.
where can I see BitShares Core coding convention ? I prefer 4 white spaces, what do you prefer ?
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. sorry @abitmore i didnt saw this one.
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.
indentation everywhere in BitShares Core code base is prefer to 3 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.
yes. 3 spaces everywhere(except p2p code that uses 2 but we don't want to change that 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.
ok sure. Thank you very much ! Does BitShares Core have code convention ?
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 you please change the indentation back to 3 white spaces? Thanks.
We don't have code conventions so far.
tests/cli/main.cpp
Outdated
account_object nathan_acct_after_upgrade; | ||
graphene::wallet::brain_key_info bki; | ||
signed_transaction create_acct_tx; | ||
signed_transaction transfer_tx; |
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.
Should not define so many different transaction objects in cli_fixture
; nathan_acct_before_upgrade
and nathan_acct_after_upgrade
should not be here as well; they should be declared in individual test cases.
tests/cli/main.cpp
Outdated
|
||
BOOST_TEST_MESSAGE("Importing nathan's balance"); | ||
import_txs = con->wallet_api_ptr->import_balance("nathan", nathan_keys, true); | ||
nathan_acct_before_upgrade = con->wallet_api_ptr->get_account("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.
The nathan account upgrading should be in a "basic" test case and be invoked by needed test cases, but not in fixture.
tests/cli/main.cpp
Outdated
// create a new account | ||
bki = con->wallet_api_ptr->suggest_brain_key(); | ||
BOOST_CHECK(!bki.brain_priv_key.empty()); | ||
create_acct_tx = con->wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "jmjatlanta", "nathan", "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.
The jmj account creation should be in a test case as well.
tests/cli/main.cpp
Outdated
|
||
// attempt to give jmjatlanta some bitsahres | ||
BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to jmjatlanta"); | ||
transfer_tx = con->wallet_api_ptr->transfer("nathan", "jmjatlanta", "10000", "1.3.0", "Here are some CORE token for your new account", 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.
The transfer should not be in cli_fixture.
made improvements as @abitmore mentioned, do we need here some more changes/improvements or not ? |
tests/cli/main.cpp
Outdated
} | ||
app1->shutdown(); | ||
try | ||
{ |
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 you please change the indentation back to 3 white spaces? Thanks.
We don't have code conventions so far.
tests/cli/main.cpp
Outdated
int server_port_number {0}; | ||
fc::temp_directory app_dir = graphene::utilities::temp_directory_path(); | ||
std::shared_ptr<graphene::app::application> app1 = start_application(app_dir, server_port_number); | ||
client_connection* con = new client_connection(app1, app_dir, server_port_number); |
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.
Initializing these variables here is a bad idea. They're heavy. Better move them to a constructor. Then some member variables can be changed to local variable.
By the way, why need to use a pointer?
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.
- fixed indentation from 4 white spaces to 3 (commit is ready)
- initializing variables in constructor has different compile errors, need to fight all them, trying to understand why they happened, still fighting ...
- I've used pointer because without pointer I had compile errors, still trying to understand why and still fighting with them ...
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.
unknown location(0): fatal error: in "cli_connect": memory access violation at address: 0x00000064: no mapping at fault address
/home/valera/Projects/Blockchain/Graphene/BitShares/bitshares-core/tests/cli/main.cpp(260): last checkpoint: "cli_connect" fixture ctor
*** 1 failure is detected in the test module "Test Application"
such error I see when trying to call next method:
app_dir = graphene::utilities::temp_directory_path();
It means next:
BOOST_FIXTURE_TEST_CASE( cli_connect, cli_fixture )
- this Boost fixture cannot call cli_fixture
constructor with graphene::utilities::temp_directory_path()
method inside, maybe I'm doing something wrong ? Still trying to understand the reason and to code as we desire !
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.
fixed by direct initialization instead of using assignment operators inside constructor body
tests/cli/main.cpp
Outdated
// upgrade nathan | ||
BOOST_TEST_MESSAGE("Upgrading Nathan to LTM"); | ||
upgrade_tx = con->wallet_api_ptr->upgrade_account("nathan", true); | ||
nathan_acct_after_upgrade = con->wallet_api_ptr->get_account("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.
The upgrade of nathan account can be abstracted to a single test case, then be invoked by other test cases. See this for example:
INVOKE(create_account_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.
will do it soon
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.
INVOKE doesn't work well enough with test fixtures, also need to fight here with errors
…emory access violation error
…nment operators inside the constructor body
guys, when you will have enough time check please my new changes, I've committed all required changes that were asked by @abitmore , hope all was done correctly enough, I've compiled and tested and it seems work absolutely as intended. Thanks a lot ! |
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 much better now. Thanks!
tests/cli/main.cpp
Outdated
|
||
// create a new account | ||
graphene::wallet::brain_key_info bki = con.wallet_api_ptr->suggest_brain_key(); | ||
BOOST_CHECK(!bki.brain_priv_key.empty()); | ||
signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key( | ||
bki.brain_priv_key, "jmjatlanta", "nathan", "nathan", true); | ||
signed_transaction create_acct_tx = con.wallet_api_ptr->create_account_with_brain_key(bki.brain_priv_key, "jmjatlanta", "nathan", "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.
Apparently your screen is wider than mine. I like the wrapped format, at max around 130 characters a line.
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.
ok sure ! I will format the whole file right now as required !
tests/cli/main.cpp
Outdated
nathan_acct_after_upgrade = con.wallet_api_ptr->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()) ); |
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 line is too long to fit in my screen as well.
By the way there were some long lines that didn't change, so I'm unable to comment on them. Please help wrap them as well.
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.
ok sure !
tests/cli/main.cpp
Outdated
std::vector<std::string> nathan_keys; | ||
|
||
cli_fixture() : | ||
server_port_number(0), |
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 think we can use some indentations 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.
ok sure !
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 so far. Waiting for CI reports.
Thank you ! |
@oxarbitrage @jmjatlanta @pmconrad your opinions? |
i think it is looking great but i will suggest the following if possible: the "create a new account", "save the private key for this new account in the wallet file" and "attempt to give jmjatlanta some bitsahres" are pretty common actions. maybe create test for the new test to make sense you can add some checks on it like if the account was created and if the transfer went ok. |
@oxarbitrage thank you very much ! Your idea is great and makes sense ! I think I need to code it too. Is anybody disagree ? |
|
||
// attempt to give jmjatlanta some bitsahres | ||
BOOST_TEST_MESSAGE("Transferring bitshares from Nathan to jmjatlanta"); | ||
for(int i = 1; i <= 200; i++) | ||
for(int i = 1; i <= 199; i++) |
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 this change? Something was broken?
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.
nothing was broken, I've changed this because we have +1 transaction inside INVOKE create_new_account, and I've decided to decrease here history by -1 transaction. Should I change another way ? I can change BOOST_CHECK history transfers to 202 as an example here
bitshares-core/tests/cli/main.cpp
Line 518 in 18a78a5
BOOST_CHECK_EQUAL(201, history.size() ); |
what are your thoughts ? 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.
I've changed this because we have +1 transaction inside INVOKE create_new_account, and I've decided to decrease here history by -1 transaction.
Makes sense. Thanks.
Looks good, but haven't checked in depth. |
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 too, should be easier to add more tests here with the new framework. thanks.
Thank you guys ! |
Thanks for merge ! |
PR for #1192