Skip to content

Commit

Permalink
Handle decoding non padded values in storage
Browse files Browse the repository at this point in the history
  • Loading branch information
hugo-dc committed May 30, 2024
1 parent 291b3c3 commit 2710c0f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion test/integration/statetest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ set_tests_properties(
add_test(
NAME ${PREFIX}/execute_exported_tests
# TODO: Broken exported tests are filtered out.
COMMAND evmone-statetest ${EXPORT_DIR}/state_transition --gtest_filter=-*block.*
COMMAND evmone-statetest ${EXPORT_DIR}/state_transition --gtest_filter=-*call.*
)
set_tests_properties(
${PREFIX}/execute_exported_tests PROPERTIES
Expand Down
11 changes: 9 additions & 2 deletions test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,15 @@ template <>
hash256 from_json<hash256>(const json::json& j)
{
const auto s = j.get<std::string>();
if (s == "0" || s == "0x0") // Special case to handle "0". Required by exec-spec-tests.
return 0x00_bytes32; // TODO: Get rid of it.
if (s.size() < 66) // Special case to handle non-zero padded values
{
const auto s_ = s.substr(0, 2) == "0x" ? s : "0x" + s;
const auto opt_hash =
evmc::from_hex<hash256>("0x" + std::string(64 - s_.size(), '0') + s_.substr(2));
if (!opt_hash)
throw std::invalid_argument("invalid hash: " + s);

Check warning on line 98 in test/statetest/statetest_loader.cpp

View check run for this annotation

Codecov / codecov/patch

test/statetest/statetest_loader.cpp#L98

Added line #L98 was not covered by tests
return *opt_hash;
}

const auto opt_hash = evmc::from_hex<hash256>(s);
if (!opt_hash)
Expand Down

0 comments on commit 2710c0f

Please sign in to comment.