exceptions: Add some exceptions

This commit is contained in:
theoreticalbts 2015-07-08 16:30:32 -04:00
parent 8d3fd20db2
commit 9c4ac2e064
6 changed files with 93 additions and 9 deletions

View file

@ -76,12 +76,62 @@ namespace graphene { namespace chain {
FC_DECLARE_DERIVED_EXCEPTION( invalid_pts_address, graphene::chain::utility_exception, 3060001, "invalid pts address" )
FC_DECLARE_DERIVED_EXCEPTION( insufficient_feeds, graphene::chain::chain_exception, 37006, "insufficient feeds" )
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( transfer );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( from_account_not_whitelisted, transfer, 1, "owner mismatch" )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( to_account_not_whitelisted, transfer, 2, "owner mismatch" )
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_cancel );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( call_order_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( account_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( account_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( account_whitelist );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( account_upgrade );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( account_transfer );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_update_bitasset );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_update_feed_producers );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_issue );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_reserve );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_fund_fee_pool );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_settle );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_global_settle );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( asset_publish_feed );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( delegate_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( witness_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( witness_withdraw_pay );
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( proposal_create );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( review_period_required, proposal_create, 1, "review_period required" )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( review_period_insufficient, proposal_create, 2, "review_period insufficient" )
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( proposal_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( proposal_delete );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( withdraw_permission_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( withdraw_permission_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( withdraw_permission_claim );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( withdraw_permission_delete );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( fill_order );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( global_parameters_update );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( vesting_balance_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( vesting_balance_withdraw );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( worker_create );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( custom );
//GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( assert );
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( balance_claim );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( claimed_too_often, balance_claim, 1, "balance claimed too often" )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( invalid_claim_amount, balance_claim, 2, "invalid claim amount" )
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( owner_mismatch, balance_claim, 3, "owner mismatch" )
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( override_transfer );
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( not_permitted, override_transfer, 1, "not permitted" )
/*
FC_DECLARE_DERIVED_EXCEPTION( addition_overflow, graphene::chain::chain_exception, 30002, "addition overflow" )
FC_DECLARE_DERIVED_EXCEPTION( subtraction_overflow, graphene::chain::chain_exception, 30003, "subtraction overflow" )

View file

@ -18,6 +18,7 @@
#include <graphene/chain/proposal_evaluator.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/exceptions.hpp>
namespace graphene { namespace chain {
@ -41,8 +42,21 @@ void_result proposal_create_evaluator::do_evaluate(const proposal_create_operati
operation_get_required_owner_authorities(op.op, auths);
}
if( auths.find(account_id_type()) != auths.end() )
FC_ASSERT( o.review_period_seconds
&& *o.review_period_seconds >= global_parameters.committee_proposal_review_period );
{
GRAPHENE_ASSERT(
o.review_period_seconds.valid(),
proposal_create_review_period_required,
"Review period not given, but at least ${min} required",
("min", global_parameters.committee_proposal_review_period)
);
GRAPHENE_ASSERT(
*o.review_period_seconds >= global_parameters.committee_proposal_review_period,
proposal_create_review_period_insufficient,
"Review period of ${t} required, but at least ${min} required",
("t", *o.review_period_seconds)
("min", global_parameters.committee_proposal_review_period)
);
}
}
for( const op_wrapper& op : o.proposed_ops )

View file

@ -17,6 +17,7 @@
*/
#include <graphene/chain/transfer_evaluator.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/exceptions.hpp>
namespace graphene { namespace chain {
void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
@ -30,8 +31,20 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op )
if( asset_type.options.flags & white_list )
{
FC_ASSERT( to_account.is_authorized_asset( asset_type ) );
FC_ASSERT( from_account.is_authorized_asset( asset_type ) );
GRAPHENE_ASSERT(
from_account.is_authorized_asset( asset_type ),
transfer_from_account_not_whitelisted,
"'from' account ${from} is not whitelisted for asset ${asset}",
("from",op.from)
("asset",op.amount.asset_id)
);
GRAPHENE_ASSERT(
to_account.is_authorized_asset( asset_type ),
transfer_to_account_not_whitelisted,
"'to' account ${to} is not whitelisted for asset ${asset}",
("to",op.to)
("asset",op.amount.asset_id)
);
}
if( fee_asset_type.options.flags & white_list )
@ -60,7 +73,12 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op
database& d = db();
const asset_object& asset_type = op.amount.asset_id(d);
FC_ASSERT( asset_type.can_override() );
GRAPHENE_ASSERT(
asset_type.can_override(),
override_transfer_not_permitted,
"override_transfer not permitted for asset ${asset}",
("asset", op.amount.asset_id)
);
FC_ASSERT( asset_type.issuer == op.issuer );
const account_object& from_account = op.from(d);

View file

@ -19,6 +19,7 @@
#include <graphene/chain/withdraw_permission_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
namespace graphene { namespace chain {

View file

@ -19,6 +19,7 @@
#include <boost/test/unit_test.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/operations.hpp>
#include <graphene/chain/account_object.hpp>
@ -384,12 +385,12 @@ BOOST_AUTO_TEST_CASE( genesis_authority )
sign();
// The review period isn't set yet. Make sure it throws.
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), fc::exception );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_required );
pop.review_period_seconds = global_params.committee_proposal_review_period / 2;
trx.operations.back() = pop;
sign();
// The review period is too short. Make sure it throws.
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), fc::exception );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx ), proposal_create_review_period_insufficient );
pop.review_period_seconds = global_params.committee_proposal_review_period;
trx.operations.back() = pop;
sign();

View file

@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
transfer_operation op({advanced.amount(0), nathan.id, dan.id, advanced.amount(100)});
trx.operations.push_back(op);
//Fail because dan is not whitelisted.
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_to_account_not_whitelisted );
account_whitelist_operation wop({asset(), account_id_type(), dan.id, account_whitelist_operation::white_listed});
trx.operations.back() = wop;
@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE( transfer_whitelist_uia )
op.amount = advanced.amount(50);
trx.operations.back() = op;
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), transfer_from_account_not_whitelisted );
trx.operations = {asset_reserve_operation{asset(), nathan.id, advanced.amount(10)}};
//Fail because nathan is blacklisted
GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception);