Reenable affiliate_payout_helper_test

This commit is contained in:
Srdjan Obucina 2020-03-31 01:51:30 +02:00
parent 59369bbca1
commit 1636bad78f

View file

@ -298,123 +298,123 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
int64_t ann_btc = 0;
int64_t audrey_btc = 0;
// {
// const tournament_object& game = db.create<tournament_object>( []( tournament_object& t ) {
// t.options.game_options = rock_paper_scissors_game_options();
// t.options.buy_in = asset( 10 );
// });
// affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// // Alice has no distribution set
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
// // Paula has nothing for Bookie
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.paula_id, 1000 ).value );
// // 20% of 4 gets rounded down to 0
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.penny_id, 4 ).value );
//
// // 20% of 5 = 1 is paid to Audrey
// BOOST_CHECK_EQUAL( 1, helper.payout( ath.penny_id, 5 ).value );
// ath.audrey_ppy++;
//
// // 20% of 50 = 10: 2 to Alice, 3 to Ann, 5 to Audrey
// BOOST_CHECK_EQUAL( 10, helper.payout( ath.penny_id, 50 ).value );
// ath.alice_ppy += 2;
// ath.ann_ppy += 3;
// ath.audrey_ppy += 5;
//
// // 20% of 59 = 11: 1 to Ann, 10 to Audrey
// BOOST_CHECK_EQUAL( 11, helper.payout( ath.petra_id, 59 ).value );
// ath.audrey_ppy += 10;
// ath.ann_ppy += 1;
//
// helper.commit();
//
// BOOST_CHECK_EQUAL( ath.alice_ppy, get_balance( ath.alice_id, asset_id_type() ) );
// BOOST_CHECK_EQUAL( ath.ann_ppy, get_balance( ath.ann_id, asset_id_type() ) );
// BOOST_CHECK_EQUAL( ath.audrey_ppy, get_balance( ath.audrey_id, asset_id_type() ) );
// }
{
const tournament_object& game = db.create<tournament_object>( []( tournament_object& t ) {
t.options.game_options = rock_paper_scissors_game_options();
t.options.buy_in = asset( 10 );
});
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// Alice has no distribution set
BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
// Paula has nothing for Bookie
BOOST_CHECK_EQUAL( 0, helper.payout( ath.paula_id, 1000 ).value );
// 20% of 4 gets rounded down to 0
BOOST_CHECK_EQUAL( 0, helper.payout( ath.penny_id, 4 ).value );
// {
// const tournament_object& game = db.create<tournament_object>( [btc_id]( tournament_object& t ) {
// t.options.game_options = rock_paper_scissors_game_options();
// t.options.buy_in = asset( 10, btc_id );
// });
// affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// // 20% of 60 = 12: 2 to Alice, 3 to Ann, 7 to Audrey
// BOOST_CHECK_EQUAL( 12, helper.payout( ath.penny_id, 60 ).value );
// alice_btc += 2;
// ann_btc += 3;
// audrey_btc += 7;
// helper.commit();
// BOOST_CHECK_EQUAL( alice_btc, get_balance( ath.alice_id, btc_id ) );
// BOOST_CHECK_EQUAL( ann_btc, get_balance( ath.ann_id, btc_id ) );
// BOOST_CHECK_EQUAL( audrey_btc, get_balance( ath.audrey_id, btc_id ) );
// }
//
// {
// const betting_market_group_object& game = db.create<betting_market_group_object>( []( betting_market_group_object& b ) {
// b.asset_id = asset_id_type();
// } );
// affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// // Alice has no distribution set
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
// // Petra has nothing for Bookie
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.petra_id, 1000 ).value );
// // 20% of 4 gets rounded down to 0
// BOOST_CHECK_EQUAL( 0, helper.payout( ath.penny_id, 4 ).value );
//
// // 20% of 5 = 1 is paid to Ann
// BOOST_CHECK_EQUAL( 1, helper.payout( ath.penny_id, 5 ).value );
// ath.ann_ppy++;
//
// // 20% of 40 = 8: 8 to Alice
// BOOST_CHECK_EQUAL( 8, helper.payout( ath.paula_id, 40 ).value );
// ath.alice_ppy += 8;
//
// // intermediate commit should clear internal accumulator
// helper.commit();
//
// // 20% of 59 = 11: 6 to Alice, 5 to Ann
// BOOST_CHECK_EQUAL( 11, helper.payout( ath.penny_id, 59 ).value );
// ath.alice_ppy += 6;
// ath.ann_ppy += 5;
//
// helper.commit();
//
// BOOST_CHECK_EQUAL( ath.alice_ppy, get_balance( ath.alice_id, asset_id_type() ) );
// BOOST_CHECK_EQUAL( ath.ann_ppy, get_balance( ath.ann_id, asset_id_type() ) );
// BOOST_CHECK_EQUAL( ath.audrey_ppy, get_balance( ath.audrey_id, asset_id_type() ) );
// }
//
// {
// const betting_market_group_object& game = db.create<betting_market_group_object>( [btc_id]( betting_market_group_object& b ) {
// b.asset_id = btc_id;
// } );
// affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// // 20% of 60 = 12: 7 to Alice, 5 to Ann
// BOOST_CHECK_EQUAL( 12, helper.payout( ath.penny_id, 60 ).value );
// alice_btc += 7;
// ann_btc += 5;
// helper.commit();
// BOOST_CHECK_EQUAL( alice_btc, get_balance( ath.alice_id, btc_id ) );
// BOOST_CHECK_EQUAL( ann_btc, get_balance( ath.ann_id, btc_id ) );
// BOOST_CHECK_EQUAL( audrey_btc, get_balance( ath.audrey_id, btc_id ) );
// }
//
// {
// // Fix total supply
// auto& index = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index<balances_by_account_index>();
// auto abo = index.get_account_balance( account_id_type(), asset_id_type() );
// BOOST_CHECK( abo != nullptr );
// db.modify( *abo, [&ath]( account_balance_object& bal ) {
// bal.balance -= ath.alice_ppy + ath.ann_ppy + ath.audrey_ppy;
// });
//
// abo = index.get_account_balance( irene_id, btc_id );
// BOOST_CHECK( abo != nullptr );
// db.modify( *abo, [alice_btc,ann_btc,audrey_btc]( account_balance_object& bal ) {
// bal.balance -= alice_btc + ann_btc + audrey_btc;
// });
// }
// 20% of 5 = 1 is paid to Audrey
BOOST_CHECK_EQUAL( 1, helper.payout( ath.penny_id, 5 ).value );
ath.audrey_ppy++;
// 20% of 50 = 10: 2 to Alice, 3 to Ann, 5 to Audrey
BOOST_CHECK_EQUAL( 10, helper.payout( ath.penny_id, 50 ).value );
ath.alice_ppy += 2;
ath.ann_ppy += 3;
ath.audrey_ppy += 5;
// 20% of 59 = 11: 1 to Ann, 10 to Audrey
BOOST_CHECK_EQUAL( 11, helper.payout( ath.petra_id, 59 ).value );
ath.audrey_ppy += 10;
ath.ann_ppy += 1;
helper.commit();
BOOST_CHECK_EQUAL( ath.alice_ppy, get_balance( ath.alice_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( ath.ann_ppy, get_balance( ath.ann_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( ath.audrey_ppy, get_balance( ath.audrey_id, asset_id_type() ) );
}
{
const tournament_object& game = db.create<tournament_object>( [btc_id]( tournament_object& t ) {
t.options.game_options = rock_paper_scissors_game_options();
t.options.buy_in = asset( 10, btc_id );
});
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// 20% of 60 = 12: 2 to Alice, 3 to Ann, 7 to Audrey
BOOST_CHECK_EQUAL( 12, helper.payout( ath.penny_id, 60 ).value );
alice_btc += 2;
ann_btc += 3;
audrey_btc += 7;
helper.commit();
BOOST_CHECK_EQUAL( alice_btc, get_balance( ath.alice_id, btc_id ) );
BOOST_CHECK_EQUAL( ann_btc, get_balance( ath.ann_id, btc_id ) );
BOOST_CHECK_EQUAL( audrey_btc, get_balance( ath.audrey_id, btc_id ) );
}
{
const betting_market_group_object& game = db.create<betting_market_group_object>( []( betting_market_group_object& b ) {
b.asset_id = asset_id_type();
} );
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// Alice has no distribution set
BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
// Petra has nothing for Bookie
BOOST_CHECK_EQUAL( 0, helper.payout( ath.petra_id, 1000 ).value );
// 20% of 4 gets rounded down to 0
BOOST_CHECK_EQUAL( 0, helper.payout( ath.penny_id, 4 ).value );
// 20% of 5 = 1 is paid to Ann
BOOST_CHECK_EQUAL( 1, helper.payout( ath.penny_id, 5 ).value );
ath.ann_ppy++;
// 20% of 40 = 8: 8 to Alice
BOOST_CHECK_EQUAL( 8, helper.payout( ath.paula_id, 40 ).value );
ath.alice_ppy += 8;
// intermediate commit should clear internal accumulator
helper.commit();
// 20% of 59 = 11: 6 to Alice, 5 to Ann
BOOST_CHECK_EQUAL( 11, helper.payout( ath.penny_id, 59 ).value );
ath.alice_ppy += 6;
ath.ann_ppy += 5;
helper.commit();
BOOST_CHECK_EQUAL( ath.alice_ppy, get_balance( ath.alice_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( ath.ann_ppy, get_balance( ath.ann_id, asset_id_type() ) );
BOOST_CHECK_EQUAL( ath.audrey_ppy, get_balance( ath.audrey_id, asset_id_type() ) );
}
{
const betting_market_group_object& game = db.create<betting_market_group_object>( [btc_id]( betting_market_group_object& b ) {
b.asset_id = btc_id;
} );
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
// 20% of 60 = 12: 7 to Alice, 5 to Ann
BOOST_CHECK_EQUAL( 12, helper.payout( ath.penny_id, 60 ).value );
alice_btc += 7;
ann_btc += 5;
helper.commit();
BOOST_CHECK_EQUAL( alice_btc, get_balance( ath.alice_id, btc_id ) );
BOOST_CHECK_EQUAL( ann_btc, get_balance( ath.ann_id, btc_id ) );
BOOST_CHECK_EQUAL( audrey_btc, get_balance( ath.audrey_id, btc_id ) );
}
{
// Fix total supply
auto& index = db.get_index_type< primary_index< account_balance_index > >().get_secondary_index<balances_by_account_index>();
auto abo = index.get_account_balance( account_id_type(), asset_id_type() );
BOOST_CHECK( abo != nullptr );
db.modify( *abo, [&ath]( account_balance_object& bal ) {
bal.balance -= ath.alice_ppy + ath.ann_ppy + ath.audrey_ppy;
});
abo = index.get_account_balance( irene_id, btc_id );
BOOST_CHECK( abo != nullptr );
db.modify( *abo, [alice_btc,ann_btc,audrey_btc]( account_balance_object& bal ) {
bal.balance -= alice_btc + ann_btc + audrey_btc;
});
}
}
BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )