diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ee05ffd9..730b6b84 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -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(); + 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(); + + // 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().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 >().inspect_all_objects( + [&](const object& o) + { + ilog( "budget: ${brec}", ("brec", static_cast(o)) ); + }); + */ + } + } FC_LOG_AND_RETHROW() +} + // TODO: Write linear VBO tests BOOST_AUTO_TEST_SUITE_END()