Updated CLI Tests [Issue 436]

This commit is contained in:
Meheboob Khan 2022-10-11 00:13:04 +00:00 committed by serkixenos
parent 0856e898bb
commit 846366139f
6 changed files with 670 additions and 94 deletions

View file

@ -1906,10 +1906,10 @@ map<son_id_type, string> database_api_impl::get_son_network_status_by_sidechain(
string status;
if (sso.last_active_timestamp.find(sidechain) != sso.last_active_timestamp.end()) {
if (sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) {
if (time_point_sec(sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_heartbeat_frequency())) > _db.head_block_time()) {
status = "OK, regular SON heartbeat";
} else {
if (sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) {
if (time_point_sec(sso.last_active_timestamp.at(sidechain) + fc::seconds(gpo.parameters.son_down_time())) > _db.head_block_time()) {
status = "OK, irregular SON heartbeat, but not triggering SON down proposal";
} else {
status = "NOT OK, irregular SON heartbeat, triggering SON down proposal]";

View file

@ -1493,13 +1493,6 @@ class wallet_api
*/
map<string, son_id_type> list_sons(const string& lowerbound, uint32_t limit);
/** Lists active at the moment SONs.
* This returns a list of all account names that own active SON, and the associated SON id,
* sorted by name.
* @returns a list of active SONs mapping SON names to SON ids
*/
map<string, son_id_type> list_active_sons();
/**
* @brief Get list of active sons
* @return List of active SONs
@ -2741,7 +2734,6 @@ FC_API( graphene::wallet::wallet_api,
(update_son_vesting_balances)
(activate_deregistered_son)
(list_sons)
(list_active_sons)
(get_active_sons)
(get_active_sons_by_sidechain)
(get_son_network_status)

View file

@ -2230,50 +2230,6 @@ public:
return sign_transaction( tx, broadcast );
} FC_CAPTURE_AND_RETHROW( (owner_account) ) }
//! Fixme - do we need to specify sidechain_type as params here?
map<string, son_id_type> list_active_sons()
{
try
{
const global_property_object& gpo = get_global_properties();
set<son_id_type> son_ids_set;
for(const auto& active_sidechain_type : active_sidechain_types)
{
std::transform(gpo.active_sons.at(active_sidechain_type).cbegin(), gpo.active_sons.at(active_sidechain_type).cend(),
std::inserter(son_ids_set, son_ids_set.end()),
[](const son_info &swi) {
return swi.son_id;
});
}
vector<son_id_type> son_ids;
son_ids.reserve(son_ids_set.size());
for(const auto& son_id : son_ids_set)
{
son_ids.emplace_back(son_id);
}
std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(son_ids);
vector<std::string> owners;
for(auto obj: son_objects)
{
std::string acc_id = account_id_to_string(obj->son_account);
owners.push_back(acc_id);
}
vector< optional< account_object> > accs = _remote_db->get_accounts(owners);
std::remove_if(son_objects.begin(), son_objects.end(),
[](const fc::optional<son_object>& obj) -> bool { return obj.valid(); });
map<string, son_id_type> result;
std::transform(accs.begin(), accs.end(), son_objects.begin(),
std::inserter(result, result.end()),
[](fc::optional<account_object>& acct, fc::optional<son_object> son) {
FC_ASSERT(acct, "Invalid active SONs list in global properties.");
return std::make_pair<string, son_id_type>(string(acct->name), std::move(son->id));
});
return result;
}
FC_CAPTURE_AND_RETHROW()
}
flat_map<sidechain_type, vector<son_info>> get_active_sons()
{ try {
return _remote_db->get_active_sons();
@ -5276,11 +5232,6 @@ map<string, son_id_type> wallet_api::list_sons(const string& lowerbound, uint32_
return my->_remote_db->lookup_son_accounts(lowerbound, limit);
}
map<string, son_id_type> wallet_api::list_active_sons()
{
return my->list_active_sons();
}
flat_map<sidechain_type, vector<son_info>> wallet_api::get_active_sons()
{
return my->get_active_sons();

View file

@ -231,6 +231,12 @@ signed_block cli_fixture::generate_block(uint32_t skip, const fc::ecc::private_k
return block;
}
void cli_fixture::generate_blocks( uint32_t block_count )
{
for( uint32_t i = 0; i < block_count; ++i )
generate_block();
}
bool cli_fixture::generate_maintenance_block() {
try {
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key")));

View file

@ -65,6 +65,7 @@ struct cli_fixture
int miss_blocks = 0);
void generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks = true, uint32_t skip = ~0);
void generate_blocks( uint32_t block_count );
///////////
/// @brief Skip intermediate blocks, and generate a maintenance block

View file

@ -863,9 +863,9 @@ BOOST_AUTO_TEST_CASE( related_functions )
BOOST_TEST_MESSAGE("SON-related functions cli wallet tests end");
}
BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
BOOST_FIXTURE_TEST_CASE( get_active_sons, cli_fixture )
{
BOOST_TEST_MESSAGE("SON cli wallet tests for list_active_sons begin");
BOOST_TEST_MESSAGE("SON cli wallet tests for get_active_sons begin");
try
{
son_test_helper sth(*this);
@ -874,12 +874,16 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
global_property_object gpo;
gpo = con.wallet_api_ptr->get_global_properties();
//! Set son number as 5 (as the begining son count)
unsigned int son_number = 5;
unsigned int son_number = 15; //gpo.parameters.maximum_son_count();
flat_map<sidechain_type, string> sidechain_public_keys;
BOOST_TEST_MESSAGE("Verify that there are no sons");
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::bitcoin).size());
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::hive).size());
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::ethereum).size());
auto gpo_active_sons = gpo.active_sons;
// create son accounts
BOOST_TEST_MESSAGE("Create son accounts");
for(unsigned int i = 1; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
@ -895,50 +899,674 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
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());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 1; i < son_number + 1; i++)
{
std::string name = "sonaccount" + fc::to_pretty_string(i);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name, sidechain_type::ethereum, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo_active_sons = gpo.active_sons;
auto cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
for(unsigned int i = 1; i < son_number; i++)
BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 5; i < son_number - 1; 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, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name1, name2, sidechain_type::ethereum, true, true);
std::string name = "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(name, name2, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_TEST_MESSAGE("gpo active_sons[bitcoin]: " << gpo.active_sons.at(sidechain_type::bitcoin).size());
BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::hive).size());
BOOST_TEST_MESSAGE("gpo active_sons[hive]: " << gpo.active_sons.at(sidechain_type::ethereum).size());
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
BOOST_CHECK(gpo.active_sons.at(sidechain_type::bitcoin).size() == son_number);
BOOST_CHECK(gpo.active_sons.at(sidechain_type::hive).size() == son_number);
BOOST_CHECK(gpo.active_sons.at(sidechain_type::ethereum).size() == son_number);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
map<string, son_id_type> active_sons = con.wallet_api_ptr->list_active_sons();
BOOST_CHECK(active_sons.size() == son_number);
for(unsigned int i = 1; i < son_number + 1; i++)
BOOST_TEST_MESSAGE("Unvoting for Specific SON");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::ethereum, false, true);
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
BOOST_TEST_MESSAGE("Unvoting for Specific SON in Specific Sidechain");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount6", "sonaccount7", sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount7", "sonaccount8", sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount8", "sonaccount9", sidechain_type::ethereum, false, true);
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
BOOST_TEST_MESSAGE("Unvoting for all SONs");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount6", "sonaccount7", sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount7", "sonaccount8", sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount8", "sonaccount9", sidechain_type::ethereum, true, true);
BOOST_CHECK(generate_maintenance_block());
for(unsigned int i = 6; i < son_number - 1; i++)
{
std::string name = "sonaccount" + fc::to_pretty_string(i);
BOOST_CHECK(active_sons.find(name) != active_sons.end());
std::string name = "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(name, name2, sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, false, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->get_active_sons());
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons());
} catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
edump((e.to_detail_string()));
throw;
}
BOOST_TEST_MESSAGE("SON cli wallet tests for list_active_sons end");
BOOST_TEST_MESSAGE("SON cli wallet tests for get_active_sons end");
}
BOOST_FIXTURE_TEST_CASE( get_active_sons_by_sidechain, cli_fixture )
{
BOOST_TEST_MESSAGE("SON cli wallet tests for get_active_sons_by_sidechain begin");
try
{
son_test_helper sth(*this);
signed_transaction vote_tx;
global_property_object gpo;
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = 15;
flat_map<sidechain_type, string> sidechain_public_keys;
BOOST_TEST_MESSAGE("Verify that there are no sons");
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::bitcoin).size());
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::hive).size());
BOOST_CHECK(0 == gpo.active_sons.at(sidechain_type::ethereum).size());
auto gpo_active_sons = gpo.active_sons;
// create son accounts
BOOST_TEST_MESSAGE("Create son accounts");
for(unsigned int i = 1; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
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::ethereum] = "ethereum address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,
false);
con.wallet_api_ptr->transfer(
"nathan", "sonaccount" + fc::to_pretty_string(i), "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);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
auto cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
auto cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 5; i < son_number - 1; i++)
{
std::string name = "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(name, name2, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_TEST_MESSAGE("Unvoting for Specific SON");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount5", "sonaccount6", sidechain_type::ethereum, false, true);
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_TEST_MESSAGE("Unvoting for Specific SON in Specific Sidechain");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount6", "sonaccount7", sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount7", "sonaccount8", sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount8", "sonaccount9", sidechain_type::ethereum, false, true);
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_TEST_MESSAGE("Unvoting for all SONs");
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount6", "sonaccount7", sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount7", "sonaccount8", sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son("sonaccount8", "sonaccount9", sidechain_type::ethereum, true, true);
BOOST_CHECK(generate_maintenance_block());
for(unsigned int i = 6; i < son_number - 1; i++)
{
std::string name = "sonaccount" + fc::to_pretty_string(i);
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 1);
if(i == 6)
{
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, false, true);
}
else if(i == 7)
{
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, false, true);
}
else if(i == 8)
{
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, false, true);
}
else{
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::bitcoin, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, false, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, false, true);
}
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
BOOST_CHECK(gpo.active_sons != gpo_active_sons);
gpo_active_sons = gpo.active_sons;
cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->get_active_sons_by_sidechain(sidechain_type::bitcoin));
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->get_active_sons_by_sidechain(sidechain_type::hive));
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->get_active_sons_by_sidechain(sidechain_type::ethereum));
} catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
edump((e.to_detail_string()));
throw;
}
BOOST_TEST_MESSAGE("SON cli wallet tests for get_active_sons_by_sidechain end");
}
BOOST_FIXTURE_TEST_CASE( get_son_network_status, cli_fixture )
{
BOOST_TEST_MESSAGE("SON get_son_network_status cli wallet tests begin");
try
{
son_test_helper sth(*this);
auto db = app1->chain_database();
signed_transaction vote_tx;
global_property_object gpo;
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count();
BOOST_TEST_MESSAGE("son_number"<<son_number);
flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts
for(unsigned int i = 1; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
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::ethereum] = "ethereum address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,
false);
con.wallet_api_ptr->transfer(
"nathan", "sonaccount" + fc::to_pretty_string(i), "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);
}
BOOST_CHECK(generate_maintenance_block());
auto network_status_obj = con.wallet_api_ptr->get_son_network_status();
for(map<sidechain_type, map<son_id_type, string>>::iterator outer_iter=network_status_obj.begin(); outer_iter!=network_status_obj.end(); ++outer_iter)
{
for(map<son_id_type, string>::iterator inner_iter=outer_iter->second.begin(); inner_iter!=outer_iter->second.end(); ++inner_iter)
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "No heartbeats sent");
}
}
BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 1; i < son_number-1; i++)
{
std::string name = "sonaccount" + fc::to_pretty_string(i);
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 2);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
auto gpo_active_sons = gpo.active_sons;
auto cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
BOOST_TEST_MESSAGE("Sending Heartbeat for sonaccount3");
son_object son_obj1 = con.wallet_api_ptr->get_son("sonaccount3");
signed_transaction trx1;
son_heartbeat_operation op1;
op1.owner_account = son_obj1.son_account;
op1.son_id = son_obj1.id;
op1.ts = db->head_block_time()+fc::seconds(2*db->block_interval());
trx1.operations.push_back(op1);
con.wallet_api_ptr->sign_transaction(trx1, true);
generate_blocks(50);
BOOST_TEST_MESSAGE("Checking Network Status");
network_status_obj = con.wallet_api_ptr->get_son_network_status();
for(map<sidechain_type, map<son_id_type, string>>::iterator outer_iter=network_status_obj.begin(); outer_iter!=network_status_obj.end(); ++outer_iter)
{
for(map<son_id_type, string>::iterator inner_iter=outer_iter->second.begin(); inner_iter!=outer_iter->second.end(); ++inner_iter)
{
if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "OK, regular SON heartbeat");
}
else{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "No heartbeats sent");
}
}
}
BOOST_TEST_MESSAGE("Sending Heartbeat for sonaccount4");
son_object son_obj2 = con.wallet_api_ptr->get_son("sonaccount4");
signed_transaction trx2;
son_heartbeat_operation op2;
op2.owner_account = son_obj2.son_account;
op2.son_id = son_obj2.id;
op2.ts = db->head_block_time()+fc::seconds(2*db->block_interval());
trx2.operations.push_back(op2);
con.wallet_api_ptr->sign_transaction(trx2, true);
generate_blocks(50);
BOOST_TEST_MESSAGE("Checking Network Status");
network_status_obj = con.wallet_api_ptr->get_son_network_status();
for(map<sidechain_type, map<son_id_type, string>>::iterator outer_iter=network_status_obj.begin(); outer_iter!=network_status_obj.end(); ++outer_iter)
{
for(map<son_id_type, string>::iterator inner_iter=outer_iter->second.begin(); inner_iter!=outer_iter->second.end(); ++inner_iter)
{
if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "OK, irregular SON heartbeat, but not triggering SON down proposal");
}
else if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "OK, regular SON heartbeat");
}
else{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "No heartbeats sent");
}
}
}
generate_blocks(db->head_block_time() + gpo.parameters.son_heartbeat_frequency(), false);
BOOST_TEST_MESSAGE("Checking Network Status");
network_status_obj = con.wallet_api_ptr->get_son_network_status();
for(map<sidechain_type, map<son_id_type, string>>::iterator outer_iter=network_status_obj.begin(); outer_iter!=network_status_obj.end(); ++outer_iter)
{
for(map<son_id_type, string>::iterator inner_iter=outer_iter->second.begin(); inner_iter!=outer_iter->second.end(); ++inner_iter)
{
if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "OK, irregular SON heartbeat, but not triggering SON down proposal");
}
else{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "No heartbeats sent");
}
}
}
generate_blocks(db->head_block_time() + gpo.parameters.son_heartbeat_frequency() + gpo.parameters.son_down_time(), false);
BOOST_TEST_MESSAGE("Checking Network Status");
network_status_obj = con.wallet_api_ptr->get_son_network_status();
for(map<sidechain_type, map<son_id_type, string>>::iterator outer_iter=network_status_obj.begin(); outer_iter!=network_status_obj.end(); ++outer_iter)
{
for(map<son_id_type, string>::iterator inner_iter=outer_iter->second.begin(); inner_iter!=outer_iter->second.end(); ++inner_iter)
{
if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else if((inner_iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(inner_iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else{
BOOST_TEST_MESSAGE("status: "<< inner_iter->second);
BOOST_CHECK(inner_iter->second == "No heartbeats sent");
}
}
}
} catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
edump((e.to_detail_string()));
throw;
}
BOOST_TEST_MESSAGE("SON get_son_network_status cli wallet tests end");
}
BOOST_FIXTURE_TEST_CASE( get_son_network_status_by_sidechain, cli_fixture )
{
BOOST_TEST_MESSAGE("SON get_son_network_status_by_sidechain cli wallet tests begin");
try
{
son_test_helper sth(*this);
signed_transaction vote_tx;
auto db = app1->chain_database();
global_property_object gpo;
gpo = con.wallet_api_ptr->get_global_properties();
unsigned int son_number = gpo.parameters.maximum_son_count();
BOOST_TEST_MESSAGE("son_number"<<son_number);
flat_map<sidechain_type, string> sidechain_public_keys;
// create son accounts
for(unsigned int i = 1; i < son_number + 1; i++)
{
sidechain_public_keys.clear();
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::ethereum] = "ethereum address " + fc::to_pretty_string(i);
sth.create_son("sonaccount" + fc::to_pretty_string(i),
"http://son" + fc::to_pretty_string(i),
sidechain_public_keys,
false);
con.wallet_api_ptr->transfer(
"nathan", "sonaccount" + fc::to_pretty_string(i), "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);
}
// Check Network Status Before sending Heartbeats
BOOST_CHECK(generate_maintenance_block());
for(sidechain_type sidechain:active_sidechain_types)
{
auto network_status_obj = con.wallet_api_ptr->get_son_network_status_by_sidechain(sidechain);
for(map<son_id_type, string>::iterator iter=network_status_obj.begin(); iter!=network_status_obj.end(); ++iter)
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "No heartbeats sent");
}
}
BOOST_TEST_MESSAGE("Voting for SONs");
for(unsigned int i = 1; i < son_number-1; i++)
{
std::string name = "sonaccount" + fc::to_pretty_string(i);
std::string name2 = "sonaccount" + fc::to_pretty_string(i + 2);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::bitcoin, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::hive, true, true);
vote_tx = con.wallet_api_ptr->vote_for_son(name, name2, sidechain_type::ethereum, true, true);
}
BOOST_CHECK(generate_maintenance_block());
gpo = con.wallet_api_ptr->get_global_properties();
auto gpo_active_sons = gpo.active_sons;
auto cmd_active_sons = con.wallet_api_ptr->get_active_sons();
BOOST_CHECK(gpo_active_sons == cmd_active_sons);
auto cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::bitcoin));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::bitcoin) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::ethereum));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::ethereum) == cmd_active_sons2);
cmd_active_sons2 = con.wallet_api_ptr->get_active_sons_by_sidechain((sidechain_type::hive));
BOOST_CHECK(gpo_active_sons.at(sidechain_type::hive) == cmd_active_sons2);
BOOST_TEST_MESSAGE("Sending Heartbeat for sonaccount3");
son_object son_obj1 = con.wallet_api_ptr->get_son("sonaccount3");
signed_transaction trx1;
son_heartbeat_operation op1;
op1.owner_account = son_obj1.son_account;
op1.son_id = son_obj1.id;
op1.ts = db->head_block_time()+fc::seconds(2*db->block_interval());
trx1.operations.push_back(op1);
con.wallet_api_ptr->sign_transaction(trx1, true);
generate_blocks(50);
BOOST_TEST_MESSAGE("Checking Network Status");
for(sidechain_type sidechain:active_sidechain_types)
{
auto network_status_obj = con.wallet_api_ptr->get_son_network_status_by_sidechain(sidechain);
for(map<son_id_type, string>::iterator iter=network_status_obj.begin(); iter!=network_status_obj.end(); ++iter)
{
if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "OK, regular SON heartbeat");
}
else{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "No heartbeats sent");
}
}
}
BOOST_TEST_MESSAGE("Sending Heartbeat for sonaccount4");
son_object son_obj2 = con.wallet_api_ptr->get_son("sonaccount4");
signed_transaction trx2;
son_heartbeat_operation op2;
op2.owner_account = son_obj2.son_account;
op2.son_id = son_obj2.id;
op2.ts = db->head_block_time()+fc::seconds(2*db->block_interval());
trx2.operations.push_back(op2);
con.wallet_api_ptr->sign_transaction(trx2, true);
generate_blocks(50);
for(sidechain_type sidechain:active_sidechain_types)
{
auto network_status_obj = con.wallet_api_ptr->get_son_network_status_by_sidechain(sidechain);
for(map<son_id_type, string>::iterator iter=network_status_obj.begin(); iter!=network_status_obj.end(); ++iter)
{
if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "OK, irregular SON heartbeat, but not triggering SON down proposal");
}
else if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "OK, regular SON heartbeat");
}
else{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "No heartbeats sent");
}
}
}
generate_blocks(db->head_block_time() + gpo.parameters.son_heartbeat_frequency(), false);
BOOST_TEST_MESSAGE("Checking Network Status");
for(sidechain_type sidechain:active_sidechain_types)
{
auto network_status_obj = con.wallet_api_ptr->get_son_network_status_by_sidechain(sidechain);
for(map<son_id_type, string>::iterator iter=network_status_obj.begin(); iter!=network_status_obj.end(); ++iter)
{
if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "OK, irregular SON heartbeat, but not triggering SON down proposal");
}
else{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "No heartbeats sent");
}
}
}
generate_blocks(db->head_block_time() + gpo.parameters.son_heartbeat_frequency() + gpo.parameters.son_down_time(), false);;
BOOST_TEST_MESSAGE("Checking Network Status");
for(sidechain_type sidechain:active_sidechain_types)
{
auto network_status_obj = con.wallet_api_ptr->get_son_network_status_by_sidechain(sidechain);
for(map<son_id_type, string>::iterator iter=network_status_obj.begin(); iter!=network_status_obj.end(); ++iter)
{
if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(0).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(0).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else if((iter->first == gpo.active_sons.at(sidechain_type::bitcoin).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::hive).at(1).son_id) &&
(iter->first == gpo.active_sons.at(sidechain_type::ethereum).at(1).son_id))
{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "NOT OK, irregular SON heartbeat, triggering SON down proposal]");
}
else{
BOOST_TEST_MESSAGE("status: "<< iter->second);
BOOST_CHECK(iter->second == "No heartbeats sent");
}
}
}
} catch( fc::exception& e ) {
BOOST_TEST_MESSAGE("SON cli wallet tests exception");
edump((e.to_detail_string()));
throw;
}
BOOST_TEST_MESSAGE("SON get_son_network_status_by_sidechain cli wallet tests end");
}
BOOST_AUTO_TEST_CASE( maintenance_test )
@ -1036,5 +1664,3 @@ BOOST_AUTO_TEST_CASE( maintenance_test )
BOOST_AUTO_TEST_SUITE_END()