Skip to content

Commit

Permalink
Merge pull request #273 from AntelopeIO/GH-264-unneeded-blocks
Browse files Browse the repository at this point in the history
Test: Remove production of unneeded blocks
  • Loading branch information
heifner authored Jun 11, 2024
2 parents 1570bf7 + ef6d68d commit 99e4f89
Show file tree
Hide file tree
Showing 25 changed files with 481 additions and 472 deletions.
6 changes: 3 additions & 3 deletions plugins/chain_plugin/test/test_account_query_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BOOST_FIXTURE_TEST_CASE(newaccount_test, validating_tester) { try {
aq_db.commit_block( block );
});

produce_blocks(10);
produce_block();

account_name tester_account = "tester"_n;
const auto trace_ptr = create_account(tester_account);
Expand All @@ -68,7 +68,7 @@ BOOST_FIXTURE_TEST_CASE(updateauth_test, validating_tester) { try {
aq_db.commit_block( block );
});

produce_blocks(10);
produce_block();

const auto& tester_account = "tester"_n;
const string role = "first";
Expand Down Expand Up @@ -103,7 +103,7 @@ BOOST_FIXTURE_TEST_CASE(updateauth_test_multi_threaded, validating_tester) { try
aq_db.commit_block( block );
});

produce_blocks(10);
produce_block();

const auto tester_account = "tester"_n;
const string role = "first";
Expand Down
6 changes: 3 additions & 3 deletions tests/chain_plugin_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ static auto get_account_full = [](chain_apis::read_only& plugin,
BOOST_AUTO_TEST_SUITE(chain_plugin_tests)

BOOST_FIXTURE_TEST_CASE( get_block_with_invalid_abi, validating_tester ) try {
produce_blocks(2);
produce_block();

create_accounts( {"asserter"_n} );
produce_block();

// setup contract and abi
set_code( "asserter"_n, test_contracts::asserter_wasm() );
set_abi( "asserter"_n, test_contracts::asserter_abi() );
produce_blocks(1);
produce_block();

auto resolver = [&,this]( const account_name& name ) -> std::optional<abi_serializer> {
try {
Expand Down Expand Up @@ -183,7 +183,7 @@ BOOST_AUTO_TEST_CASE( get_consensus_parameters ) try {
} FC_LOG_AND_RETHROW() //get_consensus_parameters

BOOST_FIXTURE_TEST_CASE( get_account, validating_tester ) try {
produce_blocks(2);
produce_block();

std::vector<account_name> accs{{ "alice"_n, "bob"_n, "cindy"_n}};
create_accounts(accs, false, false);
Expand Down
6 changes: 4 additions & 2 deletions tests/get_producers_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( get_producers, T, testers ) { try {
BOOST_REQUIRE(row.contains("producer_authority"));


chain.produce_blocks(2);
chain.produce_block();

chain.create_accounts( {"dan"_n,"sam"_n,"pam"_n} );
chain.produce_block();
chain.set_producers( {"dan"_n,"sam"_n,"pam"_n} );
chain.produce_blocks(30);
chain.produce_block();
chain.produce_block(fc::seconds(1000));
chain.produce_block();

results = plugin.get_producers(params, fc::time_point::maximum());
BOOST_REQUIRE_EQUAL(results.rows.size(), 3u);
Expand Down
26 changes: 13 additions & 13 deletions tests/get_table_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ issue_tokens( validating_tester& t, account_name issuer, account_name to, const
}

BOOST_FIXTURE_TEST_CASE( get_scope_test, validating_tester ) try {
produce_blocks(2);
produce_block();

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
"eosio.bpay"_n, "eosio.vpay"_n, "eosio.saving"_n, "eosio.names"_n });
Expand All @@ -75,7 +75,7 @@ BOOST_FIXTURE_TEST_CASE( get_scope_test, validating_tester ) try {

set_code( "eosio.token"_n, test_contracts::eosio_token_wasm() );
set_abi( "eosio.token"_n, test_contracts::eosio_token_abi() );
produce_blocks(1);
produce_block();

// create currency
auto act = mutable_variant_object()
Expand All @@ -87,7 +87,7 @@ BOOST_FIXTURE_TEST_CASE( get_scope_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("999.0000 SYS") );
}
produce_blocks(1);
produce_block();

// iterate over scope
eosio::chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum(), fc::microseconds::maximum(), {});
Expand Down Expand Up @@ -136,7 +136,7 @@ BOOST_FIXTURE_TEST_CASE( get_scope_test, validating_tester ) try {
} FC_LOG_AND_RETHROW() /// get_scope_test

BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
produce_blocks(2);
produce_block();

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
"eosio.bpay"_n, "eosio.vpay"_n, "eosio.saving"_n, "eosio.names"_n });
Expand All @@ -147,7 +147,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {

set_code( "eosio.token"_n, test_contracts::eosio_token_wasm() );
set_abi( "eosio.token"_n, test_contracts::eosio_token_abi() );
produce_blocks(1);
produce_block();

// create currency
auto act = mutable_variant_object()
Expand All @@ -159,7 +159,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("10000.0000 SYS") );
}
produce_blocks(1);
produce_block();

// create currency 2
act = mutable_variant_object()
Expand All @@ -170,7 +170,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("9999.0000 AAA") );
}
produce_blocks(1);
produce_block();

// create currency 3
act = mutable_variant_object()
Expand All @@ -181,7 +181,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("7777.0000 CCC") );
}
produce_blocks(1);
produce_block();

// create currency 3
act = mutable_variant_object()
Expand All @@ -192,7 +192,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("8888.0000 BBB") );
}
produce_blocks(1);
produce_block();

// get table: normal case
eosio::chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum(), fc::microseconds::maximum(), {});
Expand Down Expand Up @@ -316,7 +316,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_test, validating_tester ) try {
} FC_LOG_AND_RETHROW()

BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, validating_tester ) try {
produce_blocks(2);
produce_block();

create_accounts({ "eosio.token"_n, "eosio.ram"_n, "eosio.ramfee"_n, "eosio.stake"_n,
"eosio.bpay"_n, "eosio.vpay"_n, "eosio.saving"_n, "eosio.names"_n, "eosio.rex"_n });
Expand All @@ -327,7 +327,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, validating_tester ) try {

set_code( "eosio.token"_n, test_contracts::eosio_token_wasm() );
set_abi( "eosio.token"_n, test_contracts::eosio_token_abi() );
produce_blocks(1);
produce_block();

// create currency
auto act = mutable_variant_object()
Expand All @@ -339,7 +339,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, validating_tester ) try {
for (account_name a: accs) {
issue_tokens( *this, config::system_account_name, a, eosio::chain::asset::from_string("10000.0000 SYS") );
}
produce_blocks(1);
produce_block();

set_code( config::system_account_name, test_contracts::eosio_system_wasm() );
set_abi( config::system_account_name, test_contracts::eosio_system_abi() );
Expand All @@ -362,7 +362,7 @@ BOOST_FIXTURE_TEST_CASE( get_table_by_seckey_test, validating_tester ) try {
bidname("initb"_n, "org"_n, eosio::chain::asset::from_string("11.0000 SYS"));
bidname("initc"_n, "io"_n, eosio::chain::asset::from_string("12.0000 SYS"));
bidname("initd"_n, "html"_n, eosio::chain::asset::from_string("14.0000 SYS"));
produce_blocks(1);
produce_block();

// get table: normal case
eosio::chain_apis::read_only plugin(*(this->control), {}, fc::microseconds::maximum(), fc::microseconds::maximum(), {});
Expand Down
24 changes: 14 additions & 10 deletions tests/test_chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ class chain_plugin_tester : public validating_tester {
BOOST_CHECK_EQUAL( success(), regproducer(p) );
}
}
produce_blocks( 250);
produce_block();
produce_block(fc::seconds(1000));
produce_block();

auto trace_auth = validating_tester::push_action(config::system_account_name, updateauth::get_name(), config::system_account_name, mvo()
("account", name(config::system_account_name).to_string())
Expand All @@ -342,7 +344,9 @@ class chain_plugin_tester : public validating_tester {
)
);
}
produce_blocks( 250 );
produce_block();
produce_block(fc::seconds(1000));
produce_block();

auto producer_keys = control->active_producers().producers;
BOOST_CHECK_EQUAL( 21u, producer_keys.size() );
Expand All @@ -366,9 +370,9 @@ BOOST_AUTO_TEST_SUITE(test_chain_plugin_tests)

BOOST_FIXTURE_TEST_CASE(account_results_total_resources_test, chain_plugin_tester) { try {

produce_blocks(10);
produce_block();
setup_system_accounts();
produce_blocks();
produce_block();
create_account_with_resources("alice1111111"_n, config::system_account_name);
//stake more than 15% of total EOS supply to activate chain
transfer( name("eosio"), name("alice1111111"), core_from_string("650000000.0000"), name("eosio") );
Expand All @@ -383,9 +387,9 @@ BOOST_FIXTURE_TEST_CASE(account_results_total_resources_test, chain_plugin_teste

BOOST_FIXTURE_TEST_CASE(account_results_self_delegated_bandwidth_test, chain_plugin_tester) { try {

produce_blocks(10);
produce_block();
setup_system_accounts();
produce_blocks();
produce_block();
const asset nstake = core_from_string("1.0000");
const asset cstake = core_from_string("2.0000");
create_account_with_resources("alice1111111"_n, config::system_account_name, core_from_string("1.0000"), false);
Expand Down Expand Up @@ -413,9 +417,9 @@ BOOST_FIXTURE_TEST_CASE(account_results_self_delegated_bandwidth_test, chain_plu

BOOST_FIXTURE_TEST_CASE(account_results_refund_request_test, chain_plugin_tester) { try {

produce_blocks(10);
produce_block();
setup_system_accounts();
produce_blocks();
produce_block();

setup_producer_accounts({"producer1111"_n});
regproducer("producer1111"_n);
Expand Down Expand Up @@ -469,7 +473,7 @@ BOOST_FIXTURE_TEST_CASE(account_results_refund_request_test, chain_plugin_tester

BOOST_FIXTURE_TEST_CASE(account_results_voter_info_test, chain_plugin_tester) { try {

produce_blocks(10);
produce_block();
setup_system_accounts();

create_account_with_resources("alice1111111"_n, config::system_account_name, core_from_string("1.0000"), false);
Expand All @@ -484,7 +488,7 @@ BOOST_FIXTURE_TEST_CASE(account_results_voter_info_test, chain_plugin_tester) {

BOOST_FIXTURE_TEST_CASE(account_results_rex_info_test, chain_plugin_tester) { try {

produce_blocks(10);
produce_block();
setup_system_accounts();

create_account_with_resources("alice1111111"_n, config::system_account_name, core_from_string("1.0000"), false);
Expand Down
4 changes: 2 additions & 2 deletions tests/test_snapshot_information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ void test_snapshot_information() {
const std::filesystem::path parent_path = chain.get_config().blocks_dir.parent_path();

chain.create_account("snapshot"_n);
chain.produce_blocks(1);
chain.produce_block();
chain.set_code("snapshot"_n, test_contracts::snapshot_test_wasm());
chain.set_abi("snapshot"_n, test_contracts::snapshot_test_abi());
chain.produce_blocks(1);
chain.produce_block();

auto block = chain.produce_block();
const uint32_t base_block_num = block->block_num();
Expand Down
Loading

0 comments on commit 99e4f89

Please sign in to comment.