Compare commits
4 commits
master
...
feature/SO
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
de842e1218 | ||
|
|
c1208b36f6 | ||
|
|
ff09c75734 | ||
|
|
2502207561 |
3 changed files with 36 additions and 11 deletions
|
|
@ -171,15 +171,22 @@ void account_options::validate() const
|
|||
{
|
||||
auto needed_witnesses = num_witness;
|
||||
auto needed_committee = num_committee;
|
||||
auto needed_sons = num_son;
|
||||
|
||||
for( vote_id_type id : votes )
|
||||
if( id.type() == vote_id_type::witness && needed_witnesses )
|
||||
--needed_witnesses;
|
||||
else if ( id.type() == vote_id_type::committee && needed_committee )
|
||||
--needed_committee;
|
||||
else if ( id.type() == vote_id_type::son && needed_sons )
|
||||
--needed_sons;
|
||||
|
||||
FC_ASSERT( needed_witnesses == 0 && needed_committee == 0,
|
||||
"May not specify fewer witnesses or committee members than the number voted for.");
|
||||
FC_ASSERT( needed_witnesses == 0,
|
||||
"May not specify fewer witnesses than the number voted for.");
|
||||
FC_ASSERT( needed_committee == 0,
|
||||
"May not specify fewer committee members than the number voted for.");
|
||||
FC_ASSERT( needed_sons == 0,
|
||||
"May not specify fewer SONs than the number voted for.");
|
||||
}
|
||||
|
||||
void affiliate_reward_distribution::validate() const
|
||||
|
|
|
|||
|
|
@ -2272,26 +2272,27 @@ public:
|
|||
uint16_t desired_number_of_sons,
|
||||
bool broadcast /* = false */)
|
||||
{ try {
|
||||
FC_ASSERT(sons_to_approve.size() || sons_to_reject.size(), "Both accepted and rejected lists can't be empty simultaneously");
|
||||
account_object voting_account_object = get_account(voting_account);
|
||||
for (const std::string& son : sons_to_approve)
|
||||
{
|
||||
account_id_type son_owner_account_id = get_account_id(son);
|
||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
|
||||
if (!son_obj)
|
||||
FC_THROW("Account ${son} is not registered as a witness", ("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);
|
||||
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));
|
||||
}
|
||||
for (const std::string& son : sons_to_reject)
|
||||
{
|
||||
account_id_type son_owner_account_id = get_account_id(son);
|
||||
fc::optional<son_object> son_obj = _remote_db->get_son_by_account(son_owner_account_id);
|
||||
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));
|
||||
unsigned votes_removed = voting_account_object.options.votes.erase(son_obj->vote_id);
|
||||
if (!votes_removed)
|
||||
FC_THROW("Account ${account} is already not voting for son ${son}", ("account", voting_account)("son", son));
|
||||
FC_THROW("Account ${account} is already not voting for SON ${son}", ("account", voting_account)("son", son));
|
||||
}
|
||||
voting_account_object.options.num_son = desired_number_of_sons;
|
||||
|
||||
|
|
|
|||
|
|
@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
accepted.push_back("son1account");
|
||||
accepted.push_back("son2account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
rejected, 2, true);
|
||||
BOOST_CHECK(generate_block());
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
|
|
@ -412,7 +412,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
rejected.clear();
|
||||
rejected.push_back("son1account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
rejected, 1, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
|
|
@ -431,7 +431,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
rejected.clear();
|
||||
rejected.push_back("son1accnt");
|
||||
BOOST_CHECK_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true), fc::exception);
|
||||
rejected, 1, true), fc::exception);
|
||||
BOOST_CHECK(generate_block());
|
||||
|
||||
// Verify the votes
|
||||
|
|
@ -449,7 +449,7 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
rejected.clear();
|
||||
rejected.push_back("son2account");
|
||||
update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true);
|
||||
rejected, 0, true);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
|
|
@ -468,7 +468,24 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
rejected.push_back("son1accnt");
|
||||
accepted.push_back("son1accnt");
|
||||
BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 15, true), fc::exception);
|
||||
rejected, 1, true), fc::exception);
|
||||
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;
|
||||
|
||||
// Try to accept and reject empty lists
|
||||
accepted.clear();
|
||||
rejected.clear();
|
||||
BOOST_REQUIRE_THROW(update_votes_tx = con.wallet_api_ptr->update_son_votes("nathan", accepted,
|
||||
rejected, 1, true), fc::exception);
|
||||
BOOST_CHECK(generate_maintenance_block());
|
||||
|
||||
// Verify the votes
|
||||
|
|
|
|||
Loading…
Reference in a new issue