operation_tests2.cpp: Implement zero_second_vbo test for issue #390

This commit is contained in:
theoreticalbts 2015-10-28 11:43:56 -04:00
parent 5e91e095c0
commit d588ac987c

View file

@ -27,6 +27,7 @@
#include <graphene/chain/asset_object.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/balance_object.hpp>
#include <graphene/chain/budget_record_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/market_evaluator.hpp>
@ -1207,6 +1208,121 @@ BOOST_AUTO_TEST_CASE(transfer_with_memo) {
} FC_LOG_AND_RETHROW()
}
BOOST_AUTO_TEST_CASE(zero_second_vbo)
{
try
{
ACTOR(alice);
// don't pay witnesses so we have some worker budget to work with
transfer(account_id_type(), alice_id, asset(int64_t(100000) * 1100 * 1000 * 1000));
{
asset_reserve_operation op;
op.payer = alice_id;
op.amount_to_reserve = asset(int64_t(100000) * 1000 * 1000 * 1000);
transaction tx;
tx.operations.push_back( op );
set_expiration( db, tx );
db.push_transaction( tx, database::skip_authority_check | database::skip_tapos_check | database::skip_transaction_signatures );
}
enable_fees();
upgrade_to_lifetime_member(alice_id);
generate_block();
auto check_vesting_1b = [&](vesting_balance_id_type vbid)
{
// this function checks that Alice can't draw any right now,
// but one block later, she can withdraw it all.
vesting_balance_withdraw_operation withdraw_op;
withdraw_op.vesting_balance = vbid;
withdraw_op.owner = alice_id;
withdraw_op.amount = asset(1);
signed_transaction withdraw_tx;
withdraw_tx.operations.push_back( withdraw_op );
sign(withdraw_tx, alice_private_key);
GRAPHENE_REQUIRE_THROW( PUSH_TX( db, withdraw_tx ), fc::exception );
generate_block();
withdraw_tx = signed_transaction();
withdraw_op.amount = asset(500);
withdraw_tx.operations.push_back( withdraw_op );
set_expiration( db, withdraw_tx );
sign(withdraw_tx, alice_private_key);
PUSH_TX( db, withdraw_tx );
};
// This block creates a zero-second VBO with a vesting_balance_create_operation.
{
cdd_vesting_policy_initializer pinit;
pinit.vesting_seconds = 0;
vesting_balance_create_operation create_op;
create_op.creator = alice_id;
create_op.owner = alice_id;
create_op.amount = asset(500);
create_op.policy = pinit;
signed_transaction create_tx;
create_tx.operations.push_back( create_op );
set_expiration( db, create_tx );
sign(create_tx, alice_private_key);
processed_transaction ptx = PUSH_TX( db, create_tx );
vesting_balance_id_type vbid = ptx.operation_results[0].get<object_id_type>();
check_vesting_1b( vbid );
}
// This block creates a zero-second VBO with a worker_create_operation.
{
worker_create_operation create_op;
create_op.owner = alice_id;
create_op.work_begin_date = db.head_block_time();
create_op.work_end_date = db.head_block_time() + fc::days(1000);
create_op.daily_pay = share_type( 10000 );
create_op.name = "alice";
create_op.url = "";
create_op.initializer = vesting_balance_worker_initializer(0);
signed_transaction create_tx;
create_tx.operations.push_back(create_op);
set_expiration( db, create_tx );
sign(create_tx, alice_private_key);
processed_transaction ptx = PUSH_TX( db, create_tx );
worker_id_type wid = ptx.operation_results[0].get<object_id_type>();
// vote it in
account_update_operation vote_op;
vote_op.account = alice_id;
vote_op.new_options = alice_id(db).options;
vote_op.new_options->votes.insert(wid(db).vote_for);
signed_transaction vote_tx;
vote_tx.operations.push_back(vote_op);
set_expiration( db, vote_tx );
sign( vote_tx, alice_private_key );
PUSH_TX( db, vote_tx );
// vote it in, wait for one maint. for vote to take effect
vesting_balance_id_type vbid = wid(db).worker.get<vesting_balance_worker_type>().balance;
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_block();
// wait for another maint. for worker to be paid
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(0) );
generate_block();
BOOST_CHECK( vbid(db).get_allowed_withdraw(db.head_block_time()) == asset(10000) );
/*
db.get_index_type< simple_index<budget_record_object> >().inspect_all_objects(
[&](const object& o)
{
ilog( "budget: ${brec}", ("brec", static_cast<const budget_record_object&>(o)) );
});
*/
}
} FC_LOG_AND_RETHROW()
}
// TODO: Write linear VBO tests
BOOST_AUTO_TEST_SUITE_END()