Skip to content

Commit

Permalink
Skip state tests with out of range values in json
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Dec 3, 2024
1 parent f6198c0 commit 96a40ec
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
1 change: 1 addition & 0 deletions test/blockchaintest/blockchaintest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// SPDX-License-Identifier: Apache-2.0

#include "blockchaintest.hpp"
#include "../statetest/statetest.hpp"
#include <CLI/CLI.hpp>
#include <evmone/evmone.h>
#include <evmone/version.h>
Expand Down
5 changes: 0 additions & 5 deletions test/blockchaintest/blockchaintest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

namespace evmone::test
{
struct UnsupportedTestFeature : std::runtime_error
{
using runtime_error::runtime_error;
};

// https://ethereum.org/en/developers/docs/blocks/
struct BlockHeader
{
Expand Down
13 changes: 10 additions & 3 deletions test/statetest/statetest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ class StateTest : public testing::Test
void TestBody() final
{
std::ifstream f{m_json_test_file};
const auto tests = evmone::test::load_state_tests(f);
for (const auto& test : tests)
evmone::test::run_state_test(test, m_vm, m_trace);
try
{
const auto tests = evmone::test::load_state_tests(f);
for (const auto& test : tests)
evmone::test::run_state_test(test, m_vm, m_trace);
}
catch (const evmone::test::UnsupportedTestFeature& ex)
{
GTEST_SKIP() << ex.what();
}
}
};

Expand Down
4 changes: 4 additions & 0 deletions test/statetest/statetest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace json = nlohmann;

namespace evmone::test
{
struct UnsupportedTestFeature : std::runtime_error
{
using runtime_error::runtime_error;

Check warning on line 18 in test/statetest/statetest.hpp

View check run for this annotation

Codecov / codecov/patch

test/statetest/statetest.hpp#L18

Added line #L18 was not covered by tests
};

struct TestMultiTransaction : state::Transaction
{
Expand Down
29 changes: 25 additions & 4 deletions test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,34 @@ state::AuthorizationList from_json<state::AuthorizationList>(const json::json& j
for (const auto& a : j)
{
state::Authorization authorization{};
authorization.chain_id = from_json<uint64_t>(a.at("chainId"));
try
{
authorization.chain_id = from_json<uint64_t>(a.at("chainId"));
}
catch (const std::out_of_range&)
{
throw UnsupportedTestFeature("tests with out of range chainId are not supported");
}
authorization.addr = from_json<address>(a.at("address"));
authorization.nonce = from_json<uint64_t>(a.at("nonce"));
try
{
authorization.nonce = from_json<uint64_t>(a.at("nonce"));
}
catch (const std::out_of_range&)
{
throw UnsupportedTestFeature("tests with out of range nonce are not supported");
}
if (a.contains("signer"))
authorization.signer = from_json<address>(a.at("signer"));
authorization.r = from_json<intx::uint256>(a.at("r"));
authorization.s = from_json<intx::uint256>(a.at("s"));
try
{
authorization.r = from_json<intx::uint256>(a.at("r"));
authorization.s = from_json<intx::uint256>(a.at("s"));
}
catch (const std::out_of_range&)
{
throw UnsupportedTestFeature("tests with out of range r and s are not supported");
}
authorization.v = from_json<intx::uint256>(a.at("v"));
o.emplace_back(authorization);
}
Expand Down

0 comments on commit 96a40ec

Please sign in to comment.