Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BLOCKBACK-186] Withdraw vesting bug fix #243

Merged
merged 2 commits into from
Dec 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions libraries/chain/vesting_balance_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_
std::for_each(vesting_range.first, vesting_range.second,
[&ids, now](const vesting_balance_object& balance) {
if(balance.balance.amount > 0 && balance.balance_type == vesting_balance_type::gpos
&& balance.balance.asset_id == asset_id_type())
&& balance.is_withdraw_allowed(now, balance.balance.amount) && balance.balance.asset_id == asset_id_type())
ids.emplace_back(balance.id);
});

Expand All @@ -202,8 +202,8 @@ void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_
if(total_withdraw_amount.amount > vbo.balance.amount)
{
total_withdraw_amount.amount -= vbo.balance.amount;
d.modify( vbo, [&]( vesting_balance_object& vbo ) {vbo.withdraw( now, vbo.balance );} );
d.adjust_balance( op.owner, vbo.balance );
d.modify( vbo, [&]( vesting_balance_object& vbo ) {vbo.withdraw( now, vbo.balance );} );
}
else
{
Expand Down
38 changes: 38 additions & 0 deletions tests/tests/gpos_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,7 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )

ACTORS((alice)(bob));

graphene::app::database_api db_api1(db);
const auto& core = asset_id_type()(db);


Expand All @@ -1072,6 +1073,43 @@ BOOST_AUTO_TEST_CASE( Withdraw_gpos_vesting_balance )
// verify charles balance
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 400);
BOOST_CHECK_EQUAL(get_balance(bob_id(db), core), 99);

// Add more 50 and 73 vesting objects and withdraw 90 from
// total vesting balance of user
create_vesting(alice_id, core.amount(50), vesting_balance_type::gpos);
create_vesting(alice_id, core.amount(73), vesting_balance_type::gpos);
generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);

generate_block();

vector<vesting_balance_object> vbos = db_api1.get_vesting_balances("alice");
asset total_vesting;
for (const vesting_balance_object& vbo : vbos)
{
if (vbo.balance_type == vesting_balance_type::gpos && vbo.balance.asset_id == asset_id_type())
total_vesting += vbo.balance;
}
// total vesting balance of alice
BOOST_CHECK_EQUAL(total_vesting.amount.value, core.amount(223).amount.value);

generate_blocks(db.get_dynamic_global_properties().next_maintenance_time);
generate_blocks(db.get_global_properties().parameters.gpos_vesting_lockin_period());
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 277);
withdraw_gpos_vesting(vbo.id, alice_id, core.amount(90), vesting_balance_type::gpos, alice_private_key);
generate_block();
// verify alice balance
BOOST_CHECK_EQUAL(get_balance(alice_id(db), core), 367);

// verify remaining vesting balance
vbos = db_api1.get_vesting_balances("alice");
asset remaining_vesting;
for (const vesting_balance_object& vbo : vbos)
{
if (vbo.balance_type == vesting_balance_type::gpos && vbo.balance.asset_id == asset_id_type())
remaining_vesting += vbo.balance;
}
// remaining vesting balance of alice
BOOST_CHECK_EQUAL(remaining_vesting.amount.value, core.amount(133).amount.value);
}
catch (fc::exception &e) {
edump((e.to_detail_string()));
Expand Down