@@ -2088,6 +2088,109 @@ BOOST_AUTO_TEST_CASE( collateral_fee_of_instant_settlement_test )
20882088
20892089} FC_LOG_AND_RETHROW () }
20902090
2091+ // / Tests instant settlement:
2092+ // / * After hf core-2591, for prediction markets, forced-settlements are NOT filled at margin call order price (MCOP)
2093+ BOOST_AUTO_TEST_CASE ( pm_instant_settlement_price_test )
2094+ { try {
2095+
2096+ // Advance to a recent hard fork
2097+ generate_blocks (HARDFORK_CORE_2582_TIME );
2098+ generate_block ();
2099+
2100+ // multiple passes,
2101+ // i == 0 : before hf core-2591
2102+ // i == 1 : after hf core-2591
2103+ for ( int i = 0 ; i < 2 ; ++ i )
2104+ {
2105+ idump ( (i) );
2106+
2107+ if ( 1 == i )
2108+ {
2109+ // Advance to core-2591 hard fork
2110+ generate_blocks (HARDFORK_CORE_2591_TIME );
2111+ generate_block ();
2112+ }
2113+
2114+ set_expiration ( db, trx );
2115+
2116+ ACTORS ((judge)(alice)(feeder));
2117+
2118+ const auto & pmark = create_prediction_market (" PMARK" , judge_id);
2119+ const auto & core = asset_id_type ()(db);
2120+
2121+ asset_id_type pm_id = pmark.get_id ();
2122+
2123+ int64_t init_balance (1000000 );
2124+ transfer (committee_account, judge_id, asset (init_balance));
2125+ transfer (committee_account, alice_id, asset (init_balance));
2126+
2127+ BOOST_TEST_MESSAGE ( " Open position with equal collateral" );
2128+ borrow ( alice, pmark.amount (1000 ), asset (1000 ) );
2129+
2130+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, pm_id ), 1000 );
2131+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, asset_id_type () ), init_balance - 1000 );
2132+
2133+ // add a price feed publisher and publish a feed
2134+ update_feed_producers ( pm_id, { feeder_id } );
2135+
2136+ price_feed f;
2137+ f.settlement_price = price ( asset (100 ,pm_id), asset (1 ) );
2138+ f.core_exchange_rate = price ( asset (100 ,pm_id), asset (1 ) );
2139+ f.maintenance_collateral_ratio = 1850 ;
2140+ f.maximum_short_squeeze_ratio = 1250 ;
2141+
2142+ uint16_t feed_icr = 1900 ;
2143+
2144+ publish_feed ( pm_id, feeder_id, f, feed_icr );
2145+
2146+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, pm_id ), 1000 );
2147+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, asset_id_type () ), init_balance - 1000 );
2148+
2149+ BOOST_TEST_MESSAGE ( " Globally settling" );
2150+ force_global_settle ( pmark, pmark.amount (1 ) / core.amount (1 ) );
2151+
2152+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, pm_id ), 1000 );
2153+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, asset_id_type () ), init_balance - 1000 );
2154+
2155+ // alice settles
2156+ auto result = force_settle ( alice, asset (300 , pm_id) );
2157+ auto op_result = result.get <extendable_operation_result>().value ;
2158+
2159+ BOOST_CHECK ( !op_result.new_objects .valid () ); // force settlement order not created
2160+
2161+ BOOST_REQUIRE ( op_result.paid .valid () && 1U == op_result.paid ->size () );
2162+ BOOST_CHECK ( *op_result.paid ->begin () == asset ( 300 , pm_id ) );
2163+ BOOST_REQUIRE ( op_result.received .valid () && 1U == op_result.received ->size () );
2164+ BOOST_CHECK ( *op_result.received ->begin () == asset ( 300 ) );
2165+ BOOST_REQUIRE ( op_result.fees .valid () && 1U == op_result.fees ->size () );
2166+ BOOST_CHECK ( *op_result.fees ->begin () == asset ( 0 ) );
2167+
2168+ auto check_result = [&]
2169+ {
2170+ BOOST_CHECK ( !pm_id (db).bitasset_data (db).has_individual_settlement () );
2171+ BOOST_CHECK ( pm_id (db).bitasset_data (db).has_settlement () );
2172+ BOOST_CHECK_EQUAL ( pm_id (db).bitasset_data (db).settlement_fund .value , 700 );
2173+
2174+ BOOST_CHECK_EQUAL ( pm_id (db).dynamic_data (db).accumulated_collateral_fees .value , 0 );
2175+
2176+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, pm_id ), 700 );
2177+ BOOST_CHECK_EQUAL ( get_balance ( alice_id, asset_id_type () ), init_balance - 700 );
2178+ };
2179+
2180+ check_result ();
2181+
2182+ BOOST_TEST_MESSAGE ( " Generate a block" );
2183+ generate_block ();
2184+
2185+ check_result ();
2186+
2187+ // reset
2188+ db.pop_block ();
2189+
2190+ } // for i
2191+
2192+ } FC_LOG_AND_RETHROW () }
2193+
20912194/* *
20922195 * Test case to reproduce https://github.com/bitshares/bitshares-core/issues/1883.
20932196 * When there is only one fill_order object in the ticker rolling buffer, it should only be rolled out once.
0 commit comments