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

Refactor cli_test #1192 #1243

Merged
merged 11 commits into from
Aug 29, 2018
Merged

Refactor cli_test #1192 #1243

merged 11 commits into from
Aug 29, 2018

Conversation

cogutvalera
Copy link
Member

PR for #1192

@ryanRfox ryanRfox added the 2e Ready for Testing Status indicating the solution is sufficiently developed to begin testing label Aug 9, 2018
@ryanRfox
Copy link
Contributor

ryanRfox commented Aug 9, 2018

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.

@cogutvalera
Copy link
Member Author

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 ...

using namespace graphene::chain;
using namespace graphene::app;
//using namespace graphene::chain;
//using namespace graphene::app;
Copy link
Member

Choose a reason for hiding this comment

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

pls remove comments.

Copy link
Member Author

Choose a reason for hiding this comment

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

sure ! removed ! thanks !

oxarbitrage
oxarbitrage previously approved these changes Aug 10, 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, tested and works as expected. well done.

@cogutvalera
Copy link
Member Author

Thanks !

oxarbitrage
oxarbitrage previously approved these changes Aug 10, 2018
@cogutvalera
Copy link
Member Author

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 !

@abitmore
Copy link
Member

I'd say split it into smaller files.

}
app1->shutdown();
try
{
Copy link
Member

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)?

Copy link
Member Author

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 ?

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. sorry @abitmore i didnt saw this one.

Copy link
Member Author

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 ?

Copy link
Member

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)

Copy link
Member Author

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 ?

Copy link
Member

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.

account_object nathan_acct_after_upgrade;
graphene::wallet::brain_key_info bki;
signed_transaction create_acct_tx;
signed_transaction transfer_tx;
Copy link
Member

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.


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

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.

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

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.


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

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.

@cogutvalera
Copy link
Member Author

made improvements as @abitmore mentioned, do we need here some more changes/improvements or not ?

}
app1->shutdown();
try
{
Copy link
Member

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.

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

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?

Copy link
Member Author

@cogutvalera cogutvalera Aug 24, 2018

Choose a reason for hiding this comment

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

  1. fixed indentation from 4 white spaces to 3 (commit is ready)
  2. initializing variables in constructor has different compile errors, need to fight all them, trying to understand why they happened, still fighting ...
  3. I've used pointer because without pointer I had compile errors, still trying to understand why and still fighting with them ...

Copy link
Member Author

@cogutvalera cogutvalera Aug 26, 2018

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 !

Copy link
Member Author

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

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

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

Copy link
Member Author

Choose a reason for hiding this comment

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

will do it soon

Copy link
Member Author

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

@cogutvalera
Copy link
Member Author

cogutvalera commented Aug 27, 2018

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 !

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.

Looks much better now. Thanks!


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

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.

Copy link
Member Author

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 !

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

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.

Copy link
Member Author

@cogutvalera cogutvalera Aug 27, 2018

Choose a reason for hiding this comment

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

ok sure !

std::vector<std::string> nathan_keys;

cli_fixture() :
server_port_number(0),
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok sure !

abitmore
abitmore previously approved these changes Aug 27, 2018
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.

Looks good to me so far. Waiting for CI reports.

@cogutvalera
Copy link
Member Author

Thank you !

@abitmore
Copy link
Member

abitmore commented Aug 27, 2018

@oxarbitrage @jmjatlanta @pmconrad your opinions?

@oxarbitrage
Copy link
Member

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 createaccount and add the 3 things there. then we can invoke this new test after upgrade_nathan_account.

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.

@cogutvalera
Copy link
Member Author

cogutvalera commented Aug 28, 2018

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

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?

Copy link
Member Author

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

BOOST_CHECK_EQUAL(201, history.size() );

what are your thoughts ? Thanks !

Copy link
Member

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.

@pmconrad
Copy link
Contributor

Looks good, but haven't checked in depth.

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 too, should be easier to add more tests here with the new framework. thanks.

@cogutvalera
Copy link
Member Author

Thank you guys !

@abitmore abitmore merged commit 0ad21dc into bitshares:develop Aug 29, 2018
@cogutvalera
Copy link
Member Author

Thanks for merge !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2e Ready for Testing Status indicating the solution is sufficiently developed to begin testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants