Skip to content

Commit

Permalink
Progress bitshares#1604: Add dust check
Browse files Browse the repository at this point in the history
Add dust check to limit order update logic, and test
  • Loading branch information
nathanielhourt committed Feb 26, 2019
1 parent 8da1f72 commit 1c81eaf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,17 @@ void_result limit_order_update_evaluator::do_evaluate(const limit_order_update_o
"Cannot deduct more from order than order contains");
}

// Check dust
if (o.new_price || (o.delta_amount_to_sell && o.delta_amount_to_sell->amount < 0)) {
auto new_price = o.new_price? *o.new_price : _order->sell_price;
auto new_amount = _order->amount_for_sale();
if (o.delta_amount_to_sell)
new_amount += *o.delta_amount_to_sell;
auto new_amount_to_receive = new_amount * new_price;

FC_ASSERT(new_amount_to_receive.amount > 0, "Cannot update limit order: order becomes too small; cancel order instead");
}

// Check expiration is in the future
if (o.new_expiration)
FC_ASSERT(*o.new_expiration >= d.head_block_time(),
Expand Down
21 changes: 21 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,27 @@ BOOST_AUTO_TEST_CASE(limit_order_update_test)
}
}

BOOST_AUTO_TEST_CASE(limit_order_update_dust_test)
{
try {
ACTORS((nathan));
const auto& munee = create_user_issued_asset("MUNEE");

transfer(committee_account, nathan_id, asset(10000));
issue_uia(nathan, munee.amount(1000));

auto expiration = db.head_block_time() + 1000;
limit_order_id_type order_id = create_sell_order(nathan, asset(1000), munee.amount(100), expiration)->id;

GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-995)), fc::assert_exception);
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(1000000), munee.amount(100))), fc::assert_exception);
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(2000), munee.amount(100)), asset(-985)), fc::assert_exception);
} catch (fc::exception& e) {
edump((e.to_detail_string()));
throw;
}
}

BOOST_AUTO_TEST_CASE(limit_order_update_match_test)
{
try {
Expand Down

0 comments on commit 1c81eaf

Please sign in to comment.