From 8a92bd9b5eaedb3580cd969034f81b4ef594d68a Mon Sep 17 00:00:00 2001 From: kayan Date: Thu, 12 Oct 2023 16:49:04 +0800 Subject: [PATCH] fix unittest compile error, explicit set inlina action size to 4kB --- src/CMakeLists.txt | 2 +- tests/admin_actions_tests.cpp | 4 +- tests/basic_evm_tester.cpp | 2 +- tests/basic_evm_tester.hpp | 130 ++++++++++++++++++++++++++++++++-- tests/mapping_tests.cpp | 2 +- 5 files changed, 131 insertions(+), 9 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e215c18a..bfee316e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -91,5 +91,5 @@ target_compile_options(evm_runtime PUBLIC --no-missing-ricardian-clause) if (WITH_LARGE_STACK) target_link_options(evm_runtime PUBLIC --stack-size=50000000) else() - target_link_options(evm_runtime PUBLIC --stack-size=37600) + target_link_options(evm_runtime PUBLIC --stack-size=36000) endif() diff --git a/tests/admin_actions_tests.cpp b/tests/admin_actions_tests.cpp index ed89c498..4448ab17 100644 --- a/tests/admin_actions_tests.cpp +++ b/tests/admin_actions_tests.cpp @@ -144,7 +144,9 @@ BOOST_FIXTURE_TEST_CASE(setkvstore_tests, admin_action_tester) try { const int64_t to_bridge = 1000000; transfer_token("alice"_n, evm_account_name, make_asset(to_bridge), evm1.address_0x()); - auto [contract_addr, contract_account_id] = deploy_simple_contract(evm1); + evmc::address contract_addr; + uint64_t contract_account_id; + std::tie(contract_addr, contract_account_id) = deploy_simple_contract(evm1); // Call method "setval" on simple contract (sha3('setval(uint256)') = 0x559c9c4a) auto txn = generate_tx(contract_addr, 0, 500'000); diff --git a/tests/basic_evm_tester.cpp b/tests/basic_evm_tester.cpp index f25dfe40..7b68a471 100644 --- a/tests/basic_evm_tester.cpp +++ b/tests/basic_evm_tester.cpp @@ -34,7 +34,7 @@ balance_and_dust::operator intx::uint256() const struct vault_balance_row { name owner; - asset balance; + asset balance{}; uint64_t dust = 0; }; diff --git a/tests/basic_evm_tester.hpp b/tests/basic_evm_tester.hpp index 7a6b4c62..2dcb3473 100644 --- a/tests/basic_evm_tester.hpp +++ b/tests/basic_evm_tester.hpp @@ -89,7 +89,7 @@ struct account_object std::optional flags; inline bool has_flag(flag f)const { - return (flags.has_value() && flags.value() & static_cast(f) != 0); + return (flags.has_value() && (flags.value() & static_cast(f)) != 0); } }; @@ -201,10 +201,125 @@ class evm_eoa }; struct vault_balance_row; -class basic_evm_tester : public testing::validating_tester +class evm_validating_tester : public testing::base_tester { +public: + virtual ~evm_validating_tester() { + if( !validating_node ) { + elog( "~evm_validating_tester() called with empty validating_node; likely in the middle of failure" ); + return; + } + try { + if( num_blocks_to_producer_before_shutdown > 0 ) + produce_blocks( num_blocks_to_producer_before_shutdown ); + if (!skip_validate && std::uncaught_exceptions() == 0) + BOOST_CHECK_EQUAL( validate(), true ); + } catch( const fc::exception& e ) { + wdump((e.to_detail_string())); + } + } + controller::config vcfg; + + evm_validating_tester(const flat_set& trusted_producers = flat_set(), deep_mind_handler* dmlog = nullptr, testing::setup_policy p = testing::setup_policy::full) { + auto def_conf = default_config(tempdir, 4096 /* genesis_max_inline_action_size max inline action size*/); + + vcfg = def_conf.first; + config_validator(vcfg); + vcfg.trusted_producers = trusted_producers; + + validating_node = create_validating_node(vcfg, def_conf.second, true, dmlog); + + init(def_conf.first, def_conf.second); + execute_setup_policy(p); + } + + static void config_validator(controller::config& vcfg) { + FC_ASSERT( vcfg.blocks_dir.filename().generic_string() != "." + && vcfg.state_dir.filename().generic_string() != ".", "invalid path names in controller::config" ); + + vcfg.blocks_dir = vcfg.blocks_dir.parent_path() / std::string("v_").append( vcfg.blocks_dir.filename().generic_string() ); + vcfg.state_dir = vcfg.state_dir.parent_path() / std::string("v_").append( vcfg.state_dir.filename().generic_string() ); + + vcfg.contracts_console = false; + } + + static unique_ptr create_validating_node(controller::config vcfg, const genesis_state& genesis, bool use_genesis, deep_mind_handler* dmlog = nullptr) { + unique_ptr validating_node = std::make_unique(vcfg, testing::make_protocol_feature_set(), genesis.compute_chain_id()); + validating_node->add_indices(); + if(dmlog) + { + validating_node->enable_deep_mind(dmlog); + } + if (use_genesis) { + validating_node->startup( [](){}, []() { return false; }, genesis ); + } + else { + validating_node->startup( [](){}, []() { return false; } ); + } + return validating_node; + } + + signed_block_ptr produce_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override { + auto sb = _produce_block(skip_time, false); + auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb ); + controller::block_report br; + validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} ); + + return sb; + } + + signed_block_ptr produce_block_no_validation( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) ) { + return _produce_block(skip_time, false); + } + + void validate_push_block(const signed_block_ptr& sb) { + auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb ); + controller::block_report br; + validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} ); + } + + signed_block_ptr produce_empty_block( fc::microseconds skip_time = fc::milliseconds(config::block_interval_ms) )override { + unapplied_transactions.add_aborted( control->abort_block() ); + auto sb = _produce_block(skip_time, true); + auto bsf = validating_node->create_block_state_future( sb->calculate_id(), sb ); + controller::block_report br; + validating_node->push_block( br, bsf.get(), forked_branch_callback{}, trx_meta_cache_lookup{} ); + + return sb; + } + + signed_block_ptr finish_block()override { + return _finish_block(); + } + + bool validate() { + + + auto hbh = control->head_block_state()->header; + auto vn_hbh = validating_node->head_block_state()->header; + bool ok = control->head_block_id() == validating_node->head_block_id() && + hbh.previous == vn_hbh.previous && + hbh.timestamp == vn_hbh.timestamp && + hbh.transaction_mroot == vn_hbh.transaction_mroot && + hbh.action_mroot == vn_hbh.action_mroot && + hbh.producer == vn_hbh.producer; + + validating_node.reset(); + validating_node = std::make_unique(vcfg, testing::make_protocol_feature_set(), control->get_chain_id()); + validating_node->add_indices(); + validating_node->startup( [](){}, []() { return false; } ); + + return ok; + } + + unique_ptr validating_node; + uint32_t num_blocks_to_producer_before_shutdown = 0; + bool skip_validate = false; +}; + +class basic_evm_tester : public evm_validating_tester { public: - using testing::validating_tester::push_action; + using evm_validating_tester::push_action; static constexpr name token_account_name = "eosio.token"_n; static constexpr name faucet_account_name = "faucet"_n; @@ -244,6 +359,11 @@ class basic_evm_tester : public testing::validating_tester const std::optional ingress_bridge_fee = std::nullopt, const bool also_prepare_self_balance = true); + template + void start_block(T... t) { + evm_validating_tester::_start_block(t...); + } + void prepare_self_balance(uint64_t fund_amount = 100'0000); config_table_row get_config() const; @@ -355,14 +475,14 @@ inline constexpr intx::uint256 operator"" _ether(const char* s) } template -class speculative_block_starter +class speculative_block_starter { public: // Assumes user will not abort or finish blocks using the tester passed into the constructor for the lifetime of this // object. explicit speculative_block_starter(Tester& tester, uint32_t time_gap_sec = 0) : t(tester) { - t.control->start_block(t.control->head_block_time() + fc::milliseconds(500 + 1000 * time_gap_sec), 0); + t.start_block(t.control->head_block_time() + fc::milliseconds(500 + 1000 * time_gap_sec)); } speculative_block_starter(speculative_block_starter&& other) : t(other.t) { other.canceled = true; } diff --git a/tests/mapping_tests.cpp b/tests/mapping_tests.cpp index 56d5b241..35fb64fb 100644 --- a/tests/mapping_tests.cpp +++ b/tests/mapping_tests.cpp @@ -242,7 +242,7 @@ try { // Now actually commit the init action into a block to do further testing on top of that state in later blocks. { - control->start_block(control->head_block_time() + fc::milliseconds(500), 0); + this->_start_block(control->head_block_time() + fc::milliseconds(500)); BOOST_REQUIRE_EQUAL(control->pending_block_time().sec_since_epoch(), bm.genesis_timestamp); init();