Added unit test for affiliate_stats plugin and API
This commit is contained in:
parent
ac078afff0
commit
b40e823875
2 changed files with 121 additions and 2 deletions
|
|
@ -28,6 +28,7 @@
|
||||||
#include <graphene/market_history/market_history_plugin.hpp>
|
#include <graphene/market_history/market_history_plugin.hpp>
|
||||||
#include <graphene/bookie/bookie_plugin.hpp>
|
#include <graphene/bookie/bookie_plugin.hpp>
|
||||||
#include <graphene/bookie/bookie_api.hpp>
|
#include <graphene/bookie/bookie_api.hpp>
|
||||||
|
#include <graphene/affiliate_stats/affiliate_stats_plugin.hpp>
|
||||||
|
|
||||||
#include <graphene/db/simple_index.hpp>
|
#include <graphene/db/simple_index.hpp>
|
||||||
|
|
||||||
|
|
@ -83,6 +84,7 @@ database_fixture::database_fixture()
|
||||||
auto ahplugin = app.register_plugin<graphene::account_history::account_history_plugin>();
|
auto ahplugin = app.register_plugin<graphene::account_history::account_history_plugin>();
|
||||||
auto mhplugin = app.register_plugin<graphene::market_history::market_history_plugin>();
|
auto mhplugin = app.register_plugin<graphene::market_history::market_history_plugin>();
|
||||||
auto bookieplugin = app.register_plugin<graphene::bookie::bookie_plugin>();
|
auto bookieplugin = app.register_plugin<graphene::bookie::bookie_plugin>();
|
||||||
|
auto affiliateplugin = app.register_plugin<graphene::affiliate_stats::affiliate_stats_plugin>();
|
||||||
init_account_pub_key = init_account_priv_key.get_public_key();
|
init_account_pub_key = init_account_priv_key.get_public_key();
|
||||||
|
|
||||||
boost::program_options::variables_map options;
|
boost::program_options::variables_map options;
|
||||||
|
|
@ -114,10 +116,13 @@ database_fixture::database_fixture()
|
||||||
mhplugin->plugin_initialize(options);
|
mhplugin->plugin_initialize(options);
|
||||||
bookieplugin->plugin_set_app(&app);
|
bookieplugin->plugin_set_app(&app);
|
||||||
bookieplugin->plugin_initialize(options);
|
bookieplugin->plugin_initialize(options);
|
||||||
|
affiliateplugin->plugin_set_app(&app);
|
||||||
|
affiliateplugin->plugin_initialize(options);
|
||||||
|
|
||||||
ahplugin->plugin_startup();
|
ahplugin->plugin_startup();
|
||||||
mhplugin->plugin_startup();
|
mhplugin->plugin_startup();
|
||||||
bookieplugin->plugin_startup();
|
bookieplugin->plugin_startup();
|
||||||
|
affiliateplugin->plugin_startup();
|
||||||
|
|
||||||
generate_block();
|
generate_block();
|
||||||
|
|
||||||
|
|
@ -451,7 +456,7 @@ const asset_object& database_fixture::get_asset( const string& symbol )const
|
||||||
{
|
{
|
||||||
const auto& idx = db.get_index_type<asset_index>().indices().get<by_symbol>();
|
const auto& idx = db.get_index_type<asset_index>().indices().get<by_symbol>();
|
||||||
const auto itr = idx.find(symbol);
|
const auto itr = idx.find(symbol);
|
||||||
assert( itr != idx.end() );
|
FC_ASSERT( itr != idx.end() );
|
||||||
return *itr;
|
return *itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -459,7 +464,7 @@ const account_object& database_fixture::get_account( const string& name )const
|
||||||
{
|
{
|
||||||
const auto& idx = db.get_index_type<account_index>().indices().get<by_name>();
|
const auto& idx = db.get_index_type<account_index>().indices().get<by_name>();
|
||||||
const auto itr = idx.find(name);
|
const auto itr = idx.find(name);
|
||||||
assert( itr != idx.end() );
|
FC_ASSERT( itr != idx.end() );
|
||||||
return *itr;
|
return *itr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include <graphene/chain/tournament_object.hpp>
|
#include <graphene/chain/tournament_object.hpp>
|
||||||
|
|
||||||
#include <graphene/affiliate_stats/affiliate_stats_api.hpp>
|
#include <graphene/affiliate_stats/affiliate_stats_api.hpp>
|
||||||
|
#include <graphene/affiliate_stats/affiliate_stats_objects.hpp>
|
||||||
|
|
||||||
using namespace graphene::chain;
|
using namespace graphene::chain;
|
||||||
using namespace graphene::db;
|
using namespace graphene::db;
|
||||||
|
|
@ -607,12 +608,125 @@ BOOST_AUTO_TEST_CASE( statistics_test )
|
||||||
{ try {
|
{ try {
|
||||||
|
|
||||||
INVOKE(rps_tournament_payout_test);
|
INVOKE(rps_tournament_payout_test);
|
||||||
|
|
||||||
|
affiliate_test_helper ath( *this );
|
||||||
|
|
||||||
|
transfer( ath.audrey_id, ath.alice_id, asset( 10 ), asset(0) );
|
||||||
|
transfer( ath.audrey_id, ath.ann_id, asset( 10 ), asset(0) );
|
||||||
|
|
||||||
INVOKE(bookie_payout_test);
|
INVOKE(bookie_payout_test);
|
||||||
|
|
||||||
|
const asset_id_type btc_id = get_asset( "BTC" ).id;
|
||||||
|
|
||||||
|
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) );
|
||||||
|
|
||||||
generate_block();
|
generate_block();
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto& idx = db.get_index_type<graphene::affiliate_stats::referral_reward_index>().indices().get<graphene::affiliate_stats::by_asset>();
|
||||||
|
BOOST_CHECK_EQUAL( 2, idx.size() ); // penny 216+60 CORE, paula 600 BTC
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const auto& idx = db.get_index_type<graphene::affiliate_stats::app_reward_index>().indices().get<graphene::affiliate_stats::by_asset>();
|
||||||
|
BOOST_CHECK_EQUAL( 3, idx.size() ); // rps 216 CORE, bookie 60 CORE + 600 BTC
|
||||||
|
}
|
||||||
|
|
||||||
graphene::affiliate_stats::affiliate_stats_api stats( app );
|
graphene::affiliate_stats::affiliate_stats_api stats( app );
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<graphene::affiliate_stats::referral_payment> refs = stats.list_historic_referral_rewards( ath.alice_id, operation_history_id_type() );
|
||||||
|
BOOST_CHECK_EQUAL( 3, refs.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::rps, refs[0].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 43, refs[0].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[0].payout.asset_id.instance.value );
|
||||||
|
BOOST_REQUIRE_LE( 2, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::bookie, refs[1].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 36, refs[1].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[1].payout.asset_id.instance.value );
|
||||||
|
BOOST_REQUIRE_LE( 3, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::bookie, refs[2].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 600, refs[2].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( btc_id.instance.value, refs[2].payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( 3, stats.list_historic_referral_rewards( ath.alice_id, refs[0].id ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 2, stats.list_historic_referral_rewards( ath.alice_id, refs[1].id ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 1, stats.list_historic_referral_rewards( ath.alice_id, refs[2].id ).size() );
|
||||||
|
|
||||||
|
refs = stats.list_historic_referral_rewards( ath.ann_id, operation_history_id_type() );
|
||||||
|
BOOST_CHECK_EQUAL( 2, refs.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::rps, refs[0].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 64, refs[0].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[0].payout.asset_id.instance.value );
|
||||||
|
BOOST_REQUIRE_LE( 2, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::bookie, refs[1].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 24, refs[1].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[1].payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( 2, stats.list_historic_referral_rewards( ath.ann_id, refs[0].id ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 1, stats.list_historic_referral_rewards( ath.ann_id, refs[1].id ).size() );
|
||||||
|
|
||||||
|
refs = stats.list_historic_referral_rewards( ath.audrey_id, operation_history_id_type() );
|
||||||
|
BOOST_CHECK_EQUAL( 1, refs.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::rps, refs[0].tag );
|
||||||
|
BOOST_CHECK_EQUAL( 109, refs[0].payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[0].payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_historic_referral_rewards( ath.alice_id, operation_history_id_type(9990) ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 1, stats.list_historic_referral_rewards( ath.alice_id, operation_history_id_type(), 1 ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_historic_referral_rewards( ath.paula_id, operation_history_id_type() ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_historic_referral_rewards( ath.penny_id, operation_history_id_type() ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_historic_referral_rewards( ath.petra_id, operation_history_id_type() ).size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<graphene::affiliate_stats::top_referred_account> refs = stats.list_top_referred_accounts( asset_id_type() );
|
||||||
|
BOOST_CHECK_EQUAL( 1, refs.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( ath.penny_id.instance.value, refs[0].referral.instance.value );
|
||||||
|
BOOST_CHECK_EQUAL( 276, refs[0].total_payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, refs[0].total_payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
refs = stats.list_top_referred_accounts( btc_id );
|
||||||
|
BOOST_CHECK_EQUAL( 1, refs.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, refs.size() );
|
||||||
|
BOOST_CHECK_EQUAL( ath.paula_id.instance.value, refs[0].referral.instance.value );
|
||||||
|
BOOST_CHECK_EQUAL( 600, refs[0].total_payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( btc_id.instance.value, refs[0].total_payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( 1, stats.list_top_referred_accounts( btc_id, 1 ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_top_referred_accounts( btc_id, 0 ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_top_referred_accounts( asset_id_type(9999) ).size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::vector<graphene::affiliate_stats::top_app> top = stats.list_top_rewards_per_app( asset_id_type() );
|
||||||
|
BOOST_CHECK_EQUAL( 2, top.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, top.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::rps, top[0].app );
|
||||||
|
BOOST_CHECK_EQUAL( 216, top[0].total_payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, top[0].total_payout.asset_id.instance.value );
|
||||||
|
BOOST_REQUIRE_LE( 2, top.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::bookie, top[1].app );
|
||||||
|
BOOST_CHECK_EQUAL( 60, top[1].total_payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( 0, top[1].total_payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
top = stats.list_top_rewards_per_app( btc_id );
|
||||||
|
BOOST_CHECK_EQUAL( 1, top.size() );
|
||||||
|
BOOST_REQUIRE_LE( 1, top.size() );
|
||||||
|
BOOST_CHECK_EQUAL( app_tag::bookie, top[0].app );
|
||||||
|
BOOST_CHECK_EQUAL( 600, top[0].total_payout.amount.value );
|
||||||
|
BOOST_CHECK_EQUAL( btc_id.instance.value, top[0].total_payout.asset_id.instance.value );
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL( 1, stats.list_top_rewards_per_app( asset_id_type(), 1 ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_top_referred_accounts( btc_id, 0 ).size() );
|
||||||
|
BOOST_CHECK_EQUAL( 0, stats.list_top_rewards_per_app( asset_id_type(9999) ).size() );
|
||||||
|
}
|
||||||
|
|
||||||
} FC_LOG_AND_RETHROW() }
|
} FC_LOG_AND_RETHROW() }
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue