added manger to sports + test (temp)
This commit is contained in:
parent
38272423c7
commit
cce5dcf6d0
4 changed files with 109 additions and 4 deletions
|
|
@ -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<internationalized_string_type> 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) )
|
||||
|
||||
|
|
|
|||
|
|
@ -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<
|
||||
|
|
|
|||
|
|
@ -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_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) ) }
|
||||
|
|
|
|||
|
|
@ -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<sport_index>();
|
||||
idx.inspect_all_objects( [&](const object& obj){
|
||||
const sport_object& so = static_cast<const sport_obj&>(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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue