Skip to content

Commit 269a16d

Browse files
committed
Reduce log level of exceptions in order_update_op
1 parent 8898b5a commit 269a16d

File tree

5 files changed

+48
-29
lines changed

5 files changed

+48
-29
lines changed

libraries/chain/exceptions.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ namespace graphene { namespace chain {
8484
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( insufficient_balance, limit_order_create, 6,
8585
"Insufficient balance" )
8686

87+
GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_update );
88+
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_update, 1, "Order does not exist" )
89+
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_update, 2, "Order owned by someone else" )
90+
8791
GRAPHENE_IMPLEMENT_OP_BASE_EXCEPTIONS( limit_order_cancel );
8892
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_cancel, 1, "Order does not exist" )
8993
GRAPHENE_IMPLEMENT_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_cancel, 2, "Order owned by someone else" )

libraries/chain/include/graphene/chain/exceptions.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ namespace graphene { namespace chain {
138138
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( receiving_asset_unauthorized, limit_order_create, 5 )
139139
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( insufficient_balance, limit_order_create, 6 )
140140

141+
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_update );
142+
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_update, 1 )
143+
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_update, 2 )
144+
141145
GRAPHENE_DECLARE_OP_BASE_EXCEPTIONS( limit_order_cancel );
142146
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( nonexist_order, limit_order_cancel, 1 )
143147
GRAPHENE_DECLARE_OP_EVALUATE_EXCEPTION( owner_mismatch, limit_order_cancel, 2 )

libraries/chain/market_evaluator.cpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,19 @@ void_result limit_order_update_evaluator::do_evaluate(const limit_order_update_o
156156
{
157157
const database& d = db();
158158
FC_ASSERT( HARDFORK_CORE_1604_PASSED( d.head_block_time() ) , "Operation has not activated yet");
159-
_order = &o.order(d);
159+
160+
_order = d.find( o.order );
161+
162+
GRAPHENE_ASSERT( _order != nullptr,
163+
limit_order_update_nonexist_order,
164+
"Limit order ${oid} does not exist, cannot update",
165+
("oid", o.order) );
160166

161167
// Check this is my order
162-
FC_ASSERT(o.seller == _order->seller, "Cannot update someone else's order");
168+
GRAPHENE_ASSERT( o.seller == _order->seller,
169+
limit_order_update_owner_mismatch,
170+
"Limit order ${oid} is owned by someone else, cannot update",
171+
("oid", o.order) );
163172

164173
// Check new price is compatible and appropriate
165174
if (o.new_price) {

libraries/net/node.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,8 @@ namespace graphene { namespace net { namespace detail {
36303630
case graphene::chain::limit_order_create_selling_asset_unauthorized::code_enum::code_value :
36313631
case graphene::chain::limit_order_create_receiving_asset_unauthorized::code_enum::code_value :
36323632
case graphene::chain::limit_order_create_insufficient_balance::code_enum::code_value :
3633+
case graphene::chain::limit_order_update_nonexist_order::code_enum::code_value :
3634+
case graphene::chain::limit_order_update_owner_mismatch::code_enum::code_value :
36333635
case graphene::chain::limit_order_cancel_nonexist_order::code_enum::code_value :
36343636
case graphene::chain::limit_order_cancel_owner_mismatch::code_enum::code_value :
36353637
case graphene::chain::liquidity_pool_exchange_unfillable_price::code_enum::code_value :

tests/tests/operation_tests.cpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,52 @@ BOOST_AUTO_TEST_CASE(limit_order_update_test)
139139
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
140140

141141
// Cannot update order without changing anything
142-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id), fc::assert_exception);
142+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id), fc::exception);
143143
// Cannot update order to use inverted price assets
144-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(bitusd.amount(2), asset(1))), fc::assert_exception);
144+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(bitusd.amount(2), asset(1))), fc::exception);
145145
// Cannot update order to use negative price
146-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(-1), bitusd.amount(2))), fc::assert_exception);
147-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(1), bitusd.amount(-2))), fc::assert_exception);
146+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(-1), bitusd.amount(2))), fc::exception);
147+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(1), bitusd.amount(-2))), fc::exception);
148148
// Cannot update order to use different assets
149149
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(bitusd.amount(2), munee.amount(1))),
150-
fc::assert_exception);
150+
fc::exception);
151151
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(munee.amount(2), bitusd.amount(1))),
152-
fc::assert_exception);
153-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(2), munee.amount(1))), fc::assert_exception);
152+
fc::exception);
153+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(2), munee.amount(1))), fc::exception);
154154
// Cannot update order to expire in the past
155-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, {}, db.head_block_time() - 10), fc::assert_exception);
155+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, {}, db.head_block_time() - 10), fc::exception);
156156
// Cannot update order with a zero delta
157-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset()), fc::assert_exception);
157+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset()), fc::exception);
158158
// Cannot update order to add more funds than seller has
159-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(501)), fc::assert_exception);
159+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(501)), fc::exception);
160160
// Cannot update order to remove more funds than order has
161-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-501)), fc::assert_exception);
161+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-501)), fc::exception);
162162
// Cannot update order to remove all funds in order
163-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-500)), fc::assert_exception);
163+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-500)), fc::exception);
164164
// Cannot update order to add or remove different kind of funds
165-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, bitusd.amount(50)), fc::assert_exception);
166-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, bitusd.amount(-50)), fc::assert_exception);
167-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, munee.amount(50)), fc::assert_exception);
168-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, munee.amount(-50)), fc::assert_exception);
165+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, bitusd.amount(50)), fc::exception);
166+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, bitusd.amount(-50)), fc::exception);
167+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, munee.amount(50)), fc::exception);
168+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, munee.amount(-50)), fc::exception);
169169

170170
// Cannot update someone else's order
171171
limit_order_update_operation louop = make_limit_order_update_op( dan_id, order_id, {}, asset(-1) );
172172
trx.operations.clear();
173173
trx.operations.push_back( louop );
174-
GRAPHENE_REQUIRE_THROW( PUSH_TX(db, trx, ~0), fc::assert_exception );
174+
GRAPHENE_REQUIRE_THROW( PUSH_TX(db, trx, ~0), fc::exception );
175175
// Can propose
176176
propose( louop );
177177

178178
// Cannot update an order which does not exist
179179
louop = make_limit_order_update_op( nathan_id, order_id + 1, {}, asset(-1) );
180180
trx.operations.clear();
181181
trx.operations.push_back( louop );
182-
GRAPHENE_REQUIRE_THROW( PUSH_TX(db, trx, ~0), fc::assert_exception );
182+
GRAPHENE_REQUIRE_THROW( PUSH_TX(db, trx, ~0), fc::exception );
183183

184184
// Try changing price
185185
sell_price.base = asset(501);
186186
// Cannot update base amount in the new price to be more than the amount for sale
187-
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, sell_price), fc::assert_exception );
187+
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, sell_price), fc::exception );
188188
sell_price.base = asset(500);
189189
BOOST_REQUIRE_EQUAL(fc::json::to_string(order_id(db).sell_price), fc::json::to_string(sell_price));
190190
sell_price.base = asset(499);
@@ -203,7 +203,7 @@ BOOST_AUTO_TEST_CASE(limit_order_update_test)
203203
update_limit_order(order_id, {}, {}, expiration);
204204
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
205205
// Cannot change expiration to a time in the past
206-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, {}, db.head_block_time() - 1 ), fc::assert_exception);
206+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, {}, db.head_block_time() - 1 ), fc::exception);
207207

208208
// Try adding funds
209209
update_limit_order(order_id, {}, asset(50));
@@ -283,7 +283,7 @@ BOOST_AUTO_TEST_CASE( limit_order_update_asset_authorization_test )
283283
PUSH_TX( db, trx, ~0 );
284284

285285
// Cannot update order
286-
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::assert_exception );
286+
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::exception );
287287
BOOST_REQUIRE_EQUAL(order_id(db).for_sale.value, 49);
288288
BOOST_REQUIRE_EQUAL(fc::json::to_string(order_id(db).sell_price), fc::json::to_string(sell_price));
289289
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
@@ -328,7 +328,7 @@ BOOST_AUTO_TEST_CASE( limit_order_update_asset_authorization_test )
328328
PUSH_TX( db, trx, ~0 );
329329

330330
// Cannot update order
331-
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::assert_exception );
331+
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::exception );
332332
BOOST_REQUIRE_EQUAL(order_id(db).for_sale.value, 48);
333333
BOOST_REQUIRE_EQUAL(fc::json::to_string(order_id(db).sell_price), fc::json::to_string(sell_price));
334334
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
@@ -359,7 +359,7 @@ BOOST_AUTO_TEST_CASE( limit_order_update_asset_authorization_test )
359359
PUSH_TX( db, trx, ~0 );
360360

361361
// Cannot update order
362-
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::assert_exception );
362+
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::exception );
363363
BOOST_REQUIRE_EQUAL(order_id(db).for_sale.value, 47);
364364
BOOST_REQUIRE_EQUAL(fc::json::to_string(order_id(db).sell_price), fc::json::to_string(sell_price));
365365
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
@@ -391,7 +391,7 @@ BOOST_AUTO_TEST_CASE( limit_order_update_asset_authorization_test )
391391
PUSH_TX( db, trx, ~0 );
392392

393393
// Cannot update order
394-
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::assert_exception );
394+
GRAPHENE_REQUIRE_THROW( update_limit_order(order_id, {}, munee.amount(-1)), fc::exception );
395395
BOOST_REQUIRE_EQUAL(order_id(db).for_sale.value, 46);
396396
BOOST_REQUIRE_EQUAL(fc::json::to_string(order_id(db).sell_price), fc::json::to_string(sell_price));
397397
BOOST_REQUIRE_EQUAL(order_id(db).expiration.sec_since_epoch(), expiration.sec_since_epoch());
@@ -429,11 +429,11 @@ BOOST_AUTO_TEST_CASE(limit_order_update_dust_test)
429429
auto expiration = db.head_block_time() + 1000;
430430
limit_order_id_type order_id = create_sell_order(nathan, asset(1000), munee.amount(100), expiration)->get_id();
431431

432-
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-995)), fc::assert_exception);
432+
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, {}, asset(-995)), fc::exception);
433433
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(1000000), munee.amount(100))),
434-
fc::assert_exception);
434+
fc::exception);
435435
GRAPHENE_REQUIRE_THROW(update_limit_order(order_id, price(asset(2000), munee.amount(100)), asset(-985)),
436-
fc::assert_exception);
436+
fc::exception);
437437

438438
generate_block();
439439

0 commit comments

Comments
 (0)