Merge branch 'feature/SON-98' into feature/SON-231

This commit is contained in:
Srdjan Obucina 2020-02-03 20:13:51 +01:00
commit 703c577d90
4 changed files with 196 additions and 29 deletions

View file

@ -8,7 +8,7 @@ namespace graphene { namespace chain {
void_result recreate_son_wallet_evaluator::do_evaluate(const son_wallet_recreate_operation& op)
{ try{
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
//FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id() );
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
@ -56,7 +56,7 @@ object_id_type recreate_son_wallet_evaluator::do_apply(const son_wallet_recreate
void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_operation& op)
{ try{
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
//FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id() );
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();

View file

@ -51,6 +51,7 @@
#include <fc/crypto/digest.hpp>
#include <fc/smart_ref_impl.hpp>
#include <exception>
#include <iostream>
#include <iomanip>
#include <sstream>
@ -265,11 +266,11 @@ void database_fixture::verify_asset_supplies( const database& db )
total_balances[betting_market_group.asset_id] += o.fees_collected;
}
uint64_t sweeps_vestings = 0;
for( const sweeps_vesting_balance_object& svbo: db.get_index_type< sweeps_vesting_balance_index >().indices() )
sweeps_vestings += svbo.balance;
total_balances[db.get_global_properties().parameters.sweeps_distribution_asset()] += sweeps_vestings / SWEEPS_VESTING_BALANCE_MULTIPLIER;
total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget;
total_balances[asset_id_type()] += db.get_dynamic_global_properties().son_budget;
@ -413,6 +414,23 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i
generate_block(skip);
}
bool database_fixture::generate_maintenance_block() {
try {
fc::ecc::private_key committee_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("nathan")));
uint32_t skip = ~database::skip_fork_db;
auto maint_time = db.get_dynamic_global_properties().next_maintenance_time;
auto slots_to_miss = db.get_slot_at_time(maint_time);
db.generate_block(db.get_slot_time(slots_to_miss),
db.get_scheduled_witness(slots_to_miss),
committee_key,
skip);
return true;
} catch (std::exception& e)
{
return false;
}
}
account_create_operation database_fixture::make_account(
const std::string& name /* = "nathan" */,
public_key_type key /* = key_id_type() */
@ -731,7 +749,7 @@ const witness_object& database_fixture::create_witness( const account_object& ow
witness_create_operation op;
op.witness_account = owner.id;
op.block_signing_key = signing_private_key.get_public_key();
secret_hash_type::encoder enc;
fc::raw::pack(enc, signing_private_key);
fc::raw::pack(enc, secret_hash_type());
@ -1116,12 +1134,12 @@ int64_t database_fixture::get_balance( const account_object& account, const asse
}
int64_t database_fixture::get_dividend_pending_payout_balance(asset_id_type dividend_holder_asset_type,
account_id_type dividend_holder_account_id,
asset_id_type dividend_payout_asset_type) const
account_id_type dividend_holder_account_id,
asset_id_type dividend_payout_asset_type) const
{
const pending_dividend_payout_balance_for_holder_object_index& pending_payout_balance_index =
const pending_dividend_payout_balance_for_holder_object_index& pending_payout_balance_index =
db.get_index_type<pending_dividend_payout_balance_for_holder_object_index>();
auto pending_payout_iter =
auto pending_payout_iter =
pending_payout_balance_index.indices().get<by_dividend_payout_account>().find(boost::make_tuple(dividend_holder_asset_type, dividend_payout_asset_type, dividend_holder_account_id));
if (pending_payout_iter == pending_payout_balance_index.indices().get<by_dividend_payout_account>().end())
return 0;
@ -1342,7 +1360,7 @@ void database_fixture::delete_sport(sport_id_type sport_id)
sport_delete_op.sport_id = sport_id;
process_operation_by_witnesses(sport_delete_op);
} FC_CAPTURE_AND_RETHROW( (sport_id) ) }
const event_group_object& database_fixture::create_event_group(internationalized_string_type name, sport_id_type sport_id)
{ try {
event_group_create_operation event_group_create_op;
@ -1372,7 +1390,7 @@ void database_fixture::delete_event_group(event_group_id_type event_group_id)
process_operation_by_witnesses(event_group_delete_op);
} FC_CAPTURE_AND_RETHROW( (event_group_id) )
}
void database_fixture::try_update_event_group(event_group_id_type event_group_id,
fc::optional<object_id_type> sport_id,
fc::optional<internationalized_string_type> name,
@ -1412,7 +1430,7 @@ void database_fixture::update_event_impl(event_id_type event_id,
fc::optional<object_id_type> event_group_id,
fc::optional<internationalized_string_type> name,
fc::optional<internationalized_string_type> season,
fc::optional<event_status> status,
fc::optional<event_status> status,
bool force)
{ try {
event_update_operation event_update_op;
@ -1449,9 +1467,9 @@ void database_fixture::update_betting_market_rules(betting_market_rules_id_type
process_operation_by_witnesses(betting_market_rules_update_op);
} FC_CAPTURE_AND_RETHROW( (name)(description) ) }
const betting_market_group_object& database_fixture::create_betting_market_group(internationalized_string_type description,
event_id_type event_id,
betting_market_rules_id_type rules_id,
const betting_market_group_object& database_fixture::create_betting_market_group(internationalized_string_type description,
event_id_type event_id,
betting_market_rules_id_type rules_id,
asset_id_type asset_id,
bool never_in_play,
uint32_t delay_before_settling)
@ -1521,7 +1539,7 @@ void database_fixture::update_betting_market(betting_market_id_type betting_mark
bet_place_op.amount_to_bet = amount_to_bet;
bet_place_op.backer_multiplier = backer_multiplier;
bet_place_op.back_or_lay = back_or_lay;
trx.operations.push_back(bet_place_op);
trx.validate();
processed_transaction ptx = db.push_transaction(trx, ~0);

View file

@ -199,6 +199,12 @@ struct database_fixture {
*/
void generate_blocks(fc::time_point_sec timestamp, bool miss_intermediate_blocks = true, uint32_t skip = ~0);
///////////
/// @brief Skip intermediate blocks, and generate a maintenance block
/// @returns true on success
///////////
bool generate_maintenance_block();
account_create_operation make_account(
const std::string& name = "nathan",
public_key_type = public_key_type()
@ -295,7 +301,7 @@ struct database_fixture {
int64_t get_balance( account_id_type account, asset_id_type a )const;
int64_t get_balance( const account_object& account, const asset_object& a )const;
int64_t get_dividend_pending_payout_balance(asset_id_type dividend_holder_asset_type,
account_id_type dividend_holder_account_id,
account_id_type dividend_holder_account_id,
asset_id_type dividend_payout_asset_type) const;
vector< operation_history_object > get_operation_history( account_id_type account_id )const;
void process_operation_by_witnesses(operation op);
@ -321,7 +327,7 @@ struct database_fixture {
fc::optional<internationalized_string_type> season,
fc::optional<event_status> status,
bool force);
BOOST_PARAMETER_MEMBER_FUNCTION((void), update_event, keywords::tag,
BOOST_PARAMETER_MEMBER_FUNCTION((void), update_event, keywords::tag,
(required (event_id, (event_id_type)))
(optional (event_group_id, (fc::optional<object_id_type>), fc::optional<object_id_type>())
(name, (fc::optional<internationalized_string_type>), fc::optional<internationalized_string_type>())
@ -336,9 +342,9 @@ struct database_fixture {
void update_betting_market_rules(betting_market_rules_id_type rules_id,
fc::optional<internationalized_string_type> name,
fc::optional<internationalized_string_type> description);
const betting_market_group_object& create_betting_market_group(internationalized_string_type description,
event_id_type event_id,
betting_market_rules_id_type rules_id,
const betting_market_group_object& create_betting_market_group(internationalized_string_type description,
event_id_type event_id,
betting_market_rules_id_type rules_id,
asset_id_type asset_id,
bool never_in_play,
uint32_t delay_before_settling);
@ -347,7 +353,7 @@ struct database_fixture {
fc::optional<object_id_type> rules_id,
fc::optional<betting_market_group_status> status,
bool force);
BOOST_PARAMETER_MEMBER_FUNCTION((void), update_betting_market_group, keywords::tag,
BOOST_PARAMETER_MEMBER_FUNCTION((void), update_betting_market_group, keywords::tag,
(required (betting_market_group_id, (betting_market_group_id_type)))
(optional (description, (fc::optional<internationalized_string_type>), fc::optional<internationalized_string_type>())
(rules_id, (fc::optional<object_id_type>), fc::optional<object_id_type>())

View file

@ -6,23 +6,147 @@
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
using namespace graphene;
using namespace graphene::chain;
using namespace graphene::chain::test;
BOOST_FIXTURE_TEST_SUITE( son_wallet_tests, database_fixture )
BOOST_AUTO_TEST_CASE( son_wallet_create_test ) {
BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
BOOST_TEST_MESSAGE("son_wallet_create_test");
BOOST_TEST_MESSAGE("son_wallet_recreate_test");
generate_blocks(HARDFORK_SON_TIME);
generate_block();
set_expiration(db, trx);
ACTORS((alice)(bob));
upgrade_to_lifetime_member(alice);
upgrade_to_lifetime_member(bob);
transfer( committee_account, alice_id, asset( 500000*GRAPHENE_BLOCKCHAIN_PRECISION ) );
transfer( committee_account, bob_id, asset( 500000*GRAPHENE_BLOCKCHAIN_PRECISION ) );
generate_block();
set_expiration(db, trx);
ACTORS((alice));
std::string test_url = "https://create_son_test";
// create deposit vesting
vesting_balance_id_type deposit_alice;
{
vesting_balance_create_operation op;
op.creator = alice_id;
op.owner = alice_id;
op.amount = asset(500 * GRAPHENE_BLOCKCHAIN_PRECISION);
op.balance_type = vesting_balance_type::son;
op.policy = dormant_vesting_policy_initializer {};
trx.operations.push_back(op);
sign(trx, alice_private_key);
processed_transaction ptx = PUSH_TX(db, trx, ~0);
trx.clear();
deposit_alice = ptx.operation_results[0].get<object_id_type>();
}
generate_block();
set_expiration(db, trx);
// create payment normal vesting
vesting_balance_id_type payment_alice;
{
vesting_balance_create_operation op;
op.creator = alice_id;
op.owner = alice_id;
op.amount = asset(500 * GRAPHENE_BLOCKCHAIN_PRECISION);
op.balance_type = vesting_balance_type::normal;
trx.operations.push_back(op);
sign(trx, alice_private_key);
processed_transaction ptx = PUSH_TX(db, trx, ~0);
trx.clear();
payment_alice = ptx.operation_results[0].get<object_id_type>();
}
generate_block();
set_expiration(db, trx);
// alice becomes son
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
son_create_operation op;
op.owner_account = alice_id;
op.url = test_url;
op.deposit = deposit_alice;
op.pay_vb = payment_alice;
op.signing_key = alice_public_key;
op.sidechain_public_keys = sidechain_public_keys;
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX(db, trx, ~0);
trx.clear();
}
generate_block();
set_expiration(db, trx);
// create deposit vesting
vesting_balance_id_type deposit_bob;
{
vesting_balance_create_operation op;
op.creator = bob_id;
op.owner = bob_id;
op.amount = asset(500 * GRAPHENE_BLOCKCHAIN_PRECISION);
op.balance_type = vesting_balance_type::son;
op.policy = dormant_vesting_policy_initializer {};
trx.operations.push_back(op);
sign(trx, bob_private_key);
processed_transaction ptx = PUSH_TX(db, trx, ~0);
trx.clear();
deposit_bob = ptx.operation_results[0].get<object_id_type>();
}
generate_block();
set_expiration(db, trx);
// create payment normal vesting
vesting_balance_id_type payment_bob ;
{
vesting_balance_create_operation op;
op.creator = bob_id;
op.owner = bob_id;
op.amount = asset(500 * GRAPHENE_BLOCKCHAIN_PRECISION);
op.balance_type = vesting_balance_type::normal;
trx.operations.push_back(op);
sign(trx, bob_private_key);
processed_transaction ptx = PUSH_TX(db, trx, ~0);
trx.clear();
payment_bob = ptx.operation_results[0].get<object_id_type>();
}
generate_block();
set_expiration(db, trx);
// bob becomes son
{
flat_map<graphene::peerplays_sidechain::sidechain_type, string> sidechain_public_keys;
sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address";
son_create_operation op;
op.owner_account = bob_id;
op.url = test_url;
op.deposit = deposit_bob;
op.pay_vb = payment_bob;
op.signing_key = bob_public_key;
op.sidechain_public_keys = sidechain_public_keys;
trx.operations.push_back(op);
sign(trx, alice_private_key);
PUSH_TX(db, trx, ~0);
trx.clear();
}
generate_block();
set_expiration(db, trx);
generate_blocks(60);
set_expiration(db, trx);
{
BOOST_TEST_MESSAGE("Send son_wallet_recreate_operation");
@ -30,18 +154,36 @@ BOOST_AUTO_TEST_CASE( son_wallet_create_test ) {
op.payer = db.get_global_properties().parameters.get_son_btc_account_id();
{
son_info si;
si.son_id = son_id_type(0);
si.total_votes = 1000;
si.signing_key = alice_public_key;
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
op.sons.push_back(si);
}
{
son_info si;
si.son_id = son_id_type(1);
si.total_votes = 1000;
si.signing_key = bob_public_key;
si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = "";
op.sons.push_back(si);
}
trx.operations.push_back(op);
sign(trx, alice_private_key);
//PUSH_TX(db, trx, ~0);
PUSH_TX(db, trx, ~0);
}
generate_block();
BOOST_TEST_MESSAGE("Check son_wallet_create_operation results");
BOOST_TEST_MESSAGE("Check son_wallet_recreate_operation results");
const auto& idx = db.get_index_type<son_wallet_index>().indices().get<by_id>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find(son_wallet_id_type(0));
BOOST_REQUIRE( obj->addresses.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "" );
BOOST_REQUIRE( obj != idx.end() );
BOOST_REQUIRE( obj->expires == time_point_sec::maximum() );
}
@ -49,7 +191,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) {
BOOST_TEST_MESSAGE("son_wallet_update_test");
INVOKE(son_wallet_create_test);
INVOKE(son_wallet_recreate_test);
GET_ACTOR(alice);
{
@ -74,6 +216,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) {
const auto& idx = db.get_index_type<son_wallet_index>().indices().get<by_id>();
BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find(son_wallet_id_type(0));
BOOST_REQUIRE( obj != idx.end() );
BOOST_REQUIRE( obj->addresses.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" );
}