Test bulk discount on fees

This commit is contained in:
Nathan Hourt 2015-06-19 15:58:51 -04:00
parent 3d29b29e50
commit 639930a2d7
3 changed files with 43 additions and 7 deletions

View file

@ -78,15 +78,12 @@ void account_statistics_object::process_fees(const account_object& a, database&
auto pay_out_fees = [&](const account_object& account, share_type core_fee_total, bool require_vesting)
{
// Check the referrer and registrar -- if they're no longer members, pay up to the lifetime member instead.
// Check the referrer -- if he's no longer a member, pay to the lifetime referrer instead.
// No need to check the registrar; registrars are required to be lifetime members.
if( account.referrer(d).is_basic_account(d.head_block_time()) )
d.modify(account, [](account_object& a) {
a.referrer = a.lifetime_referrer;
});
if( account.registrar(d).is_basic_account(d.head_block_time()) )
d.modify(account, [](account_object& a) {
a.registrar = a.lifetime_referrer;
});
share_type network_cut = cut_fee(core_fee_total, account.network_fee_percentage);
assert( network_cut <= core_fee_total );

View file

@ -306,8 +306,6 @@ signed_block database::_generate_block(
if( !(skip & skip_delegate_signature) ) _pending_block.sign( block_signing_private_key );
FC_ASSERT( fc::raw::pack_size(_pending_block) <= get_global_properties().parameters.maximum_block_size );
//This line used to std::move(_pending_block) but this is unsafe as _pending_block is later referenced without being
//reinitialized. Future optimization could be to move it, then reinitialize it with the values we need to preserve.
signed_block tmp = _pending_block;
tmp.transaction_merkle_root = tmp.calculate_merkle_root();
_pending_block.transactions.clear();

View file

@ -130,4 +130,45 @@ BOOST_AUTO_TEST_CASE( cashback_test )
BOOST_CHECK_EQUAL(stud_id(db).cashback_balance(db).balance.amount.value, 25750);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE(bulk_discount)
{ try {
ACTOR(nathan);
// Give nathan ALLLLLL the money!
transfer(GRAPHENE_COMMITTEE_ACCOUNT, nathan_id, db.get_balance(GRAPHENE_COMMITTEE_ACCOUNT, asset_id_type()));
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
upgrade_to_lifetime_member(nathan_id);
share_type new_fees;
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MIN )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += transfer_operation().calculate_fee(db.current_fee_schedule());
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
auto old_cashback = nathan_id(db).cashback_balance(db).balance;
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 8);
new_fees = 0;
while( nathan_id(db).statistics(db).lifetime_fees_paid + new_fees < GRAPHENE_DEFAULT_BULK_DISCOUNT_THRESHOLD_MAX )
{
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
new_fees += transfer_operation().calculate_fee(db.current_fee_schedule());
}
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
enable_fees(GRAPHENE_BLOCKCHAIN_PRECISION*10);
old_cashback = nathan_id(db).cashback_balance(db).balance;
transfer(nathan_id, GRAPHENE_COMMITTEE_ACCOUNT, asset(1));
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
BOOST_CHECK_EQUAL(nathan_id(db).cashback_balance(db).balance.amount.value,
old_cashback.amount.value + GRAPHENE_BLOCKCHAIN_PRECISION * 9);
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()