Skip to content

Commit

Permalink
Merge pull request #2622 from steemit/2621-cleanup-fixture-vests
Browse files Browse the repository at this point in the history
Don't use debug_update in vest() override #2621
  • Loading branch information
Michael Vandeberg committed Jul 12, 2018
2 parents 97640ae + 48d63da commit d35c10b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 49 deletions.
42 changes: 25 additions & 17 deletions tests/db_fixture/database_fixture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,39 +465,47 @@ void database_fixture::transfer(
} FC_CAPTURE_AND_RETHROW( (from)(to)(amount) )
}

void database_fixture::vest( const string& from, const share_type& amount )
void database_fixture::vest( const string& from, const string& to, const asset& amount )
{
try
{
FC_ASSERT( amount.symbol == STEEM_SYMBOL, "Can only vest TESTS" );

transfer_to_vesting_operation op;
op.from = from;
op.to = "";
op.amount = asset( amount, STEEM_SYMBOL );
op.to = to;
op.amount = amount;

trx.operations.push_back( op );
trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
trx.validate();

// This sign() call fixes some tests, like withdraw_vesting_apply, that use this method
// with debug_plugin such that trx may be re-applied with less generous skip flags.
if( from == STEEM_INIT_MINER_NAME )
sign( trx, init_account_priv_key );

db->push_transaction( trx, ~0 );
trx.operations.clear();
} FC_CAPTURE_AND_RETHROW( (from)(amount) )
trx.signatures.clear();
} FC_CAPTURE_AND_RETHROW( (from)(to)(amount) )
}

void database_fixture::vest( const string& account, const asset& amount )
void database_fixture::vest( const string& from, const share_type& amount )
{
if( amount.symbol != STEEM_SYMBOL )
return;

db_plugin->debug_update( [=]( database& db )
try
{
db.modify( db.get_dynamic_global_properties(), [&]( dynamic_global_property_object& gpo )
{
gpo.current_supply += amount;
});

db.create_vesting( db.get_account( account ), amount );
transfer_to_vesting_operation op;
op.from = from;
op.to = "";
op.amount = asset( amount, STEEM_SYMBOL );

db.update_virtual_supply();
}, default_skip );
trx.operations.push_back( op );
trx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );
trx.validate();
db->push_transaction( trx, ~0 );
trx.operations.clear();
} FC_CAPTURE_AND_RETHROW( (from)(amount) )
}

void database_fixture::proxy( const string& account, const string& proxy )
Expand Down
2 changes: 1 addition & 1 deletion tests/db_fixture/database_fixture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ struct database_fixture {
void fund( const string& account_name, const asset& amount );
void transfer( const string& from, const string& to, const asset& amount );
void convert( const string& account_name, const asset& amount );
void vest( const string& from, const string& to, const asset& amount );
void vest( const string& from, const share_type& amount );
void vest( const string& account, const asset& amount );
void proxy( const string& account, const string& proxy );
void set_price_feed( const price& new_price );
void set_witness_props( const flat_map< string, vector< char > >& new_props );
Expand Down
34 changes: 17 additions & 17 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ BOOST_AUTO_TEST_CASE( account_create_apply )

BOOST_TEST_MESSAGE( "--- Test account creation with temp account does not set recovery account" );
fund( STEEM_TEMP_ACCOUNT, ASSET( "310.000 TESTS" ) );
vest( STEEM_TEMP_ACCOUNT, ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, STEEM_TEMP_ACCOUNT, ASSET( "10.000 TESTS" ) );
op.creator = STEEM_TEMP_ACCOUNT;
op.fee = ASSET( "300.000 TESTS" );
op.new_account_name = "bob";
Expand Down Expand Up @@ -627,7 +627,7 @@ BOOST_AUTO_TEST_CASE( comment_delete_apply )
ACTORS( (alice) )
generate_block();

vest( "alice", ASSET( "1000.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "1000.000 TESTS" ) );

generate_block();

Expand Down Expand Up @@ -756,11 +756,11 @@ BOOST_AUTO_TEST_CASE( vote_apply )
ACTORS( (alice)(bob)(sam)(dave) )
generate_block();

vest( "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
validate_database();
vest( "bob" , ASSET( "10.000 TESTS" ) );
vest( "sam" , ASSET( "10.000 TESTS" ) );
vest( "dave" , ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob" , ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "sam" , ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "dave" , ASSET( "10.000 TESTS" ) );
generate_block();

const auto& vote_idx = db->get_index< comment_vote_index >().indices().get< by_comment_voter >();
Expand Down Expand Up @@ -1469,7 +1469,7 @@ BOOST_AUTO_TEST_CASE( withdraw_vesting_apply )

ACTORS( (alice)(bob) )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );

BOOST_TEST_MESSAGE( "--- Test failure withdrawing negative VESTS" );

Expand Down Expand Up @@ -5776,8 +5776,8 @@ BOOST_AUTO_TEST_CASE( decline_voting_rights_apply )

ACTORS( (alice)(bob) );
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );
generate_block();

account_witness_proxy_operation proxy;
Expand Down Expand Up @@ -5924,9 +5924,9 @@ BOOST_AUTO_TEST_CASE( account_bandwidth )
BOOST_TEST_MESSAGE( "Testing: account_bandwidth" );
ACTORS( (alice)(bob) )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
fund( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );

generate_block();
db->skip_transaction_delta_check = false;
Expand Down Expand Up @@ -6089,7 +6089,7 @@ BOOST_AUTO_TEST_CASE( account_create_with_delegation_apply )
//auto gpo = db->get_dynamic_global_properties();
generate_blocks(1);
fund( "alice", ASSET("1510.000 TESTS") );
vest( "alice", ASSET("1000.000 TESTS") );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET("1000.000 TESTS") );

private_key_type priv_key = generate_private_key( "temp_key" );

Expand Down Expand Up @@ -6243,7 +6243,7 @@ BOOST_AUTO_TEST_CASE( delegate_vesting_shares_authorities )
BOOST_TEST_MESSAGE( "Testing: delegate_vesting_shares_authorities" );
signed_transaction tx;
ACTORS( (alice)(bob) )
vest( "alice", ASSET( "10000.000000 VESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10000.000 TESTS" ) );

delegate_vesting_shares_operation op;
op.vesting_shares = ASSET( "300.000000 VESTS");
Expand Down Expand Up @@ -6293,7 +6293,7 @@ BOOST_AUTO_TEST_CASE( delegate_vesting_shares_apply )
ACTORS( (alice)(bob)(charlie) )
generate_block();

vest( "alice", ASSET( "1000.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "1000.000 TESTS" ) );

generate_block();

Expand Down Expand Up @@ -6398,7 +6398,7 @@ BOOST_AUTO_TEST_CASE( delegate_vesting_shares_apply )
ACTORS( (sam)(dave) )
generate_block();

vest( "sam", ASSET( "1000.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "sam", ASSET( "1000.000 TESTS" ) );

generate_block();

Expand Down Expand Up @@ -6501,7 +6501,7 @@ BOOST_AUTO_TEST_CASE( issue_971_vesting_removal )
ACTORS( (alice)(bob) )
generate_block();

vest( "alice", ASSET( "1000.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "1000.000 TESTS" ) );

generate_block();

Expand Down Expand Up @@ -7255,7 +7255,7 @@ BOOST_AUTO_TEST_CASE( create_claimed_account_apply )
BOOST_TEST_MESSAGE( "Testing: create_claimed_account_apply" );

ACTORS( (alice) )
vest( STEEM_TEMP_ACCOUNT, ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, STEEM_TEMP_ACCOUNT, ASSET( "10.000 TESTS" ) );
generate_block();

signed_transaction tx;
Expand Down
20 changes: 10 additions & 10 deletions tests/tests/operation_time_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ BOOST_AUTO_TEST_CASE( comment_payout_dust )
ACTORS( (alice)(bob) )
generate_block();

vest( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );

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

Expand Down Expand Up @@ -1532,7 +1532,7 @@ BOOST_AUTO_TEST_CASE( convert_delay )
{
ACTORS( (alice) )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
fund( "alice", ASSET( "25.000 TBD" ) );

set_price_feed( price( ASSET( "1.000 TBD" ), ASSET( "1.250 TESTS" ) ) );
Expand Down Expand Up @@ -1776,8 +1776,8 @@ BOOST_AUTO_TEST_CASE( sbd_interest )
{
ACTORS( (alice)(bob) )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );

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

Expand Down Expand Up @@ -1861,10 +1861,10 @@ BOOST_AUTO_TEST_CASE( liquidity_rewards )

ACTORS( (alice)(bob)(sam)(dave) )
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( "sam", ASSET( "10.000 TESTS" ) );
vest( "dave", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "sam", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "dave", ASSET( "10.000 TESTS" ) );

BOOST_TEST_MESSAGE( "Rewarding Bob with TESTS" );

Expand Down Expand Up @@ -2821,7 +2821,7 @@ BOOST_AUTO_TEST_CASE( sbd_price_feed_limit )
{
ACTORS( (alice) );
generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );

price exchange_rate( ASSET( "1.000 TBD" ), ASSET( "1.000 TESTS" ) );
set_price_feed( exchange_rate );
Expand Down
8 changes: 4 additions & 4 deletions tests/tests/smt_operation_time_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ BOOST_AUTO_TEST_CASE( smt_liquidity_rewards )
asset_symbol_type any_smt_symbol = create_smt( "smtcreator", smtcreator_private_key, 3);

generate_block();
vest( "alice", ASSET( "10.000 TESTS" ) );
vest( "bob", ASSET( "10.000 TESTS" ) );
vest( "sam", ASSET( "10.000 TESTS" ) );
vest( "dave", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "alice", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "bob", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "sam", ASSET( "10.000 TESTS" ) );
vest( STEEM_INIT_MINER_NAME, "dave", ASSET( "10.000 TESTS" ) );

tx.operations.clear();
tx.signatures.clear();
Expand Down

0 comments on commit d35c10b

Please sign in to comment.