From cce5dcf6d045cf933662f06a0c30c0c2e240ddcd Mon Sep 17 00:00:00 2001 From: dimfred Date: Sun, 28 Oct 2018 14:10:30 +0100 Subject: [PATCH] added manger to sports + test (temp) --- .../include/graphene/chain/protocol/sport.hpp | 18 ++++- .../include/graphene/chain/sport_object.hpp | 4 + libraries/chain/sport_evaluator.cpp | 11 ++- tests/tests/operation_tests.cpp | 80 +++++++++++++++++++ 4 files changed, 109 insertions(+), 4 deletions(-) diff --git a/libraries/chain/include/graphene/chain/protocol/sport.hpp b/libraries/chain/include/graphene/chain/protocol/sport.hpp index a33e70e9..c9e3673b 100644 --- a/libraries/chain/include/graphene/chain/protocol/sport.hpp +++ b/libraries/chain/include/graphene/chain/protocol/sport.hpp @@ -30,6 +30,11 @@ namespace graphene { namespace chain { struct sport_create_operation : public base_operation { + struct ext + { + optional< account_id_type > manager; + }; + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; asset fee; @@ -38,7 +43,7 @@ struct sport_create_operation : public base_operation */ internationalized_string_type name; - extensions_type extensions; + extension< ext > extensions; account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } void validate()const; @@ -46,6 +51,11 @@ struct sport_create_operation : public base_operation struct sport_update_operation : public base_operation { + struct ext + { + optional< account_id_type > manager; + }; + struct fee_parameters_type { uint64_t fee = GRAPHENE_BLOCKCHAIN_PRECISION; }; asset fee; @@ -53,9 +63,9 @@ struct sport_update_operation : public base_operation optional new_name; - extensions_type extensions; + extension< ext > extensions; - account_id_type fee_payer()const { return GRAPHENE_WITNESS_ACCOUNT; } + account_id_type fee_payer()const { return extensions.value.manager.valid() ? *extensions.value.manager : GRAPHENE_WITNESS_ACCOUNT; } void validate()const; }; @@ -75,10 +85,12 @@ struct sport_delete_operation : public base_operation } } FC_REFLECT( graphene::chain::sport_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::sport_create_operation::ext, (manager) ) FC_REFLECT( graphene::chain::sport_create_operation, (fee)(name)(extensions) ) FC_REFLECT( graphene::chain::sport_update_operation::fee_parameters_type, (fee) ) +FC_REFLECT( graphene::chain::sport_update_operation::ext, (manager) ) FC_REFLECT( graphene::chain::sport_update_operation, (fee)(sport_id)(new_name)(extensions) ) diff --git a/libraries/chain/include/graphene/chain/sport_object.hpp b/libraries/chain/include/graphene/chain/sport_object.hpp index 4f3139d8..1bd25443 100644 --- a/libraries/chain/include/graphene/chain/sport_object.hpp +++ b/libraries/chain/include/graphene/chain/sport_object.hpp @@ -38,6 +38,10 @@ class sport_object : public graphene::db::abstract_object< sport_object > static const uint8_t type_id = sport_object_type; internationalized_string_type name; + + /// manager account can modify the sportobject without the permission + /// of the witness_account, also he can modify all objects beneath (event_group etc.) + account_id_type manager; }; typedef multi_index_container< diff --git a/libraries/chain/sport_evaluator.cpp b/libraries/chain/sport_evaluator.cpp index 64994306..87648322 100644 --- a/libraries/chain/sport_evaluator.cpp +++ b/libraries/chain/sport_evaluator.cpp @@ -32,6 +32,11 @@ namespace graphene { namespace chain { +bool is_manager( const sport_id_type sport_id, const account_id_type manager_id ) +{ + return db().get(sport_id).manager == manager_id; +} + void_result sport_create_evaluator::do_evaluate(const sport_create_operation& op) { try { FC_ASSERT(db().head_block_time() >= HARDFORK_1000_TIME); @@ -45,6 +50,8 @@ object_id_type sport_create_evaluator::do_apply(const sport_create_operation& op const sport_object& new_sport = db().create( [&]( sport_object& sport_obj ) { sport_obj.name = op.name; + if( op.extensions.value.manager.valid() ) + sport_obj.manager = *op.extesions.value.manager; }); return new_sport.id; } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -53,7 +60,9 @@ object_id_type sport_create_evaluator::do_apply(const sport_create_operation& op void_result sport_update_evaluator::do_evaluate(const sport_update_operation& op) { try { FC_ASSERT(db().head_block_time() >= HARDFORK_1000_TIME); - FC_ASSERT(trx_state->_is_proposed_trx); + FC_ASSERT(trx_state->_is_proposed_trx + || op.extensions.value.manager.valid() ? is_manager( op.sport_id, *op.extensions.value.manager ) : false ); + FC_ASSERT(op.new_name.valid()); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 1f396156..4ff3f5f2 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -1816,6 +1816,86 @@ BOOST_AUTO_TEST_CASE( vesting_balance_withdraw_test ) // TODO: Test with non-core asset and Bob account } FC_LOG_AND_RETHROW() } + +BOOST_AUTO_TEST_CASE( manager_test ) +{ try { + #define PUSH_TX_D( TRX ) \ + processed_transaction ptrx; \ + try { \ + PUSH_TX( db, TRX, ~0); \ + } catch (fc::exception &e ) { \ + edump( ( e.to_detail_string() ) ); \ + } + + #define EDUMP( MSG ) edump( ( MSG ) ) + + ACTOR( alice ); + database& db = db(); + + sport_id_type sport_id; + + EDUMP( "1. create a sport with alice as manager" ); + { + sport_create_operation scop; + scop.name = "TEST_SPORT"; + scop.extensions.value.manager = alice_id; + // fee_paying_account is allways WITNESS_ACC + + proposal_create_operation pcop = proposal_create_operation::commitee_proposal( + db.get_global_properties(), + db.head_block_time() + ); + pcop.fee = asset(0); + pcop.fee_paying_account = alice_id; + pcop.review_period_seconds.reset(); + fc::time_point_sec exp_time = db.head_block_time() + fc::seconds(10); + pcop.expiration_time = exp_time; + pcop.proposed_ops.push_back( scop ); + + signed_transaction trx; + set_expiration( db, trx ); + trx.operations.push_back( pcop ); + PUSH_TX_D( trx ); + + EDUMP( "1.1 Wait till proposal is executed" ); + { + while( exp + fc::seconds(5) > db.head_block_time() ) + { + + } + + const auto& idx = db.get_index_type(); + idx.inspect_all_objects( [&](const object& obj){ + const sport_object& so = static_cast(obj); + if(so.name == "TEST_SPORT"){ + sport_id = so.id; + } + } ); + } + } + + + + EDUMP( "2. modify the sport with WITNESS_ACCOUNT" ); + { + + } + + EDUMP( "3. modify the sport with alice_acc" ); + { + + } + + EDUMP( "4. modify with a proposal but with manager set" ); + { + + } + + } catch( fc::exception &e ) { + edump( (e.to_detail_string() ) ); + } +} + // TODO: Write linear VBO tests BOOST_AUTO_TEST_SUITE_END()