Skip to content

Commit

Permalink
Function that translates the name of the test fork to the EVM revisio…
Browse files Browse the repository at this point in the history
…n (to_rev) moved to utils.cpp
  • Loading branch information
gzanitti committed Aug 22, 2023
1 parent 7122c65 commit 8375a2b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 36 deletions.
1 change: 1 addition & 0 deletions test/eoftest/eoftest_runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace evmone::test

namespace
{

struct EOFValidationTest
{
struct Case
Expand Down
46 changes: 46 additions & 0 deletions test/utils/utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "utils.hpp"

namespace evmone::test
{

/// Translates tests fork name to EVM revision
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")
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}};
}

}
43 changes: 7 additions & 36 deletions test/utils/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ using evmc::from_hex;
using evmc::from_spaced_hex;
using evmc::hex;

namespace evmone::test
{

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 All @@ -28,39 +35,3 @@ inline bytes operator""_hex(const char* s, size_t size)
{
return from_spaced_hex({s, size}).value();
}

/// Translates tests fork name to EVM revision
inline 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")
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}};
}

0 comments on commit 8375a2b

Please sign in to comment.