From 35037685c75a8b7af031462b77f47c6a2f230768 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 27 Dec 2018 17:54:07 -0500 Subject: [PATCH 1/8] limit subscribed accounts to 100 --- libraries/app/database_api.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index f067a101e8..5e53c74713 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -259,7 +259,7 @@ class database_api_impl : public std::enable_shared_from_this bool _notify_remove_create = false; mutable fc::bloom_filter _subscribe_filter; - std::set _subscribed_accounts; + mutable std::set _subscribed_accounts; std::function _subscribe_callback; std::function _pending_trx_callback; std::function _block_applied_callback; @@ -594,8 +594,16 @@ vector> database_api_impl::get_key_references( vector Date: Tue, 1 Jan 2019 09:53:00 -0500 Subject: [PATCH 2/8] Do not subscribe to associated accounts --- libraries/app/database_api.cpp | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 5e53c74713..3afa4dc643 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -259,7 +259,7 @@ class database_api_impl : public std::enable_shared_from_this bool _notify_remove_create = false; mutable fc::bloom_filter _subscribe_filter; - mutable std::set _subscribed_accounts; + std::set _subscribed_accounts; std::function _subscribe_callback; std::function _pending_trx_callback; std::function _block_applied_callback; @@ -594,17 +594,6 @@ vector> database_api_impl::get_key_references( vector Date: Fri, 4 Jan 2019 08:18:06 -0500 Subject: [PATCH 3/8] removed boost signals (no longer used) --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index faf3a59f6d..948d7412cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,7 +48,6 @@ LIST(APPEND BOOST_COMPONENTS thread system filesystem program_options - signals serialization chrono unit_test_framework From 53feeff43874a85bddb052f5d32befe9700002ae Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 7 Jan 2019 13:58:55 -0500 Subject: [PATCH 4/8] Reject get_key_references with > 100 keys --- libraries/app/database_api.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index 3afa4dc643..28182fd08d 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -539,6 +539,7 @@ dynamic_global_property_object database_api_impl::get_dynamic_global_properties( vector> database_api::get_key_references( vector key )const { + FC_ASSERT(key.size() <= 100, "Number of keys must be 100 or less"); return my->get_key_references( key ); } From b4bd649268402de7b8cf8d94f386d42685c4ea4b Mon Sep 17 00:00:00 2001 From: John Jones Date: Tue, 8 Jan 2019 17:05:53 -0500 Subject: [PATCH 5/8] Make sure price_to_string works and throws as it should --- tests/tests/app_util_tests.cpp | 54 +++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/tests/tests/app_util_tests.cpp b/tests/tests/app_util_tests.cpp index 9b913fd7cd..71e750cc0a 100644 --- a/tests/tests/app_util_tests.cpp +++ b/tests/tests/app_util_tests.cpp @@ -214,30 +214,36 @@ BOOST_AUTO_TEST_CASE(price_to_string_test) { GRAPHENE_REQUIRE_THROW( price_to_string( p[i][j], 0, 20 ), fc::exception ); } try { - idump( (i) (j) (p[i][j]) ); - idump( - (price_to_string(p[i][j],0,0)) - (price_to_string(p[i][j],0,1)) - (price_to_string(p[i][j],0,2)) - (price_to_string(p[i][j],0,8)) - (price_to_string(p[i][j],0,19)) - (price_to_string(p[i][j],1,0)) - (price_to_string(p[i][j],1,15)) - (price_to_string(p[i][j],2,6)) - (price_to_string(p[i][j],2,10)) - (price_to_string(p[i][j],5,0)) - (price_to_string(p[i][j],9,1)) - (price_to_string(p[i][j],9,9)) - (price_to_string(p[i][j],9,19)) - (price_to_string(p[i][j],18,10)) - (price_to_string(p[i][j],18,13)) - (price_to_string(p[i][j],18,19)) - (price_to_string(p[i][j],19,0)) - (price_to_string(p[i][j],19,7)) - (price_to_string(p[i][j],19,19)) - (price_diff_percent_string(p[i][j],p[j][i])) - ); - } catch(...) {} + price pr = p[i][j]; + idump( (i) (j) (pr) ); + if ( pr.base.amount == 0 || (pr.base.amount > 0 && pr.quote.amount >= 0 ) ) + { + idump( (price_to_string( pr ,0,0)) ); + idump( (price_to_string( pr ,0,1)) ); + idump( (price_to_string( pr ,0,2)) ); + idump( (price_to_string( pr ,0,8)) ); + idump( (price_to_string( pr ,0,19)) ); + idump( (price_to_string( pr ,1,0)) ); + idump( (price_to_string( pr ,1,15)) ); + idump( (price_to_string( pr ,2,6)) ); + idump( (price_to_string( pr ,2,10)) ); + idump( (price_to_string( pr ,5,0)) ); + idump( (price_to_string( pr ,9,1)) ); + idump( (price_to_string( pr ,9,9)) ); + idump( (price_to_string( pr ,9,19)) ); + idump( (price_to_string( pr ,18,10)) ); + idump( (price_to_string( pr ,18,13)) ); + idump( (price_to_string( pr ,18,19)) ); + idump( (price_to_string( pr ,19,0)) ); + idump( (price_to_string( pr ,19,7)) ); + idump( (price_to_string( pr ,19,19)) ); + idump( (price_diff_percent_string( pr ,p[j][i])) ); + } else { + GRAPHENE_REQUIRE_THROW( price_to_string( pr, 0, 0 ), fc::exception ); + } + } catch(...) { + BOOST_FAIL( "Failure to log price_to_string" ); + } } } From 834e47635d441464043a1abb3dc464ae2c0e0fb4 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 11 Jan 2019 10:20:14 -0500 Subject: [PATCH 6/8] Separate throws from edge cases that should work --- tests/tests/app_util_tests.cpp | 79 +++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 25 deletions(-) diff --git a/tests/tests/app_util_tests.cpp b/tests/tests/app_util_tests.cpp index 71e750cc0a..b85c9a3e8d 100644 --- a/tests/tests/app_util_tests.cpp +++ b/tests/tests/app_util_tests.cpp @@ -32,7 +32,7 @@ using namespace graphene::chain; using namespace graphene::chain::test; using namespace graphene::app; -BOOST_FIXTURE_TEST_SUITE(app_util_tests, database_fixture) +BOOST_AUTO_TEST_SUITE(app_util_tests) BOOST_AUTO_TEST_CASE(uint128_amount_to_string_test) { @@ -179,7 +179,7 @@ BOOST_AUTO_TEST_CASE(uint128_amount_to_string_test) { } -BOOST_AUTO_TEST_CASE(price_to_string_test) { +BOOST_AUTO_TEST_CASE(price_to_string_throws) { int64_t m = std::numeric_limits::max(); int64_t n = -1; @@ -194,8 +194,10 @@ BOOST_AUTO_TEST_CASE(price_to_string_test) { p[i][j] = price( asset( a[i] ), asset( a[j] ) ); for( int i = 0; i < 11; ++i ) + { for( int j = 0; j < 11; ++j ) { + price pr = p[i][j]; if( i == 0 ) { GRAPHENE_REQUIRE_THROW( price_to_string( p[i][j], 0, 0 ), fc::exception ); @@ -214,38 +216,65 @@ BOOST_AUTO_TEST_CASE(price_to_string_test) { GRAPHENE_REQUIRE_THROW( price_to_string( p[i][j], 0, 20 ), fc::exception ); } try { - price pr = p[i][j]; - idump( (i) (j) (pr) ); if ( pr.base.amount == 0 || (pr.base.amount > 0 && pr.quote.amount >= 0 ) ) { - idump( (price_to_string( pr ,0,0)) ); - idump( (price_to_string( pr ,0,1)) ); - idump( (price_to_string( pr ,0,2)) ); - idump( (price_to_string( pr ,0,8)) ); - idump( (price_to_string( pr ,0,19)) ); - idump( (price_to_string( pr ,1,0)) ); - idump( (price_to_string( pr ,1,15)) ); - idump( (price_to_string( pr ,2,6)) ); - idump( (price_to_string( pr ,2,10)) ); - idump( (price_to_string( pr ,5,0)) ); - idump( (price_to_string( pr ,9,1)) ); - idump( (price_to_string( pr ,9,9)) ); - idump( (price_to_string( pr ,9,19)) ); - idump( (price_to_string( pr ,18,10)) ); - idump( (price_to_string( pr ,18,13)) ); - idump( (price_to_string( pr ,18,19)) ); - idump( (price_to_string( pr ,19,0)) ); - idump( (price_to_string( pr ,19,7)) ); - idump( (price_to_string( pr ,19,19)) ); - idump( (price_diff_percent_string( pr ,p[j][i])) ); + // idump( (i) (j) (pr) ); // for debugging + // These should not throw + // TODO: Verify results + BOOST_CHECK( !price_to_string( pr ,0,0).empty() ); + BOOST_CHECK( !price_to_string( pr ,0,1).empty() ); + BOOST_CHECK( !price_to_string( pr ,0,2).empty() ); + BOOST_CHECK( !price_to_string( pr ,0,8).empty() ); + BOOST_CHECK( !price_to_string( pr ,0,19).empty() ); + BOOST_CHECK( !price_to_string( pr ,1,0).empty() ); + BOOST_CHECK( !price_to_string( pr ,1,15).empty() ); + BOOST_CHECK( !price_to_string( pr ,2,6).empty() ); + BOOST_CHECK( !price_to_string( pr ,2,10).empty() ); + BOOST_CHECK( !price_to_string( pr ,5,0).empty() ); + BOOST_CHECK( !price_to_string( pr ,9,1).empty() ); + BOOST_CHECK( !price_to_string( pr ,9,9).empty() ); + BOOST_CHECK( !price_to_string( pr ,9,19).empty() ); + BOOST_CHECK( !price_to_string( pr ,18,10).empty() ); + BOOST_CHECK( !price_to_string( pr ,18,13).empty() ); + BOOST_CHECK( !price_to_string( pr ,18,19).empty() ); + BOOST_CHECK( !price_to_string( pr ,19,0).empty() ); + BOOST_CHECK( !price_to_string( pr ,19,7).empty() ); + BOOST_CHECK( !price_to_string( pr ,19,19).empty() ); + price new_price = p[j][i]; + if (pr.quote.amount >= 0) + BOOST_CHECK( !price_diff_percent_string( pr, new_price ).empty() ); + else + GRAPHENE_REQUIRE_THROW( price_diff_percent_string( pr, new_price ), fc::exception ); } else { GRAPHENE_REQUIRE_THROW( price_to_string( pr, 0, 0 ), fc::exception ); } + } catch(fc::exception& fcx) { + BOOST_FAIL( "FC Exception logging price_to_string: " + fcx.to_detail_string() ); } catch(...) { - BOOST_FAIL( "Failure to log price_to_string" ); + BOOST_FAIL( "Uncaught exception in price_to_string. i=" + std::to_string(i) + " j=" + std::to_string(j)); } } + } +} +/** + * Verify that price_to_string comes back with the correct results. Put edge cases here. + */ +BOOST_AUTO_TEST_CASE(price_to_string_verify) +{ + try + { + BOOST_CHECK_EQUAL( price_to_string( price{ asset(1), asset(1) }, 0, 0 ), "1" ); + BOOST_CHECK_EQUAL( price_to_string( price{ asset(10), asset(10) }, 0, 0), "1" ); + int64_t mx = std::numeric_limits::max(); + BOOST_CHECK_EQUAL( price_to_string( price{ asset(mx), asset(mx) }, 0, 0), "1" ); + BOOST_CHECK_EQUAL( price_to_string( price{ asset(1), asset(mx) }, 0, 0), "0.0000000000000000001" ); + BOOST_CHECK_EQUAL( price_to_string( price{ asset(mx), asset(1) }, 0, 0), "9223372036854775807" ); + } + catch (fc::exception& fx) + { + BOOST_FAIL( "FC Exception: " + fx.to_detail_string() ); + } } BOOST_AUTO_TEST_SUITE_END() From 02299573e5d1ae0d5bdcf11ce17b124c405c9e97 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 14 Jan 2019 16:08:27 -0500 Subject: [PATCH 7/8] Added human-readable message to assert --- libraries/chain/market_evaluator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 62dfc7c7b4..9badba481b 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -49,9 +49,11 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o _receive_asset = &op.min_to_receive.asset_id(d); if( _sell_asset->options.whitelist_markets.size() ) - FC_ASSERT( _sell_asset->options.whitelist_markets.find(_receive_asset->id) != _sell_asset->options.whitelist_markets.end() ); + FC_ASSERT( _sell_asset->options.whitelist_markets.find(_receive_asset->id) != _sell_asset->options.whitelist_markets.end(), + "This market has not been whitelisted." ); if( _sell_asset->options.blacklist_markets.size() ) - FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end() ); + FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end(), + "This market has been blacklisted." ); FC_ASSERT( is_authorized_asset( d, *_seller, *_sell_asset ) ); FC_ASSERT( is_authorized_asset( d, *_seller, *_receive_asset ) ); From 28875e1435164256723d412e2165239cfc9de249 Mon Sep 17 00:00:00 2001 From: John Jones Date: Mon, 14 Jan 2019 16:26:33 -0500 Subject: [PATCH 8/8] fixed long lines --- libraries/chain/market_evaluator.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 9badba481b..58dd0ac53f 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -49,10 +49,12 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o _receive_asset = &op.min_to_receive.asset_id(d); if( _sell_asset->options.whitelist_markets.size() ) - FC_ASSERT( _sell_asset->options.whitelist_markets.find(_receive_asset->id) != _sell_asset->options.whitelist_markets.end(), + FC_ASSERT( _sell_asset->options.whitelist_markets.find(_receive_asset->id) + != _sell_asset->options.whitelist_markets.end(), "This market has not been whitelisted." ); if( _sell_asset->options.blacklist_markets.size() ) - FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) == _sell_asset->options.blacklist_markets.end(), + FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id) + == _sell_asset->options.blacklist_markets.end(), "This market has been blacklisted." ); FC_ASSERT( is_authorized_asset( d, *_seller, *_sell_asset ) );