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) void_result recreate_son_wallet_evaluator::do_evaluate(const son_wallet_recreate_operation& op)
{ try{ { try{
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); 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() ); 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>(); 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) void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_operation& op)
{ try{ { try{
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); 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() ); 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>(); 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/crypto/digest.hpp>
#include <fc/smart_ref_impl.hpp> #include <fc/smart_ref_impl.hpp>
#include <exception>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>
#include <sstream> #include <sstream>
@ -413,6 +414,23 @@ void database_fixture::generate_blocks(fc::time_point_sec timestamp, bool miss_i
generate_block(skip); 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( account_create_operation database_fixture::make_account(
const std::string& name /* = "nathan" */, const std::string& name /* = "nathan" */,
public_key_type key /* = key_id_type() */ public_key_type key /* = key_id_type() */

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); 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( account_create_operation make_account(
const std::string& name = "nathan", const std::string& name = "nathan",
public_key_type = public_key_type() public_key_type = public_key_type()

View file

@ -6,23 +6,147 @@
#include <graphene/chain/son_wallet_object.hpp> #include <graphene/chain/son_wallet_object.hpp>
#include <graphene/peerplays_sidechain/defs.hpp> #include <graphene/peerplays_sidechain/defs.hpp>
using namespace graphene;
using namespace graphene::chain; using namespace graphene::chain;
using namespace graphene::chain::test; using namespace graphene::chain::test;
BOOST_FIXTURE_TEST_SUITE( son_wallet_tests, database_fixture ) 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(); generate_block();
set_expiration(db, trx); 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(); generate_block();
set_expiration(db, trx); 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"); 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(); 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); trx.operations.push_back(op);
sign(trx, alice_private_key); sign(trx, alice_private_key);
//PUSH_TX(db, trx, ~0); PUSH_TX(db, trx, ~0);
} }
generate_block(); 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>(); const auto& idx = db.get_index_type<son_wallet_index>().indices().get<by_id>();
BOOST_REQUIRE( idx.size() == 1 ); BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find(son_wallet_id_type(0)); 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() ); 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"); BOOST_TEST_MESSAGE("son_wallet_update_test");
INVOKE(son_wallet_create_test); INVOKE(son_wallet_recreate_test);
GET_ACTOR(alice); 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>(); const auto& idx = db.get_index_type<son_wallet_index>().indices().get<by_id>();
BOOST_REQUIRE( idx.size() == 1 ); BOOST_REQUIRE( idx.size() == 1 );
auto obj = idx.find(son_wallet_id_type(0)); 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" ); BOOST_REQUIRE( obj->addresses.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" );
} }