Fix all asset related broken tests

This commit is contained in:
Srdjan Obucina 2020-03-31 01:39:05 +02:00
parent d773dcb100
commit 59369bbca1
4 changed files with 125 additions and 125 deletions

View file

@ -231,7 +231,7 @@ BOOST_AUTO_TEST_CASE(elasticsearch_history_api) {
create_bitasset("USD", account_id_type()); // create op 0 create_bitasset("USD", account_id_type()); // create op 0
const account_object& dan = create_account("dan"); // create op 1 const account_object& dan = create_account("dan"); // create op 1
create_bitasset("CNY", dan.id); // create op 2 create_bitasset("CNY", dan.id); // create op 2
create_bitasset("BTC", account_id_type()); // create op 3 create_bitasset("BTCTEST", account_id_type()); // create op 3
create_bitasset("XMR", dan.id); // create op 4 create_bitasset("XMR", dan.id); // create op 4
create_bitasset("EUR", account_id_type()); // create op 5 create_bitasset("EUR", account_id_type()); // create op 5
create_bitasset("OIL", dan.id); // create op 6 create_bitasset("OIL", dan.id); // create op 6

View file

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

View file

@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) {
const account_object& dan = create_account("dan"); // create op 1 const account_object& dan = create_account("dan"); // create op 1
create_bitasset("CNY", dan.id); // create op 2 create_bitasset("CNY", dan.id); // create op 2
create_bitasset("BTC", account_id_type()); // create op 3 create_bitasset("BTCTEST", account_id_type()); // create op 3
create_bitasset("XMR", dan.id); // create op 4 create_bitasset("XMR", dan.id); // create op 4
create_bitasset("EUR", account_id_type()); // create op 5 create_bitasset("EUR", account_id_type()); // create op 5
create_bitasset("OIL", dan.id); // create op 6 create_bitasset("OIL", dan.id); // create op 6
@ -454,7 +454,7 @@ BOOST_AUTO_TEST_CASE(track_account) {
BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u); BOOST_CHECK_EQUAL(histories[1].id.instance(), 3u);
// create more ops, starting with an untracked account // create more ops, starting with an untracked account
create_bitasset( "BTC", account_id_type() ); create_bitasset( "BTCTEST", account_id_type() );
create_bitasset( "GBP", dan_id ); create_bitasset( "GBP", dan_id );
generate_block( ~database::skip_fork_db ); generate_block( ~database::skip_fork_db );
@ -468,7 +468,7 @@ BOOST_AUTO_TEST_CASE(track_account) {
db.pop_block(); db.pop_block();
// Try again, should result in same object IDs // Try again, should result in same object IDs
create_bitasset( "BTC", account_id_type() ); create_bitasset( "BTCTEST", account_id_type() );
create_bitasset( "GBP", dan_id ); create_bitasset( "GBP", dan_id );
generate_block(); generate_block();

View file

@ -48,7 +48,7 @@ BOOST_AUTO_TEST_CASE( create_lottery_asset_test )
creator.issuer = account_id_type(); creator.issuer = account_id_type();
creator.fee = asset(); creator.fee = asset();
char symbol[5] = "LOT"; char symbol[5] = "LOT";
symbol[3] = (char)('A' - 1 + test_asset_id.instance.value); symbol[4] = '\0'; // symbol depending on asset_id symbol[3] = (char)('A' - 2 + test_asset_id.instance.value); symbol[4] = '\0'; // symbol depending on asset_id
creator.symbol = symbol; creator.symbol = symbol;
creator.common_options.max_supply = 200; creator.common_options.max_supply = 200;
creator.precision = 0; creator.precision = 0;
@ -63,7 +63,7 @@ BOOST_AUTO_TEST_CASE( create_lottery_asset_test )
lottery_options.end_date = db.head_block_time() + fc::minutes(5); lottery_options.end_date = db.head_block_time() + fc::minutes(5);
lottery_options.ticket_price = asset(100); lottery_options.ticket_price = asset(100);
lottery_options.winning_tickets = { 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT }; lottery_options.winning_tickets = { 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 5 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT, 10 * GRAPHENE_1_PERCENT };
lottery_options.is_active = test_asset_id.instance.value % 2; lottery_options.is_active = (test_asset_id.instance.value - 1) % 2;
lottery_options.ending_on_soldout = true; lottery_options.ending_on_soldout = true;
creator.extensions = lottery_options; creator.extensions = lottery_options;