Implement unit test for #350

This commit is contained in:
theoreticalbts 2015-10-02 10:53:31 -04:00
parent 9b4be66aca
commit db84a492b9

View file

@ -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()));