fee_tests.cpp: Make sure validation actually enforces nonzero fees

This commit is contained in:
theoreticalbts 2015-08-12 14:02:58 -04:00
parent dffd010e8a
commit 96fb8f60c2
3 changed files with 45 additions and 1 deletions

View file

@ -16,6 +16,7 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <graphene/chain/exceptions.hpp>
#include <graphene/chain/protocol/operations.hpp>
namespace graphene { namespace chain {
@ -190,7 +191,8 @@ namespace graphene { namespace chain {
const auto& op = o.get<typename DerivedEvaluator::operation_type>();
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) );

View file

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

View file

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