From 32589d169b18aa3e7fa435ce9c3bd289f09ba0a5 Mon Sep 17 00:00:00 2001 From: Eric Frias Date: Tue, 1 May 2018 12:28:40 -0400 Subject: [PATCH] Add test for placing bets using exposure --- tests/betting/betting_tests.cpp | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tests/betting/betting_tests.cpp b/tests/betting/betting_tests.cpp index 22599012..b2222993 100644 --- a/tests/betting/betting_tests.cpp +++ b/tests/betting/betting_tests.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include @@ -483,6 +484,43 @@ BOOST_AUTO_TEST_CASE(bet_reversal_test) FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE(bet_against_exposure_test) +{ + // test whether we can bet our entire balance in one direction, have it match, then reverse our bet (while having zero balance) + try + { + generate_blocks(1); + ACTORS( (alice)(bob) ); + CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0); + + transfer(account_id_type(), alice_id, asset(10000000)); + transfer(account_id_type(), bob_id, asset(10000000)); + int64_t alice_expected_balance = 10000000; + BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); + int64_t bob_expected_balance = 10000000; + BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance); + + // back with alice's entire balance + place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + alice_expected_balance -= 10000000; + BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); + + // lay with bob's entire balance, which fully matches bob's bet + place_bet(bob_id, capitals_win_market.id, bet_type::back, asset(10000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + bob_expected_balance -= 10000000; + BOOST_REQUIRE_EQUAL(get_balance(bob_id, asset_id_type()), bob_expected_balance); + + // reverse the bet + place_bet(alice_id, capitals_win_market.id, bet_type::lay, asset(20000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION); + BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); + + // try to re-reverse it, but go too far + BOOST_CHECK_THROW( place_bet(alice_id, capitals_win_market.id, bet_type::back, asset(30000000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION), fc::exception); + BOOST_REQUIRE_EQUAL(get_balance(alice_id, asset_id_type()), alice_expected_balance); + } + FC_LOG_AND_RETHROW() +} + BOOST_AUTO_TEST_CASE(persistent_objects_test) { try @@ -2107,6 +2145,10 @@ BOOST_AUTO_TEST_SUITE_END() boost::unit_test::test_suite* init_unit_test_suite(int argc, char* argv[]) { std::srand(time(NULL)); std::cout << "Random number generator seeded to " << time(NULL) << std::endl; + + // betting operations don't take effect until HARDFORK 1000 + GRAPHENE_TESTING_GENESIS_TIMESTAMP = HARDFORK_1000_TIME.sec_since_epoch(); + return nullptr; }