From db84a492b9a2cf290f92a3987b59c11808138d56 Mon Sep 17 00:00:00 2001 From: theoreticalbts Date: Fri, 2 Oct 2015 10:53:31 -0400 Subject: [PATCH] Implement unit test for #350 --- tests/tests/operation_tests.cpp | 47 +++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 02cde4b7..5dec4eb4 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -317,6 +317,7 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 ) { price_feed feed; feed.settlement_price = settlement_price; + wdump( (feed.max_short_squeeze_price()) ); publish_feed( bitusd, feeder, feed ); }; @@ -332,22 +333,40 @@ BOOST_AUTO_TEST_CASE( black_swan_issue_346 ) BOOST_CHECK( idx.empty() ); }; - const asset_object& bitusd = setup_asset(); - top_up(); - set_price( bitusd, bitusd.amount(1) / core.amount(5) ); // $0.20 - borrow(borrower, bitusd.amount(100), asset(1000)); // 2x collat - transfer( borrower, settler, bitusd.amount(100) ); + { + const asset_object& bitusd = setup_asset(); + top_up(); + set_price( bitusd, bitusd.amount(1) / core.amount(5) ); // $0.20 + borrow(borrower, bitusd.amount(100), asset(1000)); // 2x collat + transfer( borrower, settler, bitusd.amount(100) ); - // drop to $0.02 and settle - BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() ); - set_price( bitusd, bitusd.amount(1) / core.amount(50) ); - BOOST_CHECK( bitusd.bitasset_data(db).has_settlement() ); - GRAPHENE_REQUIRE_THROW( borrow( borrower2, bitusd.amount(100), asset(10000) ), fc::exception ); - force_settle( settler, bitusd.amount(100) ); + // drop to $0.02 and settle + BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() ); + set_price( bitusd, bitusd.amount(1) / core.amount(50) ); // $0.02 + BOOST_CHECK( bitusd.bitasset_data(db).has_settlement() ); + GRAPHENE_REQUIRE_THROW( borrow( borrower2, bitusd.amount(100), asset(10000) ), fc::exception ); + force_settle( settler, bitusd.amount(100) ); - // wait for forced settlement to execute - // this would throw on Sep.18 testnet, see #346 - wait_for_settlement(); + // wait for forced settlement to execute + // this would throw on Sep.18 testnet, see #346 + wait_for_settlement(); + } + + // issue 350 + { + // ok, new asset + const asset_object& bitusd = setup_asset(); + top_up(); + set_price( bitusd, bitusd.amount(40) / core.amount(1000) ); // $0.04 + borrow( borrower, bitusd.amount(100), asset(5000) ); // 2x collat + transfer( borrower, seller, bitusd.amount(100) ); + limit_order_id_type oid_019 = create_sell_order( seller, bitusd.amount(39), core.amount(2000) )->id; // this order is at $0.019, we should not be able to match against it + limit_order_id_type oid_020 = create_sell_order( seller, bitusd.amount(40), core.amount(2000) )->id; // this order is at $0.020, we should be able to match against it + set_price( bitusd, bitusd.amount(21) / core.amount(1000) ); // $0.021 + BOOST_CHECK( !bitusd.bitasset_data(db).has_settlement() ); + BOOST_CHECK( db.find_object( oid_019 ) != nullptr ); + BOOST_CHECK( db.find_object( oid_020 ) == nullptr ); + } } catch( const fc::exception& e) { edump((e.to_detail_string()));