Added bookie payout test

This commit is contained in:
Peter Conrad 2018-04-18 18:40:04 +02:00 committed by Fabian Schuh
parent abf909803c
commit 9cfd190fa1
No known key found for this signature in database
GPG key ID: F2538A4B282D6238

View file

@ -24,6 +24,7 @@
#include <boost/test/unit_test.hpp>
#include "../common/betting_test_markets.hpp"
#include "../common/tournament_helper.hpp"
#include <graphene/chain/affiliate_payout.hpp>
@ -453,4 +454,139 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_CASE( bookie_payout_test )
{ try {
ACTORS( (alice)(ann)(audrey)(irene) );
generate_blocks( HARDFORK_999_TIME );
generate_block();
const asset_id_type btc_id = create_user_issued_asset( "BTC", irene, 0 ).id;
test::set_expiration( db, trx );
trx.clear();
// Paula: 100% to Alice for Bookie / nothing for RPS
const fc::ecc::private_key paula_private_key = generate_private_key( "paula" );
account_create_operation aco = make_account( "paula", paula_private_key.get_public_key() );
aco.extensions.value.affiliate_distributions = affiliate_reward_distributions();
aco.extensions.value.affiliate_distributions->_dists[bookie]._dist[alice_id] = GRAPHENE_100_PERCENT;
trx.operations.push_back( aco );
// Penny: For Bookie 60% to Alice + 40% to Ann / For RPS 20% to Alice, 30% to Ann, 50% to Audrey
const fc::ecc::private_key penny_private_key = generate_private_key( "penny" );
aco = make_account( "penny", penny_private_key.get_public_key() );
aco.extensions.value.affiliate_distributions = affiliate_reward_distributions();
aco.extensions.value.affiliate_distributions->_dists[bookie]._dist[alice_id] = GRAPHENE_100_PERCENT * 3 / 5;
aco.extensions.value.affiliate_distributions->_dists[bookie]._dist[ann_id] = GRAPHENE_100_PERCENT
- aco.extensions.value.affiliate_distributions->_dists[bookie]._dist[alice_id];
aco.extensions.value.affiliate_distributions->_dists[rps]._dist[alice_id] = GRAPHENE_100_PERCENT / 5;
aco.extensions.value.affiliate_distributions->_dists[rps]._dist[audrey_id] = GRAPHENE_100_PERCENT / 2;
aco.extensions.value.affiliate_distributions->_dists[rps]._dist[ann_id] = GRAPHENE_100_PERCENT
- aco.extensions.value.affiliate_distributions->_dists[rps]._dist[alice_id]
- aco.extensions.value.affiliate_distributions->_dists[rps]._dist[audrey_id];
trx.operations.push_back( aco );
// Petra: nothing for Bookie / For RPS 10% to Ann, 90% to Audrey
const fc::ecc::private_key petra_private_key = generate_private_key( "petra" );
aco = make_account( "petra", petra_private_key.get_public_key() );
aco.extensions.value.affiliate_distributions = affiliate_reward_distributions();
aco.extensions.value.affiliate_distributions->_dists[rps]._dist[ann_id] = GRAPHENE_100_PERCENT / 10;
aco.extensions.value.affiliate_distributions->_dists[rps]._dist[audrey_id] = GRAPHENE_100_PERCENT
- aco.extensions.value.affiliate_distributions->_dists[rps]._dist[ann_id];
trx.operations.push_back( aco );
processed_transaction result = db.push_transaction(trx, ~0);
trx.clear();
account_id_type paula_id = result.operation_results[0].get<object_id_type>();
account_id_type penny_id = result.operation_results[1].get<object_id_type>();
account_id_type petra_id = result.operation_results[2].get<object_id_type>();
fund( paula_id(db), asset(20000000) );
fund( penny_id(db), asset(30000000) );
fund( petra_id(db), asset(40000000) );
CREATE_ICE_HOCKEY_BETTING_MARKET(false, 0);
// place bets at 10:1
place_bet(paula_id, capitals_win_market.id, bet_type::back, asset(10000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
place_bet(penny_id, capitals_win_market.id, bet_type::lay, asset(100000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
// reverse positions at 1:1
place_bet(paula_id, capitals_win_market.id, bet_type::lay, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
place_bet(penny_id, capitals_win_market.id, bet_type::back, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
update_betting_market_group(moneyline_betting_markets.id, graphene::chain::keywords::_status = betting_market_group_status::closed);
resolve_betting_market_group(moneyline_betting_markets.id,
{{capitals_win_market.id, betting_market_resolution_type::win},
{blackhawks_win_market.id, betting_market_resolution_type::not_win}});
generate_block();
uint16_t rake_fee_percentage = db.get_global_properties().parameters.betting_rake_fee_percentage;
BOOST_CHECK_EQUAL( 3 * GRAPHENE_1_PERCENT, rake_fee_percentage );
uint32_t rake_value;
// rake_value = (-10000 + 110000 - 110000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100;
// paula starts with 20000000, pays 10000 (bet), wins 110000, then pays 110000 (bet), wins 0
BOOST_CHECK_EQUAL( get_balance( paula_id, asset_id_type() ), 20000000 - 10000 + 110000 - 110000 + 0 );
// no wins -> no affiliate payouts
rake_value = (-100000 - 110000 + 220000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100;
// penny starts with 30000000, pays 100000 (bet), wins 0, then pays 110000 (bet), wins 220000
BOOST_CHECK_EQUAL( get_balance( penny_id, asset_id_type() ), 30000000 - 100000 + 0 - 110000 + 220000 - rake_value );
// penny wins 10000 net, rake is 3% of that (=300)
// Affiliate pay is 20% of rake (=60). Of this, 60%=36 go to Alice, 40%=24 go to Ann
BOOST_CHECK_EQUAL( 36, get_balance( alice_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( 24, get_balance( ann_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( 0, get_balance( audrey_id, asset_id_type() ) );
{
issue_uia( paula_id, asset( 1000000, btc_id ) );
issue_uia( petra_id, asset( 1000000, btc_id ) );
create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl.id); \
generate_blocks(1); \
const event_object& capitals_vs_blackhawks2 = *db.get_index_type<event_object_index>().indices().get<by_id>().rbegin(); \
create_betting_market_group({{"en", "Moneyline"}}, capitals_vs_blackhawks2.id, betting_market_rules.id, btc_id, false, 0);
generate_blocks(1);
const betting_market_group_object& moneyline_betting_markets2 = *db.get_index_type<betting_market_group_object_index>().indices().get<by_id>().rbegin();
create_betting_market(moneyline_betting_markets2.id, {{"en", "Washington Capitals win"}});
generate_blocks(1);
const betting_market_object& capitals_win_market2 = *db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin();
create_betting_market(moneyline_betting_markets2.id, {{"en", "Chicago Blackhawks win"}});
generate_blocks(1);
const betting_market_object& blackhawks_win_market2 = *db.get_index_type<betting_market_object_index>().indices().get<by_id>().rbegin();
// place bets at 10:1
place_bet(paula_id, capitals_win_market2.id, bet_type::back, asset(10000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
place_bet(petra_id, capitals_win_market2.id, bet_type::lay, asset(100000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
// reverse positions at 1:1
place_bet(paula_id, capitals_win_market2.id, bet_type::lay, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
place_bet(petra_id, capitals_win_market2.id, bet_type::back, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
update_betting_market_group(moneyline_betting_markets2.id, graphene::chain::keywords::_status = betting_market_group_status::closed);
resolve_betting_market_group(moneyline_betting_markets2.id,
{{capitals_win_market2.id, betting_market_resolution_type::not_win},
{blackhawks_win_market2.id, betting_market_resolution_type::win}});
generate_block();
rake_value = (-10000 + 0 - 110000 + 220000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100;
// paula starts with 1000000, pays 10000 (bet), wins 0, then pays 110000 (bet), wins 220000
BOOST_CHECK_EQUAL( get_balance( paula_id, btc_id ), 1000000 - 10000 + 0 - 110000 + 220000 - rake_value );
// net win 100000, 3% rake = 3000, 20% of that is 600, 100% of that goes to Alice
BOOST_CHECK_EQUAL( 600, get_balance( alice_id, btc_id ) );
BOOST_CHECK_EQUAL( 0, get_balance( ann_id, btc_id ) );
BOOST_CHECK_EQUAL( 0, get_balance( audrey_id, btc_id ) );
// rake_value = (-100000 + 110000 - 110000) * rake_fee_percentage / GRAPHENE_1_PERCENT / 100;
rake_value = 0;
// petra starts with 1000000, pays 100000 (bet), wins 110000, then pays 110000 (bet), wins 0
BOOST_CHECK_EQUAL( get_balance( petra_id, btc_id ), 1000000 - 100000 + 110000 - 110000 + 0 - rake_value );
// petra wins nothing -> no payout
}
} FC_LOG_AND_RETHROW() }
BOOST_AUTO_TEST_SUITE_END()