Skip to content

Commit

Permalink
Don't change produce_block(). Add produce_block_ex().
Browse files Browse the repository at this point in the history
  • Loading branch information
greg7mdp committed May 6, 2024
1 parent bae482f commit 4bc5eaa
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 108 deletions.
31 changes: 21 additions & 10 deletions libraries/testing/include/eosio/testing/tester.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ namespace eosio::testing {

static const uint32_t DEFAULT_BILLED_CPU_TIME_US = 2000;
static const fc::microseconds abi_serializer_max_time;
static constexpr fc::microseconds default_skip_time = fc::milliseconds(config::block_interval_ms);

virtual ~base_tester() {
lib_connection.disconnect();
Expand All @@ -186,9 +187,11 @@ namespace eosio::testing {
void open( std::optional<chain_id_type> expected_chain_id = {} );
bool is_same_chain( base_tester& other );

virtual produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false) = 0;
virtual signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) = 0;
virtual signed_block_ptr finish_block() = 0;
virtual produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false) = 0;
virtual signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false) = 0;
virtual signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time ) = 0;
virtual signed_block_ptr finish_block() = 0;

// produce one block and return traces for all applied transactions, both failed and executed
signed_block_ptr produce_blocks( uint32_t n = 1, bool empty = false );
void produce_blocks_until_end_of_round();
Expand Down Expand Up @@ -576,11 +579,15 @@ namespace eosio::testing {

using base_tester::produce_block;

produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override {
produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override {
return _produce_block(skip_time, false, no_throw);
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override {
return _produce_block(skip_time, false, no_throw).block;
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time ) override {
unapplied_transactions.add_aborted( control->abort_block() );
return _produce_block(skip_time, true);
}
Expand Down Expand Up @@ -671,14 +678,18 @@ namespace eosio::testing {
}
}

produce_block_result_t produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms), bool no_throw = false )override {
produce_block_result_t produce_block_ex( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override {
auto produce_block_result = _produce_block(skip_time, false, no_throw);
validate_push_block(produce_block_result.block);
return produce_block_result;
}

produce_block_result_t produce_block_no_validation( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) {
return _produce_block(skip_time, false, false);
signed_block_ptr produce_block( fc::microseconds skip_time = default_skip_time, bool no_throw = false ) override {
return produce_block_ex(skip_time, no_throw).block;
}

signed_block_ptr produce_block_no_validation( fc::microseconds skip_time = default_skip_time ) {
return _produce_block(skip_time, false, false).block;
}

void validate_push_block(const signed_block_ptr& sb) {
Expand All @@ -688,7 +699,7 @@ namespace eosio::testing {
_wait_for_vote_if_needed(*validating_node);
}

signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override {
signed_block_ptr produce_empty_block( fc::microseconds skip_time = default_skip_time )override {
unapplied_transactions.add_aborted( control->abort_block() );
auto sb = _produce_block(skip_time, true);
validate_push_block(sb);
Expand Down Expand Up @@ -785,7 +796,7 @@ namespace eosio::testing {
// -----------------------------------------------------------
finalizer_policy transition_to_Savanna(const std::function<void(const signed_block_ptr&)>& block_callback = {}) {
auto produce_block = [&]() {
auto b = t.produce_block().block;
auto b = t.produce_block();
if (block_callback)
block_callback(b);
return b;
Expand Down
2 changes: 1 addition & 1 deletion libraries/testing/tester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ namespace eosio::testing {
res = produce_empty_block();
} else {
for( uint32_t i = 0; i < n; ++i )
res = produce_block().block;
res = produce_block();
}
return res;
}
Expand Down
12 changes: 6 additions & 6 deletions plugins/chain_plugin/test/test_account_query_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ BOOST_AUTO_TEST_CASE(future_fork_test) { try {

// create 10 blocks synced
for (int i = 0; i < 10; i++) {
node_b.push_block(node_a.produce_block().block);
node_b.push_block(node_a.produce_block());
}

// produce a block on node A with a new account and permission
Expand All @@ -182,8 +182,8 @@ BOOST_AUTO_TEST_CASE(future_fork_test) { try {
BOOST_TEST_REQUIRE(find_account_auth(pre_results, tester_account, "role"_n) == true);

// have node B take over from head-1 and produce "future" blocks to overtake
node_a.push_block(node_b.produce_block(fc::milliseconds(config::block_interval_ms * 100)).block);
node_a.push_block(node_b.produce_block().block);
node_a.push_block(node_b.produce_block(fc::milliseconds(config::block_interval_ms * 100)));
node_a.push_block(node_b.produce_block());

// ensure the account was forked away
const auto post_results = aq_db.get_accounts_by_authorizers(pars);
Expand All @@ -206,7 +206,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try {

// create 10 blocks synced
for (int i = 0; i < 10; i++) {
node_b.push_block(node_a.produce_block().block);
node_b.push_block(node_a.produce_block());
}

// produce a block on node A with a new account and permission
Expand Down Expand Up @@ -258,7 +258,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try {
aq_db.cache_transaction_trace(trace_ptr4);

// push b's onto a
node_a.push_block(node_b.produce_block().block);
node_a.push_block(node_b.produce_block());

const auto trace_ptr5 = node_b.push_action(config::system_account_name, updateauth::get_name(), tester_account, fc::mutable_variant_object()
("account", tester_account)
Expand All @@ -275,7 +275,7 @@ BOOST_AUTO_TEST_CASE(fork_test) { try {
);
aq_db.cache_transaction_trace(trace_ptr6);

node_a.push_block(node_b.produce_block().block);
node_a.push_block(node_b.produce_block());

// ensure the account was forked away
const auto post_results = aq_db.get_accounts_by_authorizers(pars);
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 @@ -30,12 +30,12 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_snapshot_information, SNAPSHOT_SUITE, snapsho
chain.set_abi("snapshot"_n, test_contracts::snapshot_test_abi());
chain.produce_blocks(1);

auto block = chain.produce_block().block;
auto block = chain.produce_block();
BOOST_REQUIRE_EQUAL(block->block_num(), 6u); // ensure that test setup stays consistent with original snapshot setup
// undo the auto-pending from tester
chain.control->abort_block();

auto block2 = chain.produce_block().block;
auto block2 = chain.produce_block();
BOOST_REQUIRE_EQUAL(block2->block_num(), 7u); // ensure that test setup stays consistent with original snapshot setup
// undo the auto-pending from tester
chain.control->abort_block();
Expand Down
36 changes: 18 additions & 18 deletions unittests/api_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ std::pair<transaction_trace_ptr, signed_block_ptr> _CallFunction(Tester& test, T
if (!no_throw) {
BOOST_CHECK_EQUAL(res->receipt->status, transaction_receipt::executed);
}
auto block = test.produce_block().block;
auto block = test.produce_block();
return { res, block };
}
}
Expand Down Expand Up @@ -844,13 +844,13 @@ BOOST_AUTO_TEST_CASE(light_validation_skip_cfa) try {
tester chain(setup_policy::full);

std::vector<signed_block_ptr> blocks;
blocks.push_back(chain.produce_block().block);
blocks.push_back(chain.produce_block());

chain.create_account( "testapi"_n );
chain.create_account( "dummy"_n );
blocks.push_back(chain.produce_block().block);
blocks.push_back(chain.produce_block());
chain.set_code( "testapi"_n, test_contracts::test_api_wasm() );
blocks.push_back(chain.produce_block().block);
blocks.push_back(chain.produce_block());

cf_action cfa;
signed_transaction trx;
Expand All @@ -866,7 +866,7 @@ BOOST_AUTO_TEST_CASE(light_validation_skip_cfa) try {
// run normal passing case
auto sigs = trx.sign(chain.get_private_key("testapi"_n, "active"), chain.control->get_chain_id());
auto trace = chain.push_transaction(trx);
blocks.push_back(chain.produce_block().block);
blocks.push_back(chain.produce_block());

BOOST_REQUIRE(trace->receipt);
BOOST_CHECK_EQUAL(trace->receipt->status, transaction_receipt::executed);
Expand Down Expand Up @@ -1593,21 +1593,21 @@ BOOST_AUTO_TEST_CASE(inline_action_with_over_4k_limit) { try {
tester chain2(setup_policy::full, db_read_mode::HEAD, {_4k + 100});
signed_block_ptr block;
for (int n=0; n < 2; ++n) {
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);
}
chain.create_account( "testapi"_n );
for (int n=0; n < 2; ++n) {
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);
}
chain.set_code( "testapi"_n, test_contracts::test_api_wasm() );
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);

block = CALL_TEST_FUNCTION_WITH_BLOCK(chain, "test_transaction", "send_action_4k", {}).second;
chain2.push_block(block);
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);

} FC_LOG_AND_RETHROW() }
Expand Down Expand Up @@ -1643,13 +1643,13 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
tester chain2(setup_policy::full_except_do_not_disable_deferred_trx, db_read_mode::HEAD, {_4k + 100});
signed_block_ptr block;
for (int n=0; n < 2; ++n) {
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);
}
chain.create_accounts( {"testapi"_n, "testapi2"_n, "alice"_n} );
chain.set_code( "testapi"_n, test_contracts::test_api_wasm() );
chain.set_code( "testapi2"_n, test_contracts::test_api_wasm() );
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);

transaction_trace_ptr trace;
Expand All @@ -1660,7 +1660,7 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
block = CALL_TEST_FUNCTION_WITH_BLOCK(chain, "test_transaction", "send_deferred_transaction_4k_action", {} ).second;
chain2.push_block(block);
BOOST_CHECK(!trace);
block = chain.produce_block( fc::seconds(2) ).block;
block = chain.produce_block( fc::seconds(2) );
chain2.push_block(block);

//check that it gets executed afterwards
Expand All @@ -1672,7 +1672,7 @@ BOOST_AUTO_TEST_CASE(deferred_inline_action_limit) { try {
c.disconnect();

for (int n=0; n < 10; ++n) {
block = chain.produce_block().block;
block = chain.produce_block();
chain2.push_block(block);
}

Expand Down Expand Up @@ -3872,7 +3872,7 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try {
fin_keys.set_finalizer_policy(0);

// this block contains the header extension for the instant finality, savanna activated when it is LIB
auto block = t.produce_block().block;
auto block = t.produce_block();

std::optional<block_header_extension> ext = block->extract_header_extension(instant_finality_extension::extension_id());
BOOST_TEST(!!ext);
Expand All @@ -3899,7 +3899,7 @@ BOOST_AUTO_TEST_CASE(initial_set_finalizer_test) { try {

auto lib_after_transition = t.lib_block->block_num();
// block after IF Critical Block is IF Proper Block
block = t.produce_block().block;
block = t.produce_block();

// lib must advance after 3 blocks
t.produce_blocks(3);
Expand All @@ -3920,7 +3920,7 @@ void test_finality_transition(const vector<account_name>& accounts,
// activate savanna
t.set_finalizers(input);
// this block contains the header extension for the instant finality, savanna activated when it is LIB
auto block = t.produce_block().block;
auto block = t.produce_block();

std::optional<block_header_extension> ext = block->extract_header_extension(instant_finality_extension::extension_id());
BOOST_TEST(!!ext);
Expand All @@ -3932,7 +3932,7 @@ void test_finality_transition(const vector<account_name>& accounts,

block_num_type active_block_num = block->block_num();
while (active_block_num > t.lib_block->block_num()) {
block = t.produce_block().block;
block = t.produce_block();
}
// lib_block is IF Genesis Block
// block is IF Critical Block
Expand All @@ -3945,7 +3945,7 @@ void test_finality_transition(const vector<account_name>& accounts,

auto lib_after_transition = t.lib_block->block_num();
// block after IF Critical Block is IF Proper Block
block = t.produce_block().block;
block = t.produce_block();

t.produce_blocks(4);
if( lib_advancing_expected ) {
Expand Down
20 changes: 10 additions & 10 deletions unittests/block_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_test)

// First we create a valid block with valid transaction
main.create_account("newacc"_n);
auto b = main.produce_block().block;
auto b = main.produce_block();

// Make a copy of the valid block and corrupt the transaction
auto copy_b = std::make_shared<signed_block>(std::move(*b));
Expand Down Expand Up @@ -60,7 +60,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test)

// First we create a valid block with valid transaction
main.create_account("newacc"_n);
auto b = main.produce_block().block;
auto b = main.produce_block();

// Make a copy of the valid block and corrupt the transaction
auto copy_b = std::make_shared<signed_block>(std::move(*b));
Expand Down Expand Up @@ -96,7 +96,7 @@ BOOST_AUTO_TEST_CASE(block_with_invalid_tx_mroot_test)
std::pair<signed_block_ptr, signed_block_ptr> corrupt_trx_in_block(validating_tester& main, account_name act_name) {
// First we create a valid block with valid transaction
main.create_account(act_name);
signed_block_ptr b = main.produce_block_no_validation().block;
signed_block_ptr b = main.produce_block_no_validation();

// Make a copy of the valid block and corrupt the transaction
auto copy_b = std::make_shared<signed_block>(b->clone());
Expand Down Expand Up @@ -137,13 +137,13 @@ BOOST_AUTO_TEST_CASE(trusted_producer_test)
std::set<account_name> producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n };
for (auto prod : producers)
main.create_account(prod);
auto b = main.produce_block().block;
auto b = main.produce_block();

std::vector<account_name> schedule(producers.cbegin(), producers.cend());
auto trace = main.set_producers(schedule);

while (b->producer != "defproducera"_n) {
b = main.produce_block().block;
b = main.produce_block();
}

auto blocks = corrupt_trx_in_block(main, "tstproducera"_n);
Expand All @@ -163,13 +163,13 @@ BOOST_AUTO_TEST_CASE(trusted_producer_verify_2nd_test)
std::set<account_name> producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n };
for (auto prod : producers)
main.create_account(prod);
auto b = main.produce_block().block;
auto b = main.produce_block();

std::vector<account_name> schedule(producers.cbegin(), producers.cend());
auto trace = main.set_producers(schedule);

while (b->producer != "defproducerc"_n) {
b = main.produce_block().block;
b = main.produce_block();
}

auto blocks = corrupt_trx_in_block(main, "tstproducera"_n);
Expand All @@ -189,13 +189,13 @@ BOOST_AUTO_TEST_CASE(untrusted_producer_test)
std::set<account_name> producers = { "defproducera"_n, "defproducerb"_n, "defproducerc"_n, "defproducerd"_n };
for (auto prod : producers)
main.create_account(prod);
auto b = main.produce_block().block;
auto b = main.produce_block();

std::vector<account_name> schedule(producers.cbegin(), producers.cend());
auto trace = main.set_producers(schedule);

while (b->producer != "defproducerb"_n) {
b = main.produce_block().block;
b = main.produce_block();
}

auto blocks = corrupt_trx_in_block(main, "tstproducera"_n);
Expand Down Expand Up @@ -226,7 +226,7 @@ BOOST_AUTO_TEST_CASE(broadcasted_block_test)
bcasted_blk_by_recv_node = block;
});

auto b = producer_node.produce_block().block;
auto b = producer_node.produce_block();
receiving_node.push_block(b);

bytes bcasted_blk_by_prod_node_packed = fc::raw::pack(*bcasted_blk_by_prod_node);
Expand Down
2 changes: 1 addition & 1 deletion unittests/chain_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ BOOST_AUTO_TEST_CASE( signal_validated_blocks ) try {
validator.push_block(accepted_block);

chain.create_account("hello"_n);
auto produced_block = chain.produce_block().block;
auto produced_block = chain.produce_block();
validator.push_block(accepted_block);
BOOST_CHECK(produced_block->calculate_id() == accepted_id);
BOOST_CHECK(accepted_id == validated_id);
Expand Down
2 changes: 1 addition & 1 deletion unittests/finality_test_cluster.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class finality_test_cluster {

// node0 produces a block and pushes it to node1 and node2
signed_block_ptr produce_and_push_block() {
auto b = node0.produce_block().block;
auto b = node0.produce_block();
for (size_t i=1; i<nodes.size(); ++i)
nodes[i].push_block(b);
return b;
Expand Down
Loading

0 comments on commit 4bc5eaa

Please sign in to comment.