Skip to content

Commit

Permalink
exceptions: Implement missing_auth exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
theoreticalbts committed Jul 8, 2015
1 parent 8ff25b8 commit d4e4854
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
20 changes: 16 additions & 4 deletions libraries/chain/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
*/
#include <graphene/chain/database.hpp>
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/transaction_evaluation_state.hpp>

#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/delegate_object.hpp>
Expand Down Expand Up @@ -90,14 +92,24 @@ database& generic_evaluator::db()const { return trx_state->db(); }
operation_get_required_authorities( op, other_auths );

for( auto id : active_auths )
FC_ASSERT(verify_authority(id(db()), authority::active) ||
verify_authority(id(db()), authority::owner), "", ("id", id));
GRAPHENE_ASSERT(
verify_authority(id(db()), authority::active) ||
verify_authority(id(db()), authority::owner),
tx_missing_active_auth,
"missing required active authority ${id}", ("id", id));

for( auto id : owner_auths )
FC_ASSERT(verify_authority(id(db()), authority::owner), "", ("id", id));
GRAPHENE_ASSERT(
verify_authority(id(db()), authority::owner),
tx_missing_owner_auth,
"missing required owner authority ${id}", ("id", id));

for( const auto& auth : other_auths )
FC_ASSERT(trx_state->check_authority(auth), "invalid authority", ("auth",auth)("sigs",trx_state->_sigs));
GRAPHENE_ASSERT(
trx_state->check_authority(auth),
tx_missing_other_auth,
"missing required authority ${auth}",
("auth",auth)("sigs",trx_state->_sigs));

} FC_CAPTURE_AND_RETHROW( (op) ) }

Expand Down
5 changes: 5 additions & 0 deletions libraries/chain/include/graphene/chain/exceptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ namespace graphene { namespace chain {
FC_DECLARE_DERIVED_EXCEPTION( operation_evaluate_exception, graphene::chain::chain_exception, 3050000, "operation evaluation exception" )
FC_DECLARE_DERIVED_EXCEPTION( utility_exception, graphene::chain::chain_exception, 3060000, "utility method exception" )

FC_DECLARE_DERIVED_EXCEPTION( tx_missing_active_auth, graphene::chain::transaction_exception, 3030001, "missing required active authority" )
FC_DECLARE_DERIVED_EXCEPTION( tx_missing_owner_auth, graphene::chain::transaction_exception, 3030002, "missing required owner authority" )
FC_DECLARE_DERIVED_EXCEPTION( tx_missing_other_auth, graphene::chain::transaction_exception, 3030003, "missing required other authority" )
//FC_DECLARE_DERIVED_EXCEPTION( tx_irrelevant_authority, graphene::chain::transaction_exception, 3030004, "irrelevant authority" )

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" )

Expand Down
5 changes: 3 additions & 2 deletions tests/tests/uia_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -84,10 +85,10 @@ BOOST_AUTO_TEST_CASE( override_transfer_test )
trx.operations.push_back(otrans);

BOOST_TEST_MESSAGE( "Require throwing without signature" );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception);
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth );
BOOST_TEST_MESSAGE( "Require throwing with dan's signature" );
trx.sign( dan_private_key );
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), fc::exception);
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, 0 ), tx_missing_active_auth );
BOOST_TEST_MESSAGE( "Pass with issuer's signature" );
trx.signatures.clear();
trx.sign( sam_private_key );
Expand Down

0 comments on commit d4e4854

Please sign in to comment.