Skip to content

Commit

Permalink
Merge branch 'main' into unittests_part7
Browse files Browse the repository at this point in the history
  • Loading branch information
linh2931 authored May 21, 2024
2 parents f88fecc + f986a07 commit f27499e
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 100 deletions.
1 change: 0 additions & 1 deletion libraries/chain/block_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
40 changes: 40 additions & 0 deletions unittests/block_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <boost/test/unit_test.hpp>
#include <eosio/testing/tester.hpp>
#include <test_contracts.hpp>

using namespace eosio;
using namespace testing;
Expand Down Expand Up @@ -344,4 +345,43 @@ BOOST_FIXTURE_TEST_CASE( abort_block_transactions_tester, validating_tester) { t

} FC_LOG_AND_RETHROW() }

// Verify blocks are produced when onblock fails
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<T, savanna_tester>) {
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()
Loading

0 comments on commit f27499e

Please sign in to comment.