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