Skip to content

Commit

Permalink
Merge pull request #3 from bitshares/develop
Browse files Browse the repository at this point in the history
Adding all the changes from the develop branch
  • Loading branch information
manikey123 authored Jan 15, 2019
2 parents 3aecf1f + 596d7e9 commit a724f9d
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 32 deletions.
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ LIST(APPEND BOOST_COMPONENTS thread
system
filesystem
program_options
signals
serialization
chrono
unit_test_framework
Expand Down
4 changes: 1 addition & 3 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ dynamic_global_property_object database_api_impl::get_dynamic_global_properties(

vector<vector<account_id_type>> database_api::get_key_references( vector<public_key_type> key )const
{
FC_ASSERT(key.size() <= 100, "Number of keys must be 100 or less");
return my->get_key_references( key );
}

Expand Down Expand Up @@ -594,9 +595,6 @@ vector<vector<account_id_type>> database_api_impl::get_key_references( vector<pu
final_result.emplace_back( std::move(result) );
}

for( auto i : final_result )
subscribe_to_item(i);

return final_result;
}

Expand Down
8 changes: 6 additions & 2 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ 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 ) );
Expand Down
87 changes: 61 additions & 26 deletions tests/tests/app_util_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down Expand Up @@ -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<int64_t>::max();
int64_t n = -1;
Expand All @@ -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 );
Expand All @@ -214,32 +216,65 @@ 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(...) {}
if ( pr.base.amount == 0 || (pr.base.amount > 0 && pr.quote.amount >= 0 ) )
{
// 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( "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<int64_t>::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()

0 comments on commit a724f9d

Please sign in to comment.