Compare commits

...

2 commits

Author SHA1 Message Date
gladcow
7134b68112 prevent exception in list_active_list 2020-02-21 16:14:11 +03:00
gladcow
8cdd3af59d test to reproduce error in list_active_sons after delete_son 2020-02-21 16:14:11 +03:00
2 changed files with 15 additions and 9 deletions

View file

@ -1988,19 +1988,22 @@ public:
}); });
std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(son_ids); std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(son_ids);
vector<account_id_type> owners; vector<account_id_type> owners;
owners.resize(son_objects.size()); for(auto obj: son_objects)
std::transform(son_objects.begin(), son_objects.end(), owners.begin(), {
[](const fc::optional<son_object>& obj) { if (obj)
FC_ASSERT(obj, "Invalid active SONs list in global properties."); owners.push_back(obj->son_account);
return obj->son_account; }
});
vector<fc::optional<account_object>> accs = _remote_db->get_accounts(owners); vector<fc::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; map<string, son_id_type> result;
std::transform(accs.begin(), accs.end(), son_ids.begin(), std::transform(accs.begin(), accs.end(), son_objects.begin(),
std::inserter(result, result.end()), std::inserter(result, result.end()),
[](fc::optional<account_object>& acct, son_id_type& sid) { [](fc::optional<account_object>& acct, fc::optional<son_object> son) {
FC_ASSERT(acct, "Invalid active SONs list in global properties."); FC_ASSERT(acct, "Invalid active SONs list in global properties.");
return std::make_pair<string, son_id_type>(string(acct->name), std::move(sid)); if (son.valid())
return std::make_pair<string, son_id_type>(string(acct->name), std::move(son->id));
return std::make_pair<string, son_id_type>(string(acct->name), std::move(son_id_type()));
}); });
return result; return result;
} FC_CAPTURE_AND_RETHROW() } } FC_CAPTURE_AND_RETHROW() }

View file

@ -650,6 +650,9 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture )
BOOST_CHECK(active_sons.find(name) != active_sons.end()); BOOST_CHECK(active_sons.find(name) != active_sons.end());
} }
// check list_active_son after SON deletion
con.wallet_api_ptr->delete_son("sonaccount1", true);
BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons());
} 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()));