More refactoring
This commit is contained in:
parent
95844b3ef3
commit
ac078afff0
1 changed files with 226 additions and 247 deletions
|
|
@ -38,6 +38,146 @@
|
|||
using namespace graphene::chain;
|
||||
using namespace graphene::db;
|
||||
|
||||
class affiliate_test_helper
|
||||
{
|
||||
public:
|
||||
affiliate_test_helper( database_fixture& f ) : fixture(f), accounts(&fixture.db.get_index_type<account_index>())
|
||||
{
|
||||
fixture.generate_blocks( HARDFORK_999_TIME );
|
||||
fixture.generate_block();
|
||||
|
||||
test::set_expiration( fixture.db, fixture.trx );
|
||||
fixture.trx.clear();
|
||||
|
||||
alice_id = find_account( "alice" );
|
||||
if( alice_id == account_id_type() )
|
||||
{
|
||||
ACTOR(alice);
|
||||
this->alice_id = alice_id;
|
||||
}
|
||||
|
||||
ann_id = find_account( "ann" );
|
||||
if( ann_id == account_id_type() )
|
||||
{
|
||||
ACTOR(ann);
|
||||
this->ann_id = ann_id;
|
||||
}
|
||||
|
||||
audrey_id = find_account( "audrey" );
|
||||
if( audrey_id == account_id_type() )
|
||||
{
|
||||
ACTOR(audrey);
|
||||
this->audrey_id = audrey_id;
|
||||
}
|
||||
|
||||
paula_id = find_account("paula");
|
||||
if( paula_id == account_id_type() )
|
||||
{
|
||||
// Paula: 100% to Alice for Bookie / nothing for RPS
|
||||
account_create_operation aco = fixture.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;
|
||||
fixture.trx.operations.push_back( aco );
|
||||
processed_transaction op_result = fixture.db.push_transaction( fixture.trx, ~0 );
|
||||
paula_id = op_result.operation_results[0].get<object_id_type>();
|
||||
fixture.trx.clear();
|
||||
fixture.fund( paula_id(fixture.db), asset(20000000) );
|
||||
}
|
||||
|
||||
penny_id = find_account("penny");
|
||||
if( penny_id == account_id_type() )
|
||||
{
|
||||
// Penny: For Bookie 60% to Alice + 40% to Ann / For RPS 20% to Alice, 30% to Ann, 50% to Audrey
|
||||
account_create_operation aco = fixture.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];
|
||||
fixture.trx.operations.push_back( aco );
|
||||
processed_transaction op_result = fixture.db.push_transaction( fixture.trx, ~0 );
|
||||
penny_id = op_result.operation_results[0].get<object_id_type>();
|
||||
fixture.trx.clear();
|
||||
fixture.fund( penny_id(fixture.db), asset(30000000) );
|
||||
}
|
||||
|
||||
petra_id = find_account("petra");
|
||||
if( petra_id == account_id_type() )
|
||||
{
|
||||
// Petra: nothing for Bookie / For RPS 10% to Ann, 90% to Audrey
|
||||
account_create_operation aco = fixture.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];
|
||||
fixture.trx.operations.push_back( aco );
|
||||
processed_transaction op_result = fixture.db.push_transaction( fixture.trx, ~0 );
|
||||
petra_id = op_result.operation_results[0].get<object_id_type>();
|
||||
fixture.trx.clear();
|
||||
fixture.fund( petra_id(fixture.db), asset(40000000) );
|
||||
}
|
||||
|
||||
update_balances();
|
||||
}
|
||||
|
||||
void update_balances()
|
||||
{
|
||||
alice_ppy = fixture.get_balance( alice_id, asset_id_type() );
|
||||
ann_ppy = fixture.get_balance( ann_id, asset_id_type() );
|
||||
audrey_ppy = fixture.get_balance( audrey_id, asset_id_type() );
|
||||
paula_ppy = fixture.get_balance( paula_id, asset_id_type() );
|
||||
penny_ppy = fixture.get_balance( penny_id, asset_id_type() );
|
||||
petra_ppy = fixture.get_balance( petra_id, asset_id_type() );
|
||||
}
|
||||
|
||||
database_fixture& fixture;
|
||||
|
||||
account_id_type alice_id;
|
||||
account_id_type ann_id;
|
||||
account_id_type audrey_id;
|
||||
account_id_type paula_id;
|
||||
account_id_type penny_id;
|
||||
account_id_type petra_id;
|
||||
|
||||
int64_t alice_ppy;
|
||||
int64_t ann_ppy;
|
||||
int64_t audrey_ppy;
|
||||
int64_t paula_ppy;
|
||||
int64_t penny_ppy;
|
||||
int64_t petra_ppy;
|
||||
|
||||
private:
|
||||
const account_index* accounts;
|
||||
account_id_type find_account( const string& name )
|
||||
{
|
||||
auto itr = accounts->indices().get<by_name>().find( name );
|
||||
if( itr == accounts->indices().get<by_name>().end() ) return account_id_type();
|
||||
return itr->id;
|
||||
}
|
||||
|
||||
static fc::ecc::private_key generate_private_key( const string& seed )
|
||||
{
|
||||
return database_fixture::generate_private_key( seed );
|
||||
}
|
||||
|
||||
const account_object& create_account( const string& name, const fc::ecc::public_key& key )
|
||||
{
|
||||
return fixture.create_account( name, key );
|
||||
}
|
||||
|
||||
public:
|
||||
const fc::ecc::private_key alice_private_key = generate_private_key( "alice" );
|
||||
const fc::ecc::private_key ann_private_key = generate_private_key( "ann" );
|
||||
const fc::ecc::private_key audrey_private_key = generate_private_key( "audrey" );
|
||||
const fc::ecc::private_key paula_private_key = generate_private_key( "paula" );
|
||||
const fc::ecc::private_key penny_private_key = generate_private_key( "penny" );
|
||||
const fc::ecc::private_key petra_private_key = generate_private_key( "petra" );
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE( affiliate_tests, database_fixture )
|
||||
|
||||
BOOST_AUTO_TEST_CASE( account_test )
|
||||
|
|
@ -144,125 +284,6 @@ BOOST_AUTO_TEST_CASE( account_test )
|
|||
BOOST_CHECK_EQUAL( 10, share_audrey->second );
|
||||
}
|
||||
|
||||
static vector<account_id_type> create_players( database_fixture& db )
|
||||
{
|
||||
auto generate_private_key = [&db]( const string& seed ) { return db.generate_private_key( seed ); };
|
||||
auto create_account = [&db]( const string& name, const fc::ecc::public_key& key ) { return db.create_account( name, key ); };
|
||||
vector<account_id_type> result;
|
||||
const auto& accounts = db.db.get_index_type<account_index>().indices().get<by_name>();
|
||||
auto find_account = [&accounts]( const string& name ) {
|
||||
auto itr = accounts.find( name );
|
||||
if( itr != accounts.end() )
|
||||
return optional<const account_object*>( &(*itr) );
|
||||
return optional<const account_object*>();
|
||||
};
|
||||
|
||||
{
|
||||
optional<const account_object*> tmp = find_account("alice");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
ACTOR( alice );
|
||||
result.push_back( alice_id );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
optional<const account_object*> tmp = find_account("ann");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
ACTOR( ann );
|
||||
result.push_back( ann_id );
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
optional<const account_object*> tmp = find_account("audrey");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
ACTOR( audrey );
|
||||
result.push_back( audrey_id );
|
||||
}
|
||||
}
|
||||
|
||||
const account_id_type alice_id = result[0];
|
||||
const account_id_type ann_id = result[1];
|
||||
const account_id_type audrey_id = result[2];
|
||||
|
||||
db.generate_blocks( HARDFORK_999_TIME );
|
||||
db.generate_block();
|
||||
|
||||
signed_transaction trx;
|
||||
test::set_expiration( db.db, trx );
|
||||
|
||||
optional<const account_object*> tmp = find_account("paula");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
// 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 = db.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 );
|
||||
processed_transaction op_result = db.db.push_transaction(trx, ~0);
|
||||
result.push_back( op_result.operation_results[0].get<object_id_type>() );
|
||||
trx.clear();
|
||||
db.fund( account_id_type(op_result.operation_results[0].get<object_id_type>())( db.db ), asset(20000000) );
|
||||
}
|
||||
|
||||
tmp = find_account("penny");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
// 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" );
|
||||
account_create_operation aco = db.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 );
|
||||
processed_transaction op_result = db.db.push_transaction(trx, ~0);
|
||||
result.push_back( op_result.operation_results[0].get<object_id_type>() );
|
||||
trx.clear();
|
||||
db.fund( account_id_type(op_result.operation_results[0].get<object_id_type>())( db.db ), asset(30000000) );
|
||||
}
|
||||
|
||||
tmp = find_account("petra");
|
||||
if( tmp.valid() )
|
||||
result.push_back( (*tmp)->id );
|
||||
else
|
||||
{
|
||||
// Petra: nothing for Bookie / For RPS 10% to Ann, 90% to Audrey
|
||||
const fc::ecc::private_key petra_private_key = generate_private_key( "petra" );
|
||||
account_create_operation aco = db.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 op_result = db.db.push_transaction(trx, ~0);
|
||||
result.push_back( op_result.operation_results[0].get<object_id_type>() );
|
||||
trx.clear();
|
||||
db.fund( account_id_type(op_result.operation_results[0].get<object_id_type>())( db.db ), asset(40000000) );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
||||
{
|
||||
ACTORS( (irene) );
|
||||
|
|
@ -270,18 +291,8 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
const asset_id_type btc_id = create_user_issued_asset( "BTC", irene, 0 ).id;
|
||||
issue_uia( irene, asset( 100000, btc_id ) );
|
||||
|
||||
vector<account_id_type> actors = create_players( *this );
|
||||
BOOST_REQUIRE_EQUAL( 6, actors.size() );
|
||||
const auto alice_id = actors[0];
|
||||
const auto ann_id = actors[1];
|
||||
const auto audrey_id = actors[2];
|
||||
const auto paula_id = actors[3];
|
||||
const auto penny_id = actors[4];
|
||||
const auto petra_id = actors[5];
|
||||
affiliate_test_helper ath( *this );
|
||||
|
||||
int64_t alice_ppy = 0;
|
||||
int64_t ann_ppy = 0;
|
||||
int64_t audrey_ppy = 0;
|
||||
int64_t alice_btc = 0;
|
||||
int64_t ann_btc = 0;
|
||||
int64_t audrey_btc = 0;
|
||||
|
|
@ -293,32 +304,32 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
});
|
||||
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
|
||||
// Alice has no distribution set
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( alice_id, 1000 ).value );
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
|
||||
// Paula has nothing for Bookie
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( paula_id, 1000 ).value );
|
||||
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( 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( penny_id, 5 ).value );
|
||||
audrey_ppy++;
|
||||
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( penny_id, 50 ).value );
|
||||
alice_ppy += 2;
|
||||
ann_ppy += 3;
|
||||
audrey_ppy += 5;
|
||||
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( petra_id, 59 ).value );
|
||||
audrey_ppy += 10;
|
||||
ann_ppy += 1;
|
||||
BOOST_CHECK_EQUAL( 11, helper.payout( ath.petra_id, 59 ).value );
|
||||
ath.audrey_ppy += 10;
|
||||
ath.ann_ppy += 1;
|
||||
|
||||
helper.commit();
|
||||
|
||||
BOOST_CHECK_EQUAL( alice_ppy, get_balance( alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ann_ppy, get_balance( ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( audrey_ppy, get_balance( audrey_id, asset_id_type() ) );
|
||||
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() ) );
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -328,14 +339,14 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
});
|
||||
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( penny_id, 60 ).value );
|
||||
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( alice_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( ann_btc, get_balance( ann_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( audrey_btc, get_balance( audrey_id, btc_id ) );
|
||||
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 ) );
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -344,33 +355,33 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
} );
|
||||
affiliate_payout_helper helper = affiliate_payout_helper( db, game );
|
||||
// Alice has no distribution set
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( alice_id, 1000 ).value );
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( ath.alice_id, 1000 ).value );
|
||||
// Petra has nothing for Bookie
|
||||
BOOST_CHECK_EQUAL( 0, helper.payout( petra_id, 1000 ).value );
|
||||
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( penny_id, 4 ).value );
|
||||
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( penny_id, 5 ).value );
|
||||
ann_ppy++;
|
||||
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( paula_id, 40 ).value );
|
||||
alice_ppy += 8;
|
||||
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( penny_id, 59 ).value );
|
||||
alice_ppy += 6;
|
||||
ann_ppy += 5;
|
||||
BOOST_CHECK_EQUAL( 11, helper.payout( ath.penny_id, 59 ).value );
|
||||
ath.alice_ppy += 6;
|
||||
ath.ann_ppy += 5;
|
||||
|
||||
helper.commit();
|
||||
|
||||
BOOST_CHECK_EQUAL( alice_ppy, get_balance( alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ann_ppy, get_balance( ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( audrey_ppy, get_balance( audrey_id, asset_id_type() ) );
|
||||
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() ) );
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -379,13 +390,13 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
} );
|
||||
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( penny_id, 60 ).value );
|
||||
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( alice_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( ann_btc, get_balance( ann_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( audrey_btc, get_balance( audrey_id, btc_id ) );
|
||||
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 ) );
|
||||
}
|
||||
|
||||
{
|
||||
|
|
@ -393,8 +404,8 @@ BOOST_AUTO_TEST_CASE( affiliate_payout_helper_test )
|
|||
auto& index = db.get_index_type<account_balance_index>().indices().get<by_account_asset>();
|
||||
auto itr = index.find( boost::make_tuple( account_id_type(), asset_id_type() ) );
|
||||
BOOST_CHECK( itr != index.end() );
|
||||
db.modify( *itr, [alice_ppy,ann_ppy,audrey_ppy]( account_balance_object& bal ) {
|
||||
bal.balance -= alice_ppy + ann_ppy + audrey_ppy;
|
||||
db.modify( *itr, [&ath]( account_balance_object& bal ) {
|
||||
bal.balance -= ath.alice_ppy + ath.ann_ppy + ath.audrey_ppy;
|
||||
});
|
||||
|
||||
itr = index.find( boost::make_tuple( irene_id, btc_id ) );
|
||||
|
|
@ -409,25 +420,7 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
|
|||
{ try {
|
||||
ACTORS( (martha) );
|
||||
|
||||
vector<account_id_type> actors = create_players( *this );
|
||||
BOOST_REQUIRE_EQUAL( 6, actors.size() );
|
||||
const auto alice_id = actors[0];
|
||||
const auto ann_id = actors[1];
|
||||
const auto audrey_id = actors[2];
|
||||
const auto paula_id = actors[3];
|
||||
const auto penny_id = actors[4];
|
||||
const auto petra_id = actors[5];
|
||||
|
||||
const int64_t alice_ppy_start = get_balance( alice_id, asset_id_type() );
|
||||
const int64_t ann_ppy_start = get_balance( ann_id, asset_id_type() );
|
||||
const int64_t audrey_ppy_start = get_balance( audrey_id, asset_id_type() );
|
||||
const int64_t paula_ppy_start = get_balance( paula_id, asset_id_type() );
|
||||
const int64_t penny_ppy_start = get_balance( penny_id, asset_id_type() );
|
||||
const int64_t petra_ppy_start = get_balance( petra_id, asset_id_type() );
|
||||
|
||||
const auto paula_private_key = generate_private_key("paula");
|
||||
const auto penny_private_key = generate_private_key("penny");
|
||||
const auto petra_private_key = generate_private_key("petra");
|
||||
affiliate_test_helper ath( *this );
|
||||
|
||||
fund( martha_id(db), asset(1000000000) );
|
||||
|
||||
|
|
@ -440,16 +433,16 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
|
|||
tournament_id_type tournament_id = helper.create_tournament( martha_id, martha_private_key, buy_in, 3, 3, 1, 1 );
|
||||
BOOST_REQUIRE(tournament_id == tournament_id_type());
|
||||
|
||||
helper.join_tournament( tournament_id, paula_id, paula_id, paula_private_key, buy_in);
|
||||
helper.join_tournament( tournament_id, penny_id, penny_id, penny_private_key, buy_in);
|
||||
helper.join_tournament( tournament_id, petra_id, petra_id, petra_private_key, buy_in);
|
||||
helper.join_tournament( tournament_id, ath.paula_id, ath.paula_id, ath.paula_private_key, buy_in);
|
||||
helper.join_tournament( tournament_id, ath.penny_id, ath.penny_id, ath.penny_private_key, buy_in);
|
||||
helper.join_tournament( tournament_id, ath.petra_id, ath.petra_id, ath.petra_private_key, buy_in);
|
||||
|
||||
generate_block();
|
||||
const tournament_object& tournament = db.get<tournament_object>( tournament_id );
|
||||
|
||||
BOOST_CHECK_EQUAL( paula_ppy_start - 12000, get_balance( paula_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( penny_ppy_start - 12000, get_balance( penny_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( petra_ppy_start - 12000, get_balance( petra_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.paula_ppy - 12000, get_balance( ath.paula_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.penny_ppy - 12000, get_balance( ath.penny_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.petra_ppy - 12000, get_balance( ath.petra_id, asset_id_type() ) );
|
||||
|
||||
const tournament_details_object& tournament_details = tournament.tournament_details_id(db);
|
||||
BOOST_CHECK_EQUAL( 3, tournament_details.matches.size() );
|
||||
|
|
@ -458,24 +451,24 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
|
|||
const match_object& match = tournament_details.matches[0](db);
|
||||
BOOST_CHECK_EQUAL( int64_t(match_state::match_complete), int64_t(match.get_state()) );
|
||||
BOOST_CHECK_EQUAL( 1, match.players.size() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(penny_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(ath.penny_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
}
|
||||
{ // match 2 is paula vs. petra: paula wins
|
||||
const match_object& match = tournament_details.matches[1](db);
|
||||
BOOST_CHECK_EQUAL( int64_t(match_state::match_in_progress), int64_t(match.get_state()) );
|
||||
BOOST_CHECK_EQUAL( 2, match.players.size() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(paula_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(petra_id).instance(), object_id_type(match.players[1]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(ath.paula_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(ath.petra_id).instance(), object_id_type(match.players[1]).instance() );
|
||||
BOOST_CHECK_EQUAL( 1, match.games.size() );
|
||||
|
||||
const game_object& game = match.games[0](db);
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::expecting_commit_moves), int64_t(game.get_state()) );
|
||||
helper.rps_throw( game.id, paula_id, rock_paper_scissors_gesture::paper, paula_private_key );
|
||||
helper.rps_throw( game.id, petra_id, rock_paper_scissors_gesture::rock, petra_private_key );
|
||||
helper.rps_throw( game.id, ath.paula_id, rock_paper_scissors_gesture::paper, ath.paula_private_key );
|
||||
helper.rps_throw( game.id, ath.petra_id, rock_paper_scissors_gesture::rock, ath.petra_private_key );
|
||||
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::expecting_reveal_moves), int64_t(game.get_state()) );
|
||||
helper.rps_reveal( game.id, paula_id, rock_paper_scissors_gesture::paper, paula_private_key );
|
||||
helper.rps_reveal( game.id, petra_id, rock_paper_scissors_gesture::rock, petra_private_key );
|
||||
helper.rps_reveal( game.id, ath.paula_id, rock_paper_scissors_gesture::paper, ath.paula_private_key );
|
||||
helper.rps_reveal( game.id, ath.petra_id, rock_paper_scissors_gesture::rock, ath.petra_private_key );
|
||||
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::game_complete), int64_t(game.get_state()) );
|
||||
BOOST_CHECK_EQUAL( 1, match.games.size() );
|
||||
|
|
@ -485,18 +478,18 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
|
|||
const match_object& match = tournament_details.matches[2](db);
|
||||
BOOST_CHECK_EQUAL( int64_t(match_state::match_in_progress), int64_t(match.get_state()) );
|
||||
BOOST_CHECK_EQUAL( 2, match.players.size() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(penny_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(paula_id).instance(), object_id_type(match.players[1]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(ath.penny_id).instance(), object_id_type(match.players[0]).instance() );
|
||||
BOOST_CHECK_EQUAL( object_id_type(ath.paula_id).instance(), object_id_type(match.players[1]).instance() );
|
||||
BOOST_CHECK_EQUAL( 1, match.games.size() );
|
||||
|
||||
const game_object& game = match.games[0](db);
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::expecting_commit_moves), int64_t(game.get_state()) );
|
||||
helper.rps_throw( game.id, paula_id, rock_paper_scissors_gesture::paper, paula_private_key );
|
||||
helper.rps_throw( game.id, penny_id, rock_paper_scissors_gesture::scissors, penny_private_key );
|
||||
helper.rps_throw( game.id, ath.paula_id, rock_paper_scissors_gesture::paper, ath.paula_private_key );
|
||||
helper.rps_throw( game.id, ath.penny_id, rock_paper_scissors_gesture::scissors, ath.penny_private_key );
|
||||
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::expecting_reveal_moves), int64_t(game.get_state()) );
|
||||
helper.rps_reveal( game.id, paula_id, rock_paper_scissors_gesture::paper, paula_private_key );
|
||||
helper.rps_reveal( game.id, penny_id, rock_paper_scissors_gesture::scissors, penny_private_key );
|
||||
helper.rps_reveal( game.id, ath.paula_id, rock_paper_scissors_gesture::paper, ath.paula_private_key );
|
||||
helper.rps_reveal( game.id, ath.penny_id, rock_paper_scissors_gesture::scissors, ath.penny_private_key );
|
||||
|
||||
BOOST_CHECK_EQUAL( int64_t(game_state::game_complete), int64_t(game.get_state()) );
|
||||
BOOST_CHECK_EQUAL( int64_t(match_state::match_complete), int64_t(match.get_state()) );
|
||||
|
|
@ -504,17 +497,17 @@ BOOST_AUTO_TEST_CASE( rps_tournament_payout_test )
|
|||
|
||||
BOOST_CHECK_EQUAL( 3*GRAPHENE_1_PERCENT, db.get_global_properties().parameters.rake_fee_percentage );
|
||||
// Penny wins net 3*buy_in minus rake = 36000 - 1080 = 34920
|
||||
BOOST_CHECK_EQUAL( paula_ppy_start - 12000, get_balance( paula_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( penny_ppy_start - 12000 + 34920, get_balance( penny_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( petra_ppy_start - 12000, get_balance( petra_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.paula_ppy - 12000, get_balance( ath.paula_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.penny_ppy - 12000 + 34920, get_balance( ath.penny_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.petra_ppy - 12000, get_balance( ath.petra_id, asset_id_type() ) );
|
||||
|
||||
// Dividend account receives 80% of rake = 864
|
||||
BOOST_CHECK_EQUAL( div_ppy + 864, get_balance( dividend_id, asset_id_type() ) );
|
||||
|
||||
// 20% of rake = 216 is paid to Penny's affiliates: 43 to Alice, 64 to Ann, 109 to Audrey
|
||||
BOOST_CHECK_EQUAL( alice_ppy_start + 43, get_balance( alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ann_ppy_start + 64, get_balance( ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( audrey_ppy_start + 109, get_balance( audrey_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.alice_ppy + 43, get_balance( ath.alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.ann_ppy + 64, get_balance( ath.ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.audrey_ppy + 109, get_balance( ath.audrey_id, asset_id_type() ) );
|
||||
|
||||
} FC_LOG_AND_RETHROW() }
|
||||
|
||||
|
|
@ -525,31 +518,17 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test )
|
|||
|
||||
const asset_id_type btc_id = create_user_issued_asset( "BTC", irene, 0 ).id;
|
||||
|
||||
vector<account_id_type> actors = create_players( *this );
|
||||
BOOST_REQUIRE_EQUAL( 6, actors.size() );
|
||||
const auto alice_id = actors[0];
|
||||
const auto ann_id = actors[1];
|
||||
const auto audrey_id = actors[2];
|
||||
const auto paula_id = actors[3];
|
||||
const auto penny_id = actors[4];
|
||||
const auto petra_id = actors[5];
|
||||
|
||||
const int64_t alice_ppy_start = get_balance( alice_id, asset_id_type() );
|
||||
const int64_t ann_ppy_start = get_balance( ann_id, asset_id_type() );
|
||||
const int64_t audrey_ppy_start = get_balance( audrey_id, asset_id_type() );
|
||||
const int64_t paula_ppy_start = get_balance( paula_id, asset_id_type() );
|
||||
const int64_t penny_ppy_start = get_balance( penny_id, asset_id_type() );
|
||||
// const int64_t petra_ppy_start = get_balance( petra_id, asset_id_type() );
|
||||
affiliate_test_helper ath( *this );
|
||||
|
||||
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);
|
||||
place_bet(ath.paula_id, capitals_win_market.id, bet_type::back, asset(10000, asset_id_type()), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
|
||||
place_bet(ath.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);
|
||||
place_bet(ath.paula_id, capitals_win_market.id, bet_type::lay, asset(110000, asset_id_type()), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
|
||||
place_bet(ath.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,
|
||||
|
|
@ -562,22 +541,22 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test )
|
|||
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() ), paula_ppy_start - 10000 + 110000 - 110000 + 0 );
|
||||
BOOST_CHECK_EQUAL( get_balance( ath.paula_id, asset_id_type() ), ath.paula_ppy - 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() ), penny_ppy_start - 100000 + 0 - 110000 + 220000 - rake_value );
|
||||
BOOST_CHECK_EQUAL( get_balance( ath.penny_id, asset_id_type() ), ath.penny_ppy - 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( alice_ppy_start + 36, get_balance( alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ann_ppy_start + 24, get_balance( ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( audrey_ppy_start + 0, get_balance( audrey_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.alice_ppy + 36, get_balance( ath.alice_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.ann_ppy + 24, get_balance( ath.ann_id, asset_id_type() ) );
|
||||
BOOST_CHECK_EQUAL( ath.audrey_ppy + 0, get_balance( ath.audrey_id, asset_id_type() ) );
|
||||
|
||||
{
|
||||
test::set_expiration( db, trx );
|
||||
issue_uia( paula_id, asset( 1000000, btc_id ) );
|
||||
issue_uia( petra_id, asset( 1000000, btc_id ) );
|
||||
issue_uia( ath.paula_id, asset( 1000000, btc_id ) );
|
||||
issue_uia( ath.petra_id, asset( 1000000, btc_id ) );
|
||||
|
||||
create_event({{"en", "Washington Capitals/Chicago Blackhawks"}, {"zh_Hans", "華盛頓首都隊/芝加哥黑鷹"}, {"ja", "ワシントン・キャピタルズ/シカゴ・ブラックホークス"}}, {{"en", "2016-17"}}, nhl.id); \
|
||||
generate_blocks(1); \
|
||||
|
|
@ -593,12 +572,12 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test )
|
|||
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);
|
||||
place_bet(ath.paula_id, capitals_win_market2.id, bet_type::back, asset(10000, btc_id), 11 * GRAPHENE_BETTING_ODDS_PRECISION);
|
||||
place_bet(ath.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);
|
||||
place_bet(ath.paula_id, capitals_win_market2.id, bet_type::lay, asset(110000, btc_id), 2 * GRAPHENE_BETTING_ODDS_PRECISION);
|
||||
place_bet(ath.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,
|
||||
|
|
@ -608,16 +587,16 @@ BOOST_AUTO_TEST_CASE( bookie_payout_test )
|
|||
|
||||
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 );
|
||||
BOOST_CHECK_EQUAL( get_balance( ath.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 ) );
|
||||
BOOST_CHECK_EQUAL( 600, get_balance( ath.alice_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( 0, get_balance( ath.ann_id, btc_id ) );
|
||||
BOOST_CHECK_EQUAL( 0, get_balance( ath.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 );
|
||||
BOOST_CHECK_EQUAL( get_balance( ath.petra_id, btc_id ), 1000000 - 100000 + 110000 - 110000 + 0 - rake_value );
|
||||
// petra wins nothing -> no payout
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue