Fix an error using the wrong scaling constant for bet odds

This commit is contained in:
Eric Frias 2017-03-23 18:16:18 -04:00
parent 9f6edc649d
commit fd38d385ca
3 changed files with 61 additions and 5 deletions

View file

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

View file

@ -36,6 +36,7 @@
#include <graphene/chain/market_object.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <graphene/chain/witness_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
#include <graphene/utilities/tempdir.hpp>
@ -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<bet_object_index>().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<betting_market_position_index>().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 )

View file

@ -41,6 +41,7 @@
#include <graphene/chain/sport_object.hpp>
#include <graphene/chain/competitor_object.hpp>
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/betting_market_object.hpp>
#include <graphene/utilities/tempdir.hpp>
@ -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<betting_market_object_index>().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()