Skip to content

Commit

Permalink
Issue EOSIO#32 Vote before voting time does not throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariusz-Trela committed Dec 4, 2018
1 parent 41549f2 commit 5becff2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
7 changes: 2 additions & 5 deletions contracts/eosio.system/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,8 @@ namespace eosiosystem {
}

// update voting power
if( is_allowed_vote_operation() )
{
asset total_update = stake_net_delta + stake_cpu_delta;
update_voting_power(from, total_update.amount);
}
asset total_update = stake_net_delta + stake_cpu_delta;
update_voting_power(from, total_update.amount);
}

void system_contract::delegatebw( account_name from, account_name receiver,
Expand Down
4 changes: 1 addition & 3 deletions contracts/eosio.system/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ namespace eosiosystem {
* If voting for a proxy, the producer votes will not change until the proxy updates their own vote.
*/
void system_contract::voteproducer( const account_name voter_name, const account_name proxy, const std::vector<account_name>& producers ) {
eosio_assert( is_allowed_vote_operation(), "initial witness election is disabled" );
require_auth( voter_name );
update_votes( voter_name, proxy, producers, true);
}
Expand Down Expand Up @@ -197,9 +198,6 @@ namespace eosiosystem {
void system_contract::regproxy( const account_name proxy, bool isproxy ) {
require_auth( proxy );

if( !is_allowed_vote_operation() )
return;

auto producer_infos = prepare_producer_infos(_producers);

::register_voting_proxy(proxy, isproxy, producer_infos.data(), producer_infos.size());
Expand Down
17 changes: 9 additions & 8 deletions unittests/eosio.interchain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ BOOST_FIXTURE_TEST_CASE( basic_vote_test, eosio_init_tester ) try {
produce_blocks( 60 - control->head_block_num() );

BOOST_REQUIRE_EQUAL( success(), create_producer( N(bob) ) );
BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxxmario), { N(bob) } ) );

CHECK_STATS(xxxxxxxmario, "5.0000 PROXY", "800.0000 BEOS", "0");
CHECK_STATS(bob, "5.0000 PROXY", "800.0000 BEOS", "0");
Expand All @@ -817,7 +817,7 @@ BOOST_FIXTURE_TEST_CASE( basic_vote_test, eosio_init_tester ) try {

produce_blocks( 100 - control->head_block_num() );

BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
prod = get_producer_info( N(bob) );
BOOST_REQUIRE_EQUAL( 0, prod["total_votes"].as_double() );

Expand Down Expand Up @@ -856,11 +856,11 @@ BOOST_FIXTURE_TEST_CASE( basic_vote_test2, eosio_init_tester ) try {
BOOST_REQUIRE_EQUAL( success(), create_producer( N(bob) ) );
BOOST_REQUIRE_EQUAL( success(), create_producer( N(carol) ) );

BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxxmario), { N(carol) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxxmario), { N(carol) } ) );

BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxmario2), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxmario2), { N(carol) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxmario2), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxmario2), { N(carol) } ) );

auto prod = get_producer_info( N(bob) );
BOOST_REQUIRE_EQUAL( 0, prod["total_votes"].as_double() );
Expand All @@ -871,9 +871,10 @@ BOOST_FIXTURE_TEST_CASE( basic_vote_test2, eosio_init_tester ) try {
produce_blocks( 100 - control->head_block_num() - 2 );
BOOST_REQUIRE_EQUAL( control->head_block_num(), 98u );

BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( success(), vote_producer( N(xxxxxxmario2), { N(carol) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxxmario), { N(bob) } ) );
BOOST_REQUIRE_EQUAL( wasm_assert_msg("initial witness election is disabled"), vote_producer( N(xxxxxxmario2), { N(carol) } ) );

produce_blocks( 2 );
BOOST_REQUIRE_EQUAL( control->head_block_num(), 100u );

prod = get_producer_info( N(bob) );
Expand Down

0 comments on commit 5becff2

Please sign in to comment.