From 800e58d0cfb320f6c89b1653617c43956590ab26 Mon Sep 17 00:00:00 2001 From: abitmore Date: Tue, 7 Aug 2018 12:21:51 -0400 Subject: [PATCH 1/3] Moved voting_account check to verify_account_votes --- libraries/chain/account_evaluator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/chain/account_evaluator.cpp b/libraries/chain/account_evaluator.cpp index cc199bcb87..d550007c76 100644 --- a/libraries/chain/account_evaluator.cpp +++ b/libraries/chain/account_evaluator.cpp @@ -71,6 +71,8 @@ void verify_account_votes( const database& db, const account_options& options ) FC_ASSERT( options.num_committee <= chain_params.maximum_committee_count, "Voted for more committee members than currently allowed (${c})", ("c", chain_params.maximum_committee_count) ); + FC_ASSERT( db.find_object(options.voting_account), "Invalid proxy account specified." ); + uint32_t max_vote_id = gpo.next_available_vote_id; bool has_worker_votes = false; for( auto id : options.votes ) @@ -134,7 +136,6 @@ void_result account_create_evaluator::do_evaluate( const account_create_operatio FC_ASSERT( !op.extensions.value.buyback_options.valid() ); } - FC_ASSERT( d.find_object(op.options.voting_account), "Invalid proxy account specified." ); FC_ASSERT( fee_paying_account->is_lifetime_member(), "Only Lifetime members may register an account." ); FC_ASSERT( op.referrer(d).is_member(d.head_block_time()), "The referrer must be either a lifetime or annual subscriber." ); From cef14fe0648745f7bcaca99abacbd530eff4a0a5 Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Tue, 7 Aug 2018 12:50:35 -0500 Subject: [PATCH 2/3] add test for invalid voting account --- tests/tests/voting_tests.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index 0b24e4ce08..4e81aedddc 100644 --- a/tests/tests/voting_tests.cpp +++ b/tests/tests/voting_tests.cpp @@ -393,4 +393,28 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_disabled) } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE(invalid_voting_account) +{ + ACTORS((alice)); + + account_id_type invalid_account_id; + invalid_account_id.instance = 99999; + + graphene::chain::account_update_operation op; + op.account = alice_id; + op.new_options = alice.options; + op.new_options->voting_account = invalid_account_id; + trx.operations.push_back(op); + sign(trx, alice_private_key); + try + { + PUSH_TX(db, trx, ~0); + BOOST_FAIL("Updating an account with an invalid voting account should fail."); + } + catch (fc::exception& ex) + { + // We should end up here + } +} + BOOST_AUTO_TEST_SUITE_END() From cfea090e7c4a4c48678a9d21b4cfa17c8949581c Mon Sep 17 00:00:00 2001 From: abitmore Date: Wed, 8 Aug 2018 07:33:45 -0400 Subject: [PATCH 3/3] Coding style update --- tests/tests/voting_tests.cpp | 38 +++++++++++++++++------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index 4e81aedddc..34f39e48c1 100644 --- a/tests/tests/voting_tests.cpp +++ b/tests/tests/voting_tests.cpp @@ -395,26 +395,24 @@ BOOST_AUTO_TEST_CASE(track_votes_committee_disabled) BOOST_AUTO_TEST_CASE(invalid_voting_account) { - ACTORS((alice)); - - account_id_type invalid_account_id; - invalid_account_id.instance = 99999; - - graphene::chain::account_update_operation op; - op.account = alice_id; - op.new_options = alice.options; - op.new_options->voting_account = invalid_account_id; - trx.operations.push_back(op); - sign(trx, alice_private_key); - try - { - PUSH_TX(db, trx, ~0); - BOOST_FAIL("Updating an account with an invalid voting account should fail."); - } - catch (fc::exception& ex) - { - // We should end up here - } + try + { + ACTORS((alice)); + + account_id_type invalid_account_id( (uint64_t)999999 ); + + BOOST_CHECK( !db.find( invalid_account_id ) ); + + graphene::chain::account_update_operation op; + op.account = alice_id; + op.new_options = alice.options; + op.new_options->voting_account = invalid_account_id; + trx.operations.push_back(op); + sign(trx, alice_private_key); + + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::exception ); + + } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_SUITE_END()