Skip to content

Commit

Permalink
Create test that breaks block size on block generation #2632
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Jul 13, 2018
1 parent 69cf04e commit 21df985
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/tests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,5 +807,58 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture )
FC_LOG_AND_RETHROW()
}

BOOST_FIXTURE_TEST_CASE( generate_block_size, clean_database_fixture )
{
try
{
db_plugin->debug_update( [=]( database& db )
{
db.modify( db.get_dynamic_global_properties(), [&]( dynamic_global_property_object& gpo )
{
gpo.maximum_block_size = STEEM_MIN_BLOCK_SIZE_LIMIT;
});
});
generate_block();

signed_transaction tx;
tx.set_expiration( db->head_block_time() + STEEM_MAX_TIME_UNTIL_EXPIRATION );

transfer_operation op;
op.from = STEEM_INIT_MINER_NAME;
op.to = STEEM_TEMP_ACCOUNT;
op.amount = asset( 1000, STEEM_SYMBOL );

// tx minus op is 79 bytes
// op is 33 bytes (32 for op + 1 byte static variant tag)
// total is 65254
// Original generation logic only allowed 115 bytes for the header
// We are targetting a size (minus header) of 65421 which creates a block of "size" 65535
// This block will actually be larger because the header estimates is too small

for( size_t i = 0; i < 1975; i++ )
{
tx.operations.push_back( op );
}

sign( tx, init_account_priv_key );
db->push_transaction( tx, 0 );

// Second transaction, tx minus op is 78 (one less byte for operation vector size)
// We need a 88 byte op. We need a 22 character memo (1 byte for length) 55 = 32 (old op) + 55 + 1
op.memo = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123";
tx.clear();
tx.operations.push_back( op );
sign( tx, init_account_priv_key );
db->push_transaction( tx, 0 );

generate_block();

// The last transfer should have been delayed due to size
auto head_block = db->fetch_block_by_number( db->head_block_num() );
BOOST_REQUIRE( head_block->transactions.size() == 1 );
}
FC_LOG_AND_RETHROW()
}

BOOST_AUTO_TEST_SUITE_END()
#endif

0 comments on commit 21df985

Please sign in to comment.