Skip to content

Commit

Permalink
rpcdaemon: EVMExecutor tests using generic state (#1289)
Browse files Browse the repository at this point in the history
  • Loading branch information
lupin012 authored Jun 26, 2023
1 parent 532ed43 commit 92d3426
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
40 changes: 27 additions & 13 deletions silkworm/silkrpc/core/evm_executor_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <silkworm/infra/grpc/client/client_context_pool.hpp>
#include <silkworm/infra/test/log.hpp>
#include <silkworm/silkrpc/common/util.hpp>
#include <silkworm/silkrpc/test/dummy_transaction.hpp>
#include <silkworm/silkrpc/test/mock_cursor.hpp>
#include <silkworm/silkrpc/types/transaction.hpp>

namespace silkworm::rpc {
Expand All @@ -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<KeyValue> get(const std::string& /*table*/, silkworm::ByteView /*key*/) const override {
Expand Down Expand Up @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand All @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand Down Expand Up @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand Down Expand Up @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand Down Expand Up @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand Down Expand Up @@ -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<test::MockCursorDupSort> mock_cursor = std::make_shared<test::MockCursorDupSort>();
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();
Expand Down
2 changes: 1 addition & 1 deletion silkworm/silkrpc/core/evm_trace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1446,7 +1446,7 @@ boost::asio::awaitable<TraceEntriesResult> 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<trace::EntryTracer>(initial_ibs);

Expand Down

0 comments on commit 92d3426

Please sign in to comment.