#328 - total_votes as map of sidechain_type
This commit is contained in:
parent
5c5116f3fc
commit
eec19a350b
3 changed files with 31 additions and 26 deletions
|
|
@ -716,11 +716,12 @@ void database::update_active_sons()
|
|||
});
|
||||
}
|
||||
modify( son, [local_vote_buffer_ref]( son_object& obj ){
|
||||
//! FIXME - only bitcoin_vote_id ???
|
||||
obj.total_votes = local_vote_buffer_ref[obj.get_bitcoin_vote_id()];
|
||||
if(obj.status == son_status::request_maintenance)
|
||||
obj.status = son_status::in_maintenance;
|
||||
});
|
||||
for(const auto& sidechain_vote_id : obj.sidechain_vote_ids ){
|
||||
obj.total_votes[sidechain_vote_id.first] = local_vote_buffer_ref[sidechain_vote_id.second];
|
||||
}
|
||||
if(obj.status == son_status::request_maintenance)
|
||||
obj.status = son_status::in_maintenance;
|
||||
});
|
||||
}
|
||||
|
||||
// Update SON authority
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ namespace graphene { namespace chain {
|
|||
|
||||
account_id_type son_account;
|
||||
flat_map<sidechain_type, vote_id_type> sidechain_vote_ids;
|
||||
uint64_t total_votes = 0;
|
||||
flat_map<sidechain_type, uint64_t> total_votes;
|
||||
string url;
|
||||
vesting_balance_id_type deposit;
|
||||
public_key_type signing_key;
|
||||
|
|
|
|||
|
|
@ -235,8 +235,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
son_object son2_obj;
|
||||
signed_transaction vote_son1_tx;
|
||||
signed_transaction vote_son2_tx;
|
||||
uint64_t son1_start_votes, son1_end_votes;
|
||||
uint64_t son2_start_votes, son2_end_votes;
|
||||
flat_map<sidechain_type, uint64_t> son1_start_votes, son1_end_votes;
|
||||
flat_map<sidechain_type, uint64_t> son2_start_votes, son2_end_votes;
|
||||
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_start_votes = son1_obj.total_votes;
|
||||
|
|
@ -253,7 +253,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
// Verify that the vote is there
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes > son1_start_votes);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] > son1_start_votes[sidechain_type::bitcoin]);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::hive] > son1_start_votes[sidechain_type::hive]);
|
||||
|
||||
// Vote for a son2account
|
||||
BOOST_TEST_MESSAGE("Voting for son2account");
|
||||
|
|
@ -264,7 +265,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
// Verify that the vote is there
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes > son2_start_votes);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] > son2_start_votes[sidechain_type::bitcoin]);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::hive] > son2_start_votes[sidechain_type::hive]);
|
||||
|
||||
//! Get nathan account
|
||||
const auto nathan_account_object = con.wallet_api_ptr->get_account("nathan");
|
||||
|
|
@ -304,7 +306,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
// Verify that the vote is removed
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
son1_end_votes = son1_obj.total_votes;
|
||||
BOOST_CHECK(son1_end_votes == son1_start_votes);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] == son1_start_votes[sidechain_type::bitcoin]);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::hive] == son1_start_votes[sidechain_type::hive]);
|
||||
|
||||
//! Check son1account voters
|
||||
voters_for_son1account = con.wallet_api_ptr->get_voters("son1account");
|
||||
|
|
@ -329,7 +332,8 @@ BOOST_AUTO_TEST_CASE( son_voting )
|
|||
// Verify that the vote is removed
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK(son2_end_votes == son2_start_votes);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] == son2_start_votes[sidechain_type::bitcoin]);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::hive] == son2_start_votes[sidechain_type::hive]);
|
||||
|
||||
//! Check son2account voters
|
||||
voters_for_son2account = con.wallet_api_ptr->get_voters("son2account");
|
||||
|
|
@ -495,8 +499,8 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
|
||||
son_object son1_obj;
|
||||
son_object son2_obj;
|
||||
uint64_t son1_start_votes, son1_end_votes;
|
||||
uint64_t son2_start_votes, son2_end_votes;
|
||||
flat_map<sidechain_type, uint64_t> son1_start_votes, son1_end_votes;
|
||||
flat_map<sidechain_type, uint64_t> son2_start_votes, son2_end_votes;
|
||||
|
||||
// Get votes at start
|
||||
son1_obj = con.wallet_api_ptr->get_son("son1account");
|
||||
|
|
@ -522,11 +526,11 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] > son1_start_votes[sidechain_type::bitcoin]);
|
||||
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);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] > son2_start_votes[sidechain_type::bitcoin]);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
|
||||
|
|
@ -542,12 +546,12 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] < son1_start_votes[sidechain_type::bitcoin]);
|
||||
son1_start_votes = son1_end_votes;
|
||||
son2_obj = con.wallet_api_ptr->get_son("son2account");
|
||||
// voice distribution changed, SON2 now has all voices
|
||||
son2_end_votes = son2_obj.total_votes;
|
||||
BOOST_CHECK((son2_end_votes > son2_start_votes)); // nathan spent funds for vb, it has different voting power
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] > son2_start_votes[sidechain_type::bitcoin]); // nathan spent funds for vb, it has different voting power
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Try to reject incorrect SON
|
||||
|
|
@ -561,11 +565,11 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] == son1_start_votes[sidechain_type::bitcoin]);
|
||||
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);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] == son2_start_votes[sidechain_type::bitcoin]);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Reject SON2
|
||||
|
|
@ -579,11 +583,11 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] == son1_start_votes[sidechain_type::bitcoin]);
|
||||
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);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] < son2_start_votes[sidechain_type::bitcoin]);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Try to accept and reject the same SON
|
||||
|
|
@ -598,11 +602,11 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] == son1_start_votes[sidechain_type::bitcoin]);
|
||||
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);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] == son2_start_votes[sidechain_type::bitcoin]);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
// Try to accept and reject empty lists
|
||||
|
|
@ -615,11 +619,11 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test )
|
|||
// 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);
|
||||
BOOST_CHECK(son1_end_votes[sidechain_type::bitcoin] == son1_start_votes[sidechain_type::bitcoin]);
|
||||
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);
|
||||
BOOST_CHECK(son2_end_votes[sidechain_type::bitcoin] == son2_start_votes[sidechain_type::bitcoin]);
|
||||
son2_start_votes = son2_end_votes;
|
||||
|
||||
} catch( fc::exception& e ) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue