From 950c5c0998c98e3b27736c521d790ea99e89a193 Mon Sep 17 00:00:00 2001 From: Kevin Heifner Date: Tue, 21 May 2024 09:27:45 -0500 Subject: [PATCH] GH-168 Remove invalid assertion for action_mroot. Add test for empty action_mroot. --- libraries/chain/block_state.cpp | 1 - unittests/block_tests.cpp | 39 +++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/libraries/chain/block_state.cpp b/libraries/chain/block_state.cpp index 868b2feffa..d76b1b9e8f 100644 --- a/libraries/chain/block_state.cpp +++ b/libraries/chain/block_state.cpp @@ -280,7 +280,6 @@ void block_state::verify_qc(const valid_quorum_certificate& qc) const { valid_t block_state::new_valid(const block_header_state& next_bhs, const digest_type& action_mroot, const digest_type& strong_digest) const { assert(valid); assert(next_bhs.core.last_final_block_num() >= core.last_final_block_num()); - assert(!action_mroot.empty()); assert(!strong_digest.empty()); // Copy parent's validation_tree and validation_mroots. diff --git a/unittests/block_tests.cpp b/unittests/block_tests.cpp index 48e962e763..de3560e4f7 100644 --- a/unittests/block_tests.cpp +++ b/unittests/block_tests.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace eosio; using namespace testing; @@ -344,4 +345,42 @@ BOOST_FIXTURE_TEST_CASE( abort_block_transactions_tester, validating_tester) { t } FC_LOG_AND_RETHROW() } +BOOST_AUTO_TEST_CASE_TEMPLATE(no_onblock_test, T, testers) { try { + T c; + + c.produce_block_ex(); + auto r = c.produce_block_ex(); + BOOST_TEST_REQUIRE(!!r.onblock_trace); + BOOST_TEST(!!r.onblock_trace->receipt); + BOOST_TEST(!r.onblock_trace->except); + BOOST_TEST(!r.onblock_trace->except_ptr); + BOOST_TEST(!r.block->action_mroot.empty()); + + // Deploy contract that rejects all actions dispatched to it with the following exceptions: + // * eosio::setcode to set code on the eosio is allowed (unless the rejectall account exists) + // * eosio::newaccount is allowed only if it creates the rejectall account. + c.set_code( config::system_account_name, test_contracts::reject_all_wasm() ); + c.produce_block(); + r = c.produce_block_ex(); // empty block, no valid onblock since it is rejected + BOOST_TEST_REQUIRE(!!r.onblock_trace); + BOOST_TEST(!r.onblock_trace->receipt); + BOOST_TEST(!!r.onblock_trace->except); + BOOST_TEST(!!r.onblock_trace->except_ptr); + + // In Legacy, action_mroot is the mroot of all delivered action receipts. + // In Savanna, action_mroot is the root of the Finality Tree + // associated with the block, i.e. the root of + // validation_tree(core.final_on_strong_qc_block_num). + if constexpr (std::is_same_v) { + BOOST_TEST(r.block->is_proper_svnn_block()); + BOOST_TEST(!r.block->action_mroot.empty()); + } else { + BOOST_TEST(!r.block->is_proper_svnn_block()); + BOOST_TEST(r.block->action_mroot.empty()); + } + c.produce_empty_block(); + +} FC_LOG_AND_RETHROW() } + + BOOST_AUTO_TEST_SUITE_END()