@@ -840,6 +840,68 @@ BOOST_AUTO_TEST_CASE( prediction_market_resolves_to_0 )
840
840
}
841
841
}
842
842
843
+ /* **
844
+ * Prediction markets should not suffer a black swan (Issue #460)
845
+ */
846
+ BOOST_AUTO_TEST_CASE ( prediction_market_black_swan )
847
+ {
848
+ try {
849
+ ACTORS ((judge)(dan)(nathan));
850
+
851
+ // progress to recent hardfork
852
+ generate_blocks ( HARDFORK_CORE_1270_TIME );
853
+ set_expiration ( db, trx );
854
+
855
+ const auto & pmark = create_prediction_market (" PMARK" , judge_id);
856
+
857
+ int64_t init_balance (1000000 );
858
+ transfer (committee_account, judge_id, asset (init_balance));
859
+ transfer (committee_account, dan_id, asset (init_balance));
860
+
861
+ update_feed_producers ( pmark, { judge_id });
862
+ price_feed feed;
863
+ feed.settlement_price = asset ( 1 , pmark.id ) / asset ( 1 );
864
+ publish_feed ( pmark, judge, feed );
865
+
866
+ borrow ( dan, pmark.amount (1000 ), asset (1000 ) );
867
+
868
+ // feed a price that will cause a black swan
869
+ feed.settlement_price = asset ( 1 , pmark.id ) / asset ( 1000 );
870
+ publish_feed ( pmark, judge, feed );
871
+
872
+ // verify a black swan happened
873
+ GRAPHENE_REQUIRE_THROW (borrow ( dan, pmark.amount (1000 ), asset (1000 ) ), fc::exception );
874
+ trx.clear ();
875
+
876
+ // progress past hardfork
877
+ generate_blocks ( HARDFORK_CORE_460_TIME + db.get_global_properties ().parameters .maintenance_interval );
878
+ set_expiration ( db, trx );
879
+
880
+ // create another prediction market to test the hardfork
881
+ const auto & pmark2 = create_prediction_market (" PMARKII" , judge_id);
882
+ update_feed_producers ( pmark2, { judge_id });
883
+ price_feed feed2;
884
+ feed2.settlement_price = asset ( 1 , pmark2.id ) / asset ( 1 );
885
+ publish_feed ( pmark2, judge, feed2 );
886
+
887
+ borrow ( dan, pmark2.amount (1000 ), asset (1000 ) );
888
+
889
+ // feed a price that would have caused a black swan
890
+ feed2.settlement_price = asset ( 1 , pmark2.id ) / asset ( 1000 );
891
+ publish_feed ( pmark2, judge, feed2 );
892
+
893
+ // verify a black swan did not happen
894
+ borrow ( dan, pmark2.amount (1000 ), asset (1000 ) );
895
+
896
+ generate_block (~database::skip_transaction_dupe_check);
897
+ generate_blocks ( db.get_dynamic_global_properties ().next_maintenance_time );
898
+ generate_block ();
899
+ } catch ( const fc::exception & e) {
900
+ edump ((e.to_detail_string ()));
901
+ throw ;
902
+ }
903
+ }
904
+
843
905
BOOST_AUTO_TEST_CASE ( create_account_test )
844
906
{
845
907
try {
0 commit comments