Skip to content

Commit

Permalink
Merge pull request bitshares#578 from abitmore/577-vote-id-exception
Browse files Browse the repository at this point in the history
Capture exceptions when initializing `vote_id_type` with a string
  • Loading branch information
abitmore authored Jan 23, 2018
2 parents 02a4499 + 3d3b2bb commit 7c45b52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libraries/chain/include/graphene/chain/protocol/vote.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ struct vote_id_type
{}
/// Construct this vote_id_type from a serial string in the form "type:instance"
explicit vote_id_type(const std::string& serial)
{
{ try {
auto colon = serial.find(':');
FC_ASSERT( colon != std::string::npos );
*this = vote_id_type(vote_type(std::stoul(serial.substr(0, colon))), std::stoul(serial.substr(colon+1)));
}
} FC_CAPTURE_AND_RETHROW( (serial) ) }

/// Set the type of this vote_id_type
void set_type(vote_type type)
Expand Down
3 changes: 3 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ BOOST_AUTO_TEST_CASE( create_account_test )
REQUIRE_THROW_WITH_VALUE(op, options.votes, boost::assign::list_of<vote_id_type>(vote_id_type("1:19")).convert_to_container<flat_set<vote_id_type>>());
op.options.num_witness = 0;
REQUIRE_THROW_WITH_VALUE(op, options.votes, boost::assign::list_of<vote_id_type>(vote_id_type("2:19")).convert_to_container<flat_set<vote_id_type>>());
REQUIRE_THROW_WITH_VALUE(op, options.votes, boost::assign::list_of<vote_id_type>(vote_id_type("3:99")).convert_to_container<flat_set<vote_id_type>>());
GRAPHENE_REQUIRE_THROW( vote_id_type("2:a"), fc::exception );
GRAPHENE_REQUIRE_THROW( vote_id_type(""), fc::exception );
op.options.num_committee = save_num_committee;
op.options.num_witness = save_num_witness;

Expand Down

0 comments on commit 7c45b52

Please sign in to comment.