Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Check for unexpected EOF prefix in tests #809

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions test/statetest/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ void validate_state(const state::State& state, evmc_revision rev)
" is invalid: " + std::string(get_error_message(result)));
}
}
else
{
throw std::invalid_argument("unexpected code with EOF prefix at " + hex0x(addr));
}
}

for (const auto& [key, value] : acc.storage)
Expand Down
39 changes: 22 additions & 17 deletions test/unittests/statetest_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,30 @@ TEST(statetest_loader, load_minimal_test)

TEST(statetest_loader, validate_state_invalid_eof)
{
{
state::State state;
state.insert(0xadd4_address, {.code = "EF0001010000020001000103000100FEDA"_hex});
EXPECT_THAT([&] { validate_state(state, EVMC_PRAGUE); },
ThrowsMessage<std::invalid_argument>(
"EOF container at 0x000000000000000000000000000000000000add4 is invalid: "
"zero_section_size"));
}
state::State state;
state.insert(0xadd4_address, {.code = "EF0001010000020001000103000100FEDA"_hex});
EXPECT_THAT([&] { validate_state(state, EVMC_PRAGUE); },
ThrowsMessage<std::invalid_argument>(
"EOF container at 0x000000000000000000000000000000000000add4 is invalid: "
"zero_section_size"));
}

TEST(statetest_loader, validate_state_unexpected_eof)
{
state::State state;
state.insert(0xadd4_address, {.code = "EF00"_hex});
EXPECT_THAT([&] { validate_state(state, EVMC_CANCUN); },
ThrowsMessage<std::invalid_argument>(
"unexpected code with EOF prefix at 0x000000000000000000000000000000000000add4"));
}

TEST(statetest_loader, validate_state_zero_storage_slot)
{
{
state::State state;
state.insert(0xadd4_address, {.storage = {{0x01_bytes32, {0x00_bytes32}}}});
EXPECT_THAT([&] { validate_state(state, EVMC_PRAGUE); },
ThrowsMessage<std::invalid_argument>(
"account 0x000000000000000000000000000000000000add4 contains invalid zero-value "
"storage entry "
"0x0000000000000000000000000000000000000000000000000000000000000001"));
}
state::State state;
state.insert(0xadd4_address, {.storage = {{0x01_bytes32, {0x00_bytes32}}}});
EXPECT_THAT([&] { validate_state(state, EVMC_PRAGUE); },
ThrowsMessage<std::invalid_argument>(
"account 0x000000000000000000000000000000000000add4 contains invalid zero-value "
"storage entry "
"0x0000000000000000000000000000000000000000000000000000000000000001"));
}