Add more debug messages to failing test

This commit is contained in:
serkixenos 2022-08-30 00:43:46 +02:00
parent 27c8126b3f
commit 2871da5d4b
2 changed files with 164 additions and 158 deletions

View file

@ -2860,7 +2860,6 @@ public:
if (!son_obj) if (!son_obj)
FC_THROW("Account ${son} is not registered as a SON", ("son", son)); FC_THROW("Account ${son} is not registered as a SON", ("son", son));
auto insert_result = voting_account_object.options.votes.insert(son_obj->vote_id); auto insert_result = voting_account_object.options.votes.insert(son_obj->vote_id);
if (!insert_result.second) if (!insert_result.second)
FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son)); FC_THROW("Account ${account} was already voting for SON ${son}", ("account", voting_account)("son", son));
} }

View file

@ -215,6 +215,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sidechain_public_keys[sidechain_type::hive] = "hive account 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys); sth.create_son("son2account", "http://son2", sidechain_public_keys);
BOOST_CHECK(generate_maintenance_block());
BOOST_TEST_MESSAGE("Voting for SONs"); BOOST_TEST_MESSAGE("Voting for SONs");
son_object son1_obj; son_object son1_obj;
@ -232,7 +234,6 @@ BOOST_AUTO_TEST_CASE( son_voting )
con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true); con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true);
// Vote for a son1account // Vote for a son1account
BOOST_TEST_MESSAGE("Voting for son1account"); BOOST_TEST_MESSAGE("Voting for son1account");
BOOST_CHECK(generate_maintenance_block());
vote_son1_tx = con.wallet_api_ptr->vote_for_son("nathan", "son1account", true, true); vote_son1_tx = con.wallet_api_ptr->vote_for_son("nathan", "son1account", true, true);
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
@ -446,9 +447,9 @@ BOOST_AUTO_TEST_CASE( list_son )
BOOST_AUTO_TEST_CASE( update_son_votes_test ) BOOST_AUTO_TEST_CASE( update_son_votes_test )
{ {
BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests begin"); BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests begin");
try try
{ {
flat_map<sidechain_type, string> sidechain_public_keys; flat_map<sidechain_type, string> sidechain_public_keys;
son_test_helper sth(*this); son_test_helper sth(*this);
@ -463,151 +464,146 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
sidechain_public_keys[sidechain_type::hive] = "hive account 2"; sidechain_public_keys[sidechain_type::hive] = "hive account 2";
sth.create_son("son2account", "http://son2", sidechain_public_keys); sth.create_son("son2account", "http://son2", sidechain_public_keys);
son_object son1_obj; BOOST_CHECK(generate_maintenance_block());
son_object son2_obj;
uint64_t son1_start_votes, son1_end_votes;
uint64_t son2_start_votes, son2_end_votes;
// Get votes at start BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes");
son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_start_votes = son1_obj.total_votes;
BOOST_TEST_MESSAGE("son1_start_votes: " << son1_start_votes);
son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_start_votes = son2_obj.total_votes;
BOOST_TEST_MESSAGE("son2_start_votes: " << son2_start_votes);
std::vector<std::string> accepted; son_object son1_obj;
std::vector<std::string> rejected; son_object son2_obj;
signed_transaction update_votes_tx; uint64_t son1_start_votes, son1_end_votes;
uint64_t son2_start_votes, son2_end_votes;
generate_block(); // Get votes at start
BOOST_CHECK(generate_maintenance_block()); son1_obj = con.wallet_api_ptr->get_son("son1account");
BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes"); son1_start_votes = son1_obj.total_votes;
// Vote for both SONs son2_obj = con.wallet_api_ptr->get_son("son2account");
accepted.clear(); son2_start_votes = son2_obj.total_votes;
rejected.clear();
accepted.push_back("son1account");
accepted.push_back("son2account");
con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true);
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 2, true);
generate_block();
BOOST_CHECK(generate_maintenance_block());
// Verify the votes std::vector<std::string> accepted;
son1_obj = con.wallet_api_ptr->get_son("son1account"); std::vector<std::string> rejected;
son1_end_votes = son1_obj.total_votes; signed_transaction update_votes_tx;
BOOST_TEST_MESSAGE("son1_end_votes: " << son1_end_votes);
BOOST_CHECK(son1_end_votes > son1_start_votes); // Vote for both SONs
son1_start_votes = son1_end_votes; accepted.clear();
son2_obj = con.wallet_api_ptr->get_son("son2account"); rejected.clear();
son2_end_votes = son2_obj.total_votes; accepted.push_back("son1account");
BOOST_TEST_MESSAGE("son2_end_votes: " << son2_end_votes); accepted.push_back("son2account");
BOOST_CHECK(son2_end_votes > son2_start_votes); con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true);
son2_start_votes = son2_end_votes; update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 2, true);
generate_block();
BOOST_CHECK(generate_maintenance_block());
// Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes;
BOOST_CHECK(son1_end_votes > son1_start_votes);
son1_start_votes = son1_end_votes;
son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes > son2_start_votes);
son2_start_votes = son2_end_votes;
// Withdraw vote for SON 1 // Withdraw vote for SON 1
accepted.clear(); accepted.clear();
rejected.clear(); rejected.clear();
rejected.push_back("son1account"); rejected.push_back("son1account");
con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true); con.wallet_api_ptr->create_vesting_balance("nathan", "1000", "1.3.0", vesting_balance_type::gpos, true);
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 1, true); rejected, 1, true);
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
// Verify the votes // Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes; son1_end_votes = son1_obj.total_votes;
BOOST_TEST_MESSAGE("son1_end_votes: " << son1_end_votes); BOOST_CHECK(son1_end_votes < son1_start_votes);
BOOST_CHECK(son1_end_votes < son1_start_votes); son1_start_votes = son1_end_votes;
son1_start_votes = son1_end_votes; son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_obj = con.wallet_api_ptr->get_son("son2account");
// voice distribution changed, SON2 now has all voices // voice distribution changed, SON2 now has all voices
son2_end_votes = son2_obj.total_votes; son2_end_votes = son2_obj.total_votes;
BOOST_TEST_MESSAGE("son2_end_votes: " << son2_end_votes); BOOST_CHECK((son2_end_votes > son2_start_votes)); // nathan spent funds for vb, it has different voting power
BOOST_CHECK((son2_end_votes > son2_start_votes)); // nathan spent funds for vb, it has different voting power son2_start_votes = son2_end_votes;
son2_start_votes = son2_end_votes;
// Try to reject incorrect SON // Try to reject incorrect SON
accepted.clear(); accepted.clear();
rejected.clear(); rejected.clear();
rejected.push_back("son1accnt"); rejected.push_back("son1accnt");
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 1, true), fc::exception); rejected, 1, true), fc::exception);
generate_block(); generate_block();
// Verify the votes // Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes; son1_end_votes = son1_obj.total_votes;
BOOST_CHECK(son1_end_votes == son1_start_votes); BOOST_CHECK(son1_end_votes == son1_start_votes);
son1_start_votes = son1_end_votes; son1_start_votes = son1_end_votes;
son2_obj = con.wallet_api_ptr->get_son("son2account"); son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_end_votes = son2_obj.total_votes; son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes == son2_start_votes); BOOST_CHECK(son2_end_votes == son2_start_votes);
son2_start_votes = son2_end_votes; son2_start_votes = son2_end_votes;
// Reject SON2 // Reject SON2
accepted.clear(); accepted.clear();
rejected.clear(); rejected.clear();
rejected.push_back("son2account"); rejected.push_back("son2account");
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 0, true); rejected, 0, true);
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
// Verify the votes // Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes; son1_end_votes = son1_obj.total_votes;
BOOST_CHECK(son1_end_votes == son1_start_votes); BOOST_CHECK(son1_end_votes == son1_start_votes);
son1_start_votes = son1_end_votes; son1_start_votes = son1_end_votes;
son2_obj = con.wallet_api_ptr->get_son("son2account"); son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_end_votes = son2_obj.total_votes; son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes < son2_start_votes); BOOST_CHECK(son2_end_votes < son2_start_votes);
son2_start_votes = son2_end_votes; son2_start_votes = son2_end_votes;
// Try to accept and reject the same SON // Try to accept and reject the same SON
accepted.clear(); accepted.clear();
rejected.clear(); rejected.clear();
rejected.push_back("son1account"); rejected.push_back("son1account");
accepted.push_back("son1account"); accepted.push_back("son1account");
BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 1, true), fc::exception); rejected, 1, true), fc::exception);
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
// Verify the votes // Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes; son1_end_votes = son1_obj.total_votes;
BOOST_CHECK(son1_end_votes == son1_start_votes); BOOST_CHECK(son1_end_votes == son1_start_votes);
son1_start_votes = son1_end_votes; son1_start_votes = son1_end_votes;
son2_obj = con.wallet_api_ptr->get_son("son2account"); son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_end_votes = son2_obj.total_votes; son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes == son2_start_votes); BOOST_CHECK(son2_end_votes == son2_start_votes);
son2_start_votes = son2_end_votes; son2_start_votes = son2_end_votes;
// Try to accept and reject empty lists // Try to accept and reject empty lists
accepted.clear(); accepted.clear();
rejected.clear(); rejected.clear();
BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted, BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
rejected, 1, true), fc::exception); rejected, 1, true), fc::exception);
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
// Verify the votes // Verify the votes
son1_obj = con.wallet_api_ptr->get_son("son1account"); son1_obj = con.wallet_api_ptr->get_son("son1account");
son1_end_votes = son1_obj.total_votes; son1_end_votes = son1_obj.total_votes;
BOOST_CHECK(son1_end_votes == son1_start_votes); BOOST_CHECK(son1_end_votes == son1_start_votes);
son1_start_votes = son1_end_votes; son1_start_votes = son1_end_votes;
son2_obj = con.wallet_api_ptr->get_son("son2account"); son2_obj = con.wallet_api_ptr->get_son("son2account");
son2_end_votes = son2_obj.total_votes; son2_end_votes = son2_obj.total_votes;
BOOST_CHECK(son2_end_votes == son2_start_votes); BOOST_CHECK(son2_end_votes == son2_start_votes);
son2_start_votes = son2_end_votes; son2_start_votes = son2_end_votes;
} catch( fc::exception& e ) { } catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception"); BOOST_TEST_MESSAGE("SON cli wallet tests exception");
edump((e.to_detail_string())); edump((e.to_detail_string()));
throw; throw;
} }
BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests end"); BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests end");
} }
BOOST_AUTO_TEST_CASE( related_functions ) BOOST_AUTO_TEST_CASE( related_functions )
@ -660,47 +656,58 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
flat_map<sidechain_type, string> sidechain_public_keys; flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts // create son accounts
for(unsigned int i = 0; i < son_number + 1; i++) for(unsigned int i = 0; i < son_number * 2; i++)
{ {
sidechain_public_keys.clear(); sidechain_public_keys.clear();
sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i);
sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i); sidechain_public_keys[sidechain_type::hive] = "hive account " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i), sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i),
sidechain_public_keys, sidechain_public_keys,
false); false);
con.wallet_api_ptr->transfer( con.wallet_api_ptr->transfer("nathan", "sonaccount" + fc::to_pretty_string(i),
"nathan", "sonaccount" + fc::to_pretty_string(i), "1000", "1.3.0", "Here are some CORE tokens for your new account", true ); "1000", "1.3.0", "Here are some CORE tokens for your new account", true );
con.wallet_api_ptr->create_vesting_balance("sonaccount" + fc::to_pretty_string(i), "500", "1.3.0", vesting_balance_type::gpos, true); con.wallet_api_ptr->create_vesting_balance("sonaccount" + fc::to_pretty_string(i), "500", "1.3.0", vesting_balance_type::gpos, true);
} }
BOOST_CHECK(generate_maintenance_block()); generate_block();
BOOST_TEST_MESSAGE("Voting for SONs"); BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 1; i < son_number + 1; i++) for(unsigned int i = 0; i < son_number * 2; i++)
{ {
std::string name = "sonaccount" + fc::to_pretty_string(i); std::string name = "sonaccount" + fc::to_pretty_string(i);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, true, true); BOOST_TEST_MESSAGE("Account " + name + " votes for SON " + name);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, true, true);
} }
generate_block();
for(unsigned int i = 0; i < son_number; i++)
{
std::string name1 = "sonaccount" + fc::to_pretty_string(i);
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1);
BOOST_TEST_MESSAGE("Account " + name1 + " votes for SON " + name2);
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
}
generate_block();
BOOST_CHECK(generate_maintenance_block()); BOOST_CHECK(generate_maintenance_block());
for(unsigned int i = 1; i < son_number; i++)
{
std::string name1 = "sonaccount" + fc::to_pretty_string(i);
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1);
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties(); gpo = con.wallet_api_ptr->get_global_properties();
BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size()); BOOST_TEST_MESSAGE("gpo: " << gpo.active_sons.size());
BOOST_CHECK(gpo.active_sons.size() == son_number); BOOST_CHECK(gpo.active_sons.size() == son_number);
map<string, son_id_type> active_sons = con.wallet_api_ptr->list_active_sons(); map<string, son_id_type> active_sons = con.wallet_api_ptr->list_active_sons();
BOOST_TEST_MESSAGE("Active SONs:");
for (auto s : active_sons) {
BOOST_TEST_MESSAGE(" " + s.first);
}
BOOST_CHECK(active_sons.size() == son_number); BOOST_CHECK(active_sons.size() == son_number);
for(unsigned int i = 1; i < son_number; i++) for(unsigned int i = 1; i < son_number + 1; i++)
{ {
std::string name = "sonaccount" + fc::to_pretty_string(i); std::string name = "sonaccount" + fc::to_pretty_string(i);
BOOST_CHECK(active_sons.find(name) != active_sons.end()); BOOST_TEST_MESSAGE("Looking for SON name: " + name);
BOOST_CHECK(active_sons.find(name) != active_sons.end());
} }
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons()); BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons());