From 92d3426ec2839d6172aa99959c693ecbe1881578 Mon Sep 17 00:00:00 2001 From: lupin012 <58134934+lupin012@users.noreply.github.com> Date: Mon, 26 Jun 2023 09:41:10 +0200 Subject: [PATCH] rpcdaemon: EVMExecutor tests using generic state (#1289) --- silkworm/silkrpc/core/evm_executor_test.cpp | 40 ++++++++++++++------- silkworm/silkrpc/core/evm_trace.cpp | 2 +- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/silkworm/silkrpc/core/evm_executor_test.cpp b/silkworm/silkrpc/core/evm_executor_test.cpp index ecb35bde8f..9758e78269 100644 --- a/silkworm/silkrpc/core/evm_executor_test.cpp +++ b/silkworm/silkrpc/core/evm_executor_test.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include namespace silkworm::rpc { @@ -39,7 +41,7 @@ using evmc::literals::operator""_address, evmc::literals::operator""_bytes32; #ifndef SILKWORM_SANITIZE TEST_CASE("EVMExecutor") { - test::SetLogVerbosityGuard log_guard{log::Level::kNone}; + silkworm::test::SetLogVerbosityGuard log_guard{log::Level::kNone}; class StubDatabase : public core::rawdb::DatabaseReader { [[nodiscard]] awaitable get(const std::string& /*table*/, silkworm::ByteView /*key*/) const override { @@ -75,8 +77,10 @@ TEST_CASE("EVMExecutor") { block.header.number = block_number; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}), boost::asio::use_future); auto result = execution_result.get(); my_pool.stop(); @@ -103,8 +107,10 @@ TEST_CASE("EVMExecutor") { txn.from = 0xa872626373628737383927236382161739290870_address; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}), boost::asio::use_future); auto result = execution_result.get(); my_pool.stop(); @@ -132,8 +138,10 @@ TEST_CASE("EVMExecutor") { txn.max_priority_fee_per_gas = 0x18; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}), boost::asio::use_future); auto result = execution_result.get(); my_pool.stop(); @@ -161,8 +169,10 @@ TEST_CASE("EVMExecutor") { txn.from = 0xa872626373628737383927236382161739290870_address; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}), boost::asio::use_future); auto result = execution_result.get(); my_pool.stop(); @@ -190,8 +200,10 @@ TEST_CASE("EVMExecutor") { txn.from = 0xa872626373628737383927236382161739290870_address; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}, false, /* gasBailout */ true), boost::asio::use_future); auto result = execution_result.get(); executor.reset(); @@ -227,8 +239,10 @@ TEST_CASE("EVMExecutor") { txn.access_list = access_list; boost::asio::any_io_executor current_executor = my_pool.next_io_context().get_executor(); - state::RemoteState remote_state{current_executor, tx_database, block_number}; - EVMExecutor executor{*chain_config_ptr, workers, remote_state}; + std::shared_ptr mock_cursor = std::make_shared(); + test::DummyTransaction tx{0, mock_cursor}; + auto state = tx.create_state(current_executor, tx_database, block_number); + EVMExecutor executor{*chain_config_ptr, workers, state}; auto execution_result = boost::asio::co_spawn(my_pool.next_io_context().get_executor(), executor.call(block, txn, {}, true, true), boost::asio::use_future); auto result = execution_result.get(); my_pool.stop(); diff --git a/silkworm/silkrpc/core/evm_trace.cpp b/silkworm/silkrpc/core/evm_trace.cpp index 73f83ce21f..8aeb9912b9 100644 --- a/silkworm/silkrpc/core/evm_trace.cpp +++ b/silkworm/silkrpc/core/evm_trace.cpp @@ -1446,7 +1446,7 @@ boost::asio::awaitable TraceCallExecutor::trace_transaction_ silkworm::IntraBlockState initial_ibs{*state}; auto curr_state = tx_.create_state(current_executor, database_reader_, block_number - 1); - EVMExecutor executor{*chain_config_ptr, workers_, *curr_state}; + EVMExecutor executor{*chain_config_ptr, workers_, curr_state}; auto entry_tracer = std::make_shared(initial_ibs);