diff --git a/libraries/chain/betting_market_object.cpp b/libraries/chain/betting_market_object.cpp index ca008915..6cda06ee 100644 --- a/libraries/chain/betting_market_object.cpp +++ b/libraries/chain/betting_market_object.cpp @@ -8,13 +8,13 @@ namespace graphene { namespace chain { if (back_or_lay == bet_type::back) { - amount_to_match_128 *= backer_multiplier - GRAPHENE_100_PERCENT; - amount_to_match_128 /= GRAPHENE_100_PERCENT; + amount_to_match_128 *= backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION; + amount_to_match_128 /= GRAPHENE_BETTING_ODDS_PRECISION; } else { - amount_to_match_128 *= GRAPHENE_100_PERCENT; - amount_to_match_128 /= backer_multiplier - GRAPHENE_100_PERCENT; + amount_to_match_128 *= GRAPHENE_BETTING_ODDS_PRECISION; + amount_to_match_128 /= backer_multiplier - GRAPHENE_BETTING_ODDS_PRECISION; } return amount_to_match_128.to_uint64(); } diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 67e4dd0d..9fa63545 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -199,6 +200,18 @@ void database_fixture::verify_asset_supplies( const database& db ) for( const fba_accumulator_object& fba : db.get_index_type< simple_index< fba_accumulator_object > >() ) total_balances[ asset_id_type() ] += fba.accumulated_fba_fees; + for (const bet_object& o : db.get_index_type().indices()) + { + total_balances[o.amount_to_bet.asset_id] += o.amount_to_bet.amount; + total_balances[o.amount_to_bet.asset_id] += o.amount_reserved_for_fees; + } + for (const betting_market_position_object& o : db.get_index_type().indices()) + { + const betting_market_object& betting_market = o.betting_market_id(db); + total_balances[betting_market.asset_id] += o.pay_if_canceled; + total_balances[betting_market.asset_id] += o.fees_collected; + } + total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget; for( const auto& item : total_debts ) diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index 6fb1cf71..0661109d 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include @@ -1626,7 +1627,6 @@ BOOST_AUTO_TEST_CASE( buyback ) BOOST_AUTO_TEST_CASE( peerplays_sport_create_test ) { ACTORS( (alice)(bob)(chloe)(dan)(izzy)(philbin) ); - upgrade_to_lifetime_member(philbin_id); try { @@ -1800,6 +1800,49 @@ BOOST_AUTO_TEST_CASE( peerplays_sport_create_test ) } } } + + // give alice and bob 10M each + transfer(account_id_type(), alice_id, asset(10000000)); + transfer(account_id_type(), bob_id, asset(10000000)); + { + // get a betting market to run tests in. It doesn't relly matter what it is, but in this test it will be "caps win". + const betting_market_object& market = *db.get_index_type().indices().begin(); + + { + // have bob lay a bet at 1:1 odds + signed_transaction tx; + bet_place_operation bet_op; + bet_op.bettor_id = bob_id; + bet_op.betting_market_id = market.id; + bet_op.amount_to_bet = asset(1000000, asset_id_type()); + bet_op.backer_multiplier = 2 * GRAPHENE_BETTING_ODDS_PRECISION; + bet_op.amount_reserved_for_fees = 1000000 / 50; // chain defaults to 2% fees + bet_op.back_or_lay = bet_type::lay; + tx.operations.push_back(bet_op); + db.current_fee_schedule().set_fee(tx.operations.back()); + set_expiration(db, tx); + sign(tx, bob_private_key); + db.push_transaction(tx); + } + + { + // have alice back a matching bet at 1:1 odds + signed_transaction tx; + bet_place_operation bet_op; + bet_op.bettor_id = alice_id; + bet_op.betting_market_id = market.id; + bet_op.amount_to_bet = asset(1000000, asset_id_type()); + bet_op.backer_multiplier = 2 * GRAPHENE_BETTING_ODDS_PRECISION; + bet_op.amount_reserved_for_fees = 1000000 / 50; // chain defaults to 2% fees + bet_op.back_or_lay = bet_type::back; + tx.operations.push_back(bet_op); + db.current_fee_schedule().set_fee(tx.operations.back()); + set_expiration(db, tx); + sign(tx, alice_private_key); + db.push_transaction(tx); + } + } + } } FC_LOG_AND_RETHROW()