Skip to content

Commit

Permalink
Move to_rev() to testutils
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Maiboroda <andrei@ethereum.org>
  • Loading branch information
gzanitti and gumb0 committed Aug 28, 2023
1 parent ab6ed91 commit c96e855
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 42 deletions.
2 changes: 1 addition & 1 deletion test/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ find_package(nlohmann_json CONFIG REQUIRED)
add_library(evmone-statetestutils STATIC)
add_library(evmone::statetestutils ALIAS evmone-statetestutils)
target_compile_features(evmone-statetestutils PUBLIC cxx_std_20)
target_link_libraries(evmone-statetestutils PRIVATE evmone::state nlohmann_json::nlohmann_json)
target_link_libraries(evmone-statetestutils PRIVATE evmone::state evmone::testutils nlohmann_json::nlohmann_json)
target_include_directories(evmone-statetestutils PRIVATE ${evmone_private_include_dir})
target_sources(
evmone-statetestutils PRIVATE
Expand Down
3 changes: 0 additions & 3 deletions test/statetest/statetest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace json = nlohmann;
namespace evmone::test
{

/// Translates tests fork name to EVM revision
evmc_revision to_rev(std::string_view s);

struct TestMultiTransaction : state::Transaction
{
struct Indexes
Expand Down
36 changes: 1 addition & 35 deletions test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "../utils/stdx/utility.hpp"
#include "../utils/utils.hpp"
#include "statetest.hpp"
#include <evmone/eof.hpp>
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -222,41 +223,6 @@ state::State from_json<state::State>(const json::json& j)
return o;
}

evmc_revision to_rev(std::string_view s)
{
if (s == "Frontier")
return EVMC_FRONTIER;
if (s == "Homestead")
return EVMC_HOMESTEAD;
if (s == "EIP150")
return EVMC_TANGERINE_WHISTLE;
if (s == "EIP158")
return EVMC_SPURIOUS_DRAGON;
if (s == "Byzantium")
return EVMC_BYZANTIUM;
if (s == "Constantinople")
return EVMC_CONSTANTINOPLE;
if (s == "ConstantinopleFix")
return EVMC_PETERSBURG;
if (s == "Istanbul")
return EVMC_ISTANBUL;
if (s == "Berlin")
return EVMC_BERLIN;
if (s == "London" || s == "ArrowGlacier")
return EVMC_LONDON;
if (s == "Merge")
return EVMC_PARIS;
if (s == "Merge+3855") // PUSH0
return EVMC_SHANGHAI;
if (s == "Shanghai")
return EVMC_SHANGHAI;
if (s == "Cancun")
return EVMC_CANCUN;
if (s == "Prague")
return EVMC_PRAGUE;
throw std::invalid_argument{"unknown revision: " + std::string{s}};
}

/// Load common parts of Transaction or TestMultiTransaction.
static void from_json_tx_common(const json::json& j, state::Transaction& o)
{
Expand Down
3 changes: 2 additions & 1 deletion test/t8n/t8n.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "../state/mpt_hash.hpp"
#include "../state/rlp.hpp"
#include "../statetest/statetest.hpp"
#include "../utils/utils.hpp"
#include <evmone/evmone.h>
#include <evmone/version.h>
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -46,7 +47,7 @@ int main(int argc, const char* argv[])
return 0;
}
if (arg == "--state.fork" && ++i < argc)
rev = evmone::test::to_rev(argv[i]);
rev = to_rev(argv[i]);
else if (arg == "--input.alloc" && ++i < argc)
alloc_file = argv[i];
else if (arg == "--input.env" && ++i < argc)
Expand Down
5 changes: 3 additions & 2 deletions test/utils/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

find_package(intx CONFIG REQUIRED)

add_library(testutils INTERFACE)
add_library(testutils STATIC)
add_library(evmone::testutils ALIAS testutils)
target_link_libraries(testutils INTERFACE evmc::evmc_cpp)
target_link_libraries(testutils PUBLIC evmc::evmc_cpp)
target_include_directories(testutils INTERFACE ${PROJECT_SOURCE_DIR} ${evmone_private_include_dir})

if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
Expand All @@ -17,3 +17,4 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.19)
utils.hpp
)
endif()
target_sources(testutils PRIVATE utils.cpp)
45 changes: 45 additions & 0 deletions test/utils/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "utils.hpp"

namespace evmone::test
{

evmc_revision to_rev(std::string_view s)
{
if (s == "Frontier")
return EVMC_FRONTIER;
if (s == "Homestead")
return EVMC_HOMESTEAD;
if (s == "EIP150")
return EVMC_TANGERINE_WHISTLE;
if (s == "EIP158")
return EVMC_SPURIOUS_DRAGON;
if (s == "Byzantium")
return EVMC_BYZANTIUM;
if (s == "Constantinople")
return EVMC_CONSTANTINOPLE;
if (s == "ConstantinopleFix")
return EVMC_PETERSBURG;
if (s == "Istanbul")
return EVMC_ISTANBUL;
if (s == "Berlin")
return EVMC_BERLIN;
if (s == "London" || s == "ArrowGlacier")
return EVMC_LONDON;
if (s == "Merge")
return EVMC_PARIS;
if (s == "Merge+3855") // PUSH0
return EVMC_SHANGHAI;
if (s == "Shanghai")
return EVMC_SHANGHAI;
if (s == "Cancun")
return EVMC_CANCUN;
if (s == "Prague")
return EVMC_PRAGUE;
throw std::invalid_argument{"unknown revision: " + std::string{s}};
}

} // namespace evmone::test
9 changes: 9 additions & 0 deletions test/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <evmc/evmc.hpp>
#include <evmc/hex.hpp>

using evmc::bytes;
Expand All @@ -11,6 +12,14 @@ using evmc::from_hex;
using evmc::from_spaced_hex;
using evmc::hex;

namespace evmone::test
{

/// Translates tests fork name to EVM revision
evmc_revision to_rev(std::string_view s);

} // namespace evmone::test

/// Converts a string to bytes by casting individual characters.
inline bytes to_bytes(std::string_view s)
{
Expand Down

0 comments on commit c96e855

Please sign in to comment.