Skip to content

Commit

Permalink
Test progress #773
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Vandeberg committed Feb 17, 2017
1 parent ce9d19f commit a835195
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 0 deletions.
14 changes: 14 additions & 0 deletions libraries/protocol/steem_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ namespace steemit { namespace protocol {
}
}

struct comment_options_extension_validate_visitor
{
comment_options_extension_validate_visitor() {}

typedef void result_type;

void operator()( const comment_payout_beneficiaries& cpb ) const
{
cpb.validate();
}
};

void comment_payout_beneficiaries::validate()const
{
uint32_t sum = 0;
Expand All @@ -98,6 +110,8 @@ namespace steemit { namespace protocol {
FC_ASSERT( max_accepted_payout.symbol == SBD_SYMBOL, "Max accepted payout must be in SBD" );
FC_ASSERT( max_accepted_payout.amount.value >= 0, "Cannot accept less than 0 payout" );
validate_permlink( permlink );
for( auto& e : extensions )
e.visit( comment_options_extension_validate_visitor() );
}

void delete_comment_operation::validate()const
Expand Down
107 changes: 107 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5995,5 +5995,112 @@ BOOST_AUTO_TEST_CASE( claim_reward_balance_apply )
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( comment_beneficiaries_validate )
{
try
{
comment_options_operation op;

op.author = "alice";
op.permlink = "test";

comment_payout_beneficiaries b;
b.beneficiaries.push_back( std::make_pair( account_name_type( "bob" ), STEEMIT_100_PERCENT + 1 ) );
op.extensions.insert( b );
STEEMIT_REQUIRE_THROW( op.validate(), fc::assert_exception );


b.beneficiaries.clear();
b.beneficiaries.push_back( std::make_pair( account_name_type( "bob" ), STEEMIT_1_PERCENT * 75 ) );
b.beneficiaries.push_back( std::make_pair( account_name_type( "sam" ), STEEMIT_1_PERCENT * 75 ) );
op.extensions.clear();
op.extensions.insert( b );
STEEMIT_REQUIRE_THROW( op.validate(), fc::assert_exception );

b.beneficiaries.clear();
for( size_t i = 0; i < 127; i++ )
{
b.beneficiaries.push_back( std::make_pair( account_name_type( "foo" + fc::to_string( i ) ), 1 ) );
}

op.extensions.clear();
op.extensions.insert( b );
op.validate();

b.beneficiaries.push_back( std::make_pair( account_name_type( "bar" ), 1 ) );
op.extensions.clear();
op.extensions.insert( b );
STEEMIT_REQUIRE_THROW( op.validate(), fc::assert_exception );
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_CASE( comment_beneficiaries_apply )
{
try
{
BOOST_TEST_MESSAGE( "Test Comment Beneficiaries" );
ACTORS( (alice)(bob)(sam) )
generate_block();

set_price_feed( price( ASSET( "1.000 TESTS" ), ASSET( "1.000 TBD" ) ) );

comment_operation comment;
vote_operation vote;
comment_options_operation op;
comment_payout_beneficiaries b;
signed_transaction tx;

comment.author = "alice";
comment.permlink = "test";
comment.parent_permlink = "test";
comment.title = "test";
comment.body = "foobar";

tx.operations.push_back( comment );
tx.set_expiration( db.head_block_time() + STEEMIT_MIN_TRANSACTION_EXPIRATION_LIMIT );
tx.sign( alice_private_key, db.get_chain_id() );
db.push_transaction( tx );

comment.author = "bob";
tx.clear();
tx.operations.push_back( comment );
tx.sign( bob_private_key, db.get_chain_id() );
db.push_transaction( tx );


BOOST_TEST_MESSAGE( "--- Test failure on more than 8 benefactors" );
for( size_t i = 0; i < 8; i++ )
{
b.beneficiaries.push_back( std::make_pair( account_name_type( STEEMIT_INIT_MINER_NAME + fc::to_string( i ) ), STEEMIT_1_PERCENT ) );
}

b.beneficiaries.push_back( std::make_pair( account_name_type( "bob" ), STEEMIT_1_PERCENT ) );
op.author = "alice";
op.permlink = "test";
op.extensions.insert( b );
tx.clear();
tx.operations.push_back( op );
tx.sign( alice_private_key, db.get_chain_id() );
STEEMIT_REQUIRE_THROW( db.push_transaction( tx ), fc::assert_exception );


BOOST_TEST_MESSAGE( "--- Test specifying a non-existent benefactor" );
b.beneficiaries.clear();
b.beneficiaries.push_back( std::make_pair( account_name_type( "dave" ), STEEMIT_1_PERCENT ) );
op.extenstions.clear();
op.extensions.insert( )

// Test setting when comment has been voted on

// Test success

// Test setting when there are already beneficiaries

// Payout and verify rewards were split properly
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_SUITE_END()
#endif

0 comments on commit a835195

Please sign in to comment.