From 96fb8f60c2b9b1a0aee3c73fcd7252129d98b51a Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Wed, 12 Aug 2015 14:02:58 -0400 Subject: [PATCH] fee_tests.cpp: Make sure validation actually enforces nonzero fees --- .../include/graphene/chain/evaluator.hpp | 4 +- .../include/graphene/chain/exceptions.hpp | 1 + tests/tests/fee_tests.cpp | 41 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 5f58efb9..16be4ac6 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -16,6 +16,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once +#include #include namespace graphene { namespace chain { @@ -190,7 +191,8 @@ namespace graphene { namespace chain { const auto& op = o.get(); prepare_fee(op.fee_payer(), op.fee); - FC_ASSERT( core_fee_paid >= db().current_fee_schedule().calculate_fee( op ).amount, + GRAPHENE_ASSERT( core_fee_paid >= db().current_fee_schedule().calculate_fee( op ).amount, + insufficient_fee, "Insufficient Fee Paid", ("core_fee_paid",core_fee_paid)("required",db().current_fee_schedule().calculate_fee( op ).amount) ); diff --git a/libraries/chain/include/graphene/chain/exceptions.hpp b/libraries/chain/include/graphene/chain/exceptions.hpp index 1a55862d..d77960f2 100644 --- a/libraries/chain/include/graphene/chain/exceptions.hpp +++ b/libraries/chain/include/graphene/chain/exceptions.hpp @@ -76,6 +76,7 @@ namespace graphene { namespace chain { FC_DECLARE_DERIVED_EXCEPTION( tx_irrelevant_sig, graphene::chain::transaction_exception, 3030004, "irrelevant signature included" ) FC_DECLARE_DERIVED_EXCEPTION( tx_duplicate_sig, graphene::chain::transaction_exception, 3030005, "duplicate signature included" ) FC_DECLARE_DERIVED_EXCEPTION( invalid_committee_approval, graphene::chain::transaction_exception, 3030006, "committee account cannot directly approve transaction" ) + FC_DECLARE_DERIVED_EXCEPTION( insufficient_fee, graphene::chain::transaction_exception, 3030007, "insufficient fee" ) 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" ) diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index f2efc353..5b81cc10 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -24,9 +24,50 @@ #include "../common/database_fixture.hpp" using namespace graphene::chain; +using namespace graphene::chain::test; BOOST_FIXTURE_TEST_SUITE( fee_tests, database_fixture ) +BOOST_AUTO_TEST_CASE( nonzero_fee_test ) +{ + try + { + ACTORS((alice)(bob)); + + const share_type prec = asset::scaled_precision( asset_id_type()(db).precision ); + + // Return number of core shares (times precision) + auto _core = [&]( int64_t x ) -> asset + { return asset( x*prec ); }; + + transfer( committee_account, alice_id, _core(1000000) ); + + // make sure the database requires our fee to be nonzero + enable_fees(); + + signed_transaction tx; + transfer_operation xfer_op; + xfer_op.from = alice_id; + xfer_op.to = bob_id; + xfer_op.amount = _core(1000); + xfer_op.fee = _core(0); + tx.operations.push_back( xfer_op ); + set_expiration( db, tx ); + sign( tx, alice_private_key ); + GRAPHENE_REQUIRE_THROW( PUSH_TX( db, tx ), insufficient_fee ); + } + catch( const fc::exception& e ) + { + edump((e.to_detail_string())); + throw; + } +} + + +/////////////////////////////////////////////////////////////// +// cashback_test infrastructure // +/////////////////////////////////////////////////////////////// + #define CHECK_BALANCE( actor_name, amount ) \ BOOST_CHECK_EQUAL( get_balance( actor_name ## _id, asset_id_type() ), amount )