From 626b5cbb2323640979859922535e4e9f7a76e49f Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Fri, 19 Jun 2015 12:28:02 -0400 Subject: [PATCH] Fix broken update_mia test --- libraries/chain/asset.cpp | 4 ++- .../chain/include/graphene/chain/config.hpp | 3 +- tests/tests/operation_tests.cpp | 31 +++++++++---------- tests/tests/operation_tests2.cpp | 4 +-- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/libraries/chain/asset.cpp b/libraries/chain/asset.cpp index eea50d9d..ef73dd73 100644 --- a/libraries/chain/asset.cpp +++ b/libraries/chain/asset.cpp @@ -122,7 +122,9 @@ namespace graphene { namespace chain { { try { if( !settlement_price.is_null() ) settlement_price.validate(); - FC_ASSERT( maximum_short_squeeze_ratio >= 1000 ); + FC_ASSERT( maximum_short_squeeze_ratio >= GRAPHENE_MIN_COLLATERAL_RATIO ); + FC_ASSERT( maximum_short_squeeze_ratio <= GRAPHENE_MAX_COLLATERAL_RATIO ); + FC_ASSERT( maintenance_collateral_ratio >= GRAPHENE_MIN_COLLATERAL_RATIO ); FC_ASSERT( maintenance_collateral_ratio <= maximum_short_squeeze_ratio ); } FC_CAPTURE_AND_RETHROW( (*this) ) } diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index bab8c531..5ff44984 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -61,9 +61,10 @@ #define GRAPHENE_DEFAULT_MAX_ASSET_WHITELIST_AUTHORITIES 10 #define GRAPHENE_DEFAULT_MAX_ASSET_FEED_PUBLISHERS 10 +// These are NOT percentages #define GRAPHENE_MIN_COLLATERAL_RATIO 1001 // lower than this could result in divide by 0 #define GRAPHENE_MAX_COLLATERAL_RATIO 32000 // higher than this is unnecessary and may exceed int16 storage -#define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO 1500 // We require collateral of 1.5x or more +#define GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO 1500 // We require collateral of 1.5x or more #define GRAPHENE_DEFAULT_MAX_SHORT_SQUEEZE_RATIO 1750 // If there is a squeeze you are protected up to 1.75x... but black swan could occur first #define GRAPHENE_DEFAULT_MARGIN_PERIOD_SEC (30*60*60*24) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 3cf8b037..8196c263 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_logic_test ) try { asset usd(100,1); asset core(100,0); - price_feed feed; + price_feed feed; feed.settlement_price = usd / core; FC_ASSERT( usd * feed.settlement_price < usd * feed.maintenance_price() ); @@ -56,7 +56,7 @@ BOOST_AUTO_TEST_CASE( feed_limit_logic_test ) } } BOOST_AUTO_TEST_CASE( call_order_update_test ) -{ +{ try { ACTORS((dan)(sam)); const auto& bitusd = create_bitasset("BITUSD"); @@ -70,7 +70,7 @@ BOOST_AUTO_TEST_CASE( call_order_update_test ) FC_ASSERT( bitusd.bitasset_data(db).current_feed.settlement_price == current_feed.settlement_price ); - auto default_call_price = ~price::call_price( bitusd.amount(5000), asset(5000), 1750); + auto default_call_price = ~price::call_price( bitusd.amount(5000), asset(5000), 1750); BOOST_TEST_MESSAGE( "attempting to borrow using 2x collateral at 1:1 price now that there is a valid order" ); borrow( dan, bitusd.amount(5000), asset(10000), default_call_price ); @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE( call_order_update_test ) BOOST_REQUIRE_EQUAL( get_balance( dan, bitusd ), 5000 ); BOOST_REQUIRE_EQUAL( get_balance( dan, core ), 10000000 - 10000 ); - + // test just increasing collateral BOOST_TEST_MESSAGE( "increasing collateral" ); borrow( dan, bitusd.amount(0), asset(10000), default_call_price ); @@ -123,11 +123,11 @@ BOOST_AUTO_TEST_CASE( call_order_update_test ) cover( dan, bitusd.amount(0), asset(1000), default_call_price ); BOOST_TEST_MESSAGE( "attempting change call price without changing debt/collateral ratio" ); - default_call_price = ~price::call_price( bitusd.amount(100), asset(50), 1750); + default_call_price = ~price::call_price( bitusd.amount(100), asset(50), 1750); cover( dan, bitusd.amount(0), asset(0), default_call_price ); BOOST_TEST_MESSAGE( "attempting change call price to be below minimum for debt/collateral ratio" ); - default_call_price = ~price::call_price( bitusd.amount(100), asset(500), 1750); + default_call_price = ~price::call_price( bitusd.amount(100), asset(500), 1750); BOOST_REQUIRE_THROW( cover( dan, bitusd.amount(0), asset(0), default_call_price ), fc::exception ); } catch (fc::exception& e) { @@ -143,10 +143,10 @@ BOOST_AUTO_TEST_CASE( call_order_update_test ) * A margin call can happen in the following situation: * 0. there exists a bid above the mas short squeeze price * 1. highest bid is lower than the call price of an order - * 2. the asset is not a prediction market + * 2. the asset is not a prediction market * 3. there is a valid price feed * - * This test creates two scenarios: + * This test creates two scenarios: * a) when the bids are above the short squeese limit (should execute) * b) when the bids are below the short squeeze limit (should not execute) */ @@ -164,14 +164,14 @@ BOOST_AUTO_TEST_CASE( margin_call_limit_test ) transfer(genesis_account, borrower2_id, asset(init_balance)); update_feed_producers( bitusd, {feedproducer.id} ); - price_feed current_feed; + price_feed current_feed; current_feed.settlement_price = bitusd.amount( 100 ) / core.amount(100); - auto default_call_price = ~price::call_price( bitusd.amount(100), asset(100), 1750); + auto default_call_price = ~price::call_price( bitusd.amount(100), asset(100), 1750); - // starting out with price 1:1 + // starting out with price 1:1 publish_feed( bitusd, feedproducer, current_feed ); - // start out with 2:1 collateral + // start out with 2:1 collateral borrow( borrower, bitusd.amount(1000), asset(2000), default_call_price ); borrow( borrower2, bitusd.amount(1000), asset(4000), default_call_price ); @@ -456,8 +456,7 @@ BOOST_AUTO_TEST_CASE( create_mia ) } } -BOOST_AUTO_TEST_CASE_EXPECTED_FAILURES( broken_update_mia, 1 ) -BOOST_AUTO_TEST_CASE( broken_update_mia ) +BOOST_AUTO_TEST_CASE( update_mia ) { try { INVOKE(create_mia); @@ -477,7 +476,6 @@ BOOST_AUTO_TEST_CASE( broken_update_mia ) trx.operations.back() = op; PUSH_TX( db, trx, ~0 ); - //idump((bit_usd)); { asset_publish_feed_operation pop; pop.asset_id = bit_usd.get_id(); @@ -485,8 +483,9 @@ BOOST_AUTO_TEST_CASE( broken_update_mia ) price_feed feed; feed.settlement_price = price(bit_usd.amount(5), bit_usd.amount(5)); REQUIRE_THROW_WITH_VALUE(pop, feed, feed); - feed.settlement_price = price(bit_usd.amount(5), asset(5)); + feed.settlement_price = ~price(bit_usd.amount(5), asset(5)); REQUIRE_THROW_WITH_VALUE(pop, feed, feed); + feed.settlement_price = price(bit_usd.amount(5), asset(5)); pop.feed = feed; REQUIRE_THROW_WITH_VALUE(pop, feed.maintenance_collateral_ratio, 0); trx.operations.back() = pop; diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 4acf3425..5e35977d 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -356,8 +356,8 @@ BOOST_AUTO_TEST_CASE( mia_feeds ) op.publisher = dan_id; op.feed.settlement_price = ~price(asset(GRAPHENE_BLOCKCHAIN_PRECISION),bit_usd.amount(40)); - op.feed.maximum_short_squeeze_ratio = 1000; - op.feed.maintenance_collateral_ratio = 1000; + op.feed.maximum_short_squeeze_ratio = 1001; + op.feed.maintenance_collateral_ratio = 1001; trx.operations.back() = op; PUSH_TX( db, trx, ~0 );