Skip to content

test: Match blockchain test exceptions#1556

Merged
chfast merged 1 commit into
masterfrom
test/block-validation-errors
May 29, 2026
Merged

test: Match blockchain test exceptions#1556
chfast merged 1 commit into
masterfrom
test/block-validation-errors

Conversation

@chfast
Copy link
Copy Markdown
Member

@chfast chfast commented May 29, 2026

The blockchain test runner treated block validity as a bool: for a block expected to be invalid it accepted ANY rejection and never checked that the reason matched the fixture's expectException. So a block rejected for the wrong reason still passed.

Make validate_block return a std::error_code instead of bool, with new block-level entries appended (at the back, keeping existing values stable) to state::ErrorCode. Each entry's message is the matching execution-spec-tests BlockException constant (INVALID_GASLIMIT, INVALID_BASEFEE_PER_GAS, INCORRECT_EXCESS_BLOB_GAS, RLP_BLOCK_LIMIT_EXCEEDED, INVALID_BLOCK_TIMESTAMP_OLDER_THAN_PARENT, INCORRECT_BLOCK_FORMAT for the rest). The loader captures the expectException string; the runner substring-matches the actual error's constant against it, which also handles the fixtures' |-separated alternatives.

Legacy ethereum/tests fixtures use older, sometimes finer-grained exception names (e.g. uncles after Paris, a number gap, a wrong base fee). The loader maps those (many-to-one) onto the BlockException constant evmone reports, so they match by reason as well.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 29, 2026

Codecov Report

❌ Patch coverage is 87.32394% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.07%. Comparing base (1c0a9b9) to head (dc1ce13).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
test/blockchaintest/blockchaintest_runner.cpp 85.71% 4 Missing and 1 partial ⚠️
test/state/errors.hpp 75.00% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1556      +/-   ##
==========================================
- Coverage   97.09%   97.07%   -0.02%     
==========================================
  Files         162      162              
  Lines       14440    14480      +40     
  Branches     3370     3380      +10     
==========================================
+ Hits        14021    14057      +36     
- Misses        303      305       +2     
- Partials      116      118       +2     
Flag Coverage Δ
eest-develop 91.84% <66.66%> (-0.10%) ⬇️
eest-develop-gmp 26.44% <0.00%> (-0.08%) ⬇️
eest-legacy 17.69% <74.64%> (+0.17%) ⬆️
eest-libsecp256k1 28.08% <0.00%> (-0.08%) ⬇️
eest-stable 91.78% <66.66%> (-0.10%) ⬇️
evmone-unittests 92.53% <15.49%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 95.94% <75.00%> (-0.08%) ⬇️
tooling 87.81% <90.90%> (+0.16%) ⬆️
tests 99.79% <ø> (ø)
Files with missing lines Coverage Δ
test/utils/blockchaintest_loader.cpp 93.65% <100.00%> (+1.12%) ⬆️
test/state/errors.hpp 84.05% <75.00%> (-2.74%) ⬇️
test/blockchaintest/blockchaintest_runner.cpp 85.99% <85.71%> (+0.27%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread test/utils/blockchaintest_loader.cpp Outdated
Comment thread test/utils/blockchaintest.hpp Outdated
Comment thread test/state/errors.hpp Outdated
Comment thread test/blockchaintest/blockchaintest_runner.cpp Outdated
Comment thread test/blockchaintest/blockchaintest_runner.cpp Outdated
Comment thread test/blockchaintest/blockchaintest_runner.cpp Outdated
@chfast chfast force-pushed the test/block-validation-errors branch 2 times, most recently from 094b74f to ecc26f5 Compare May 29, 2026 15:53
@chfast chfast requested a review from Copilot May 29, 2026 15:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR tightens blockchain test validation by requiring invalid blocks to fail for the expected reason (matching fixtures’ expectException), rather than treating “any rejection” as a pass. It introduces block-level error codes and threads the expected exception through loading and execution so the runner can compare actual vs. expected failure reasons.

Changes:

  • Replace TestBlock::valid with TestBlock::expected_exception (empty means valid).
  • Change validate_block() to return std::error_code with new block-level state::ErrorCode values whose messages match EEST BlockException.* constants.
  • Map legacy ethereum/tests exception names to the EEST constants during fixture loading, and substring-match the resulting expected exception against the actual validation error message in the runner.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
test/utils/blockchaintest.hpp Switches block validity signaling from a boolean to an expected_exception string (empty => valid).
test/utils/blockchaintest_loader.cpp Captures expectException and rewrites legacy exception names to the BlockException.* constant evmone reports.
test/state/errors.hpp Appends block-level ErrorCode entries and maps them to BlockException.*-style messages via the error category.
test/blockchaintest/blockchaintest_runner.cpp Uses std::error_code results from validate_block() and checks invalid blocks’ rejection reasons against fixture expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chfast chfast force-pushed the test/block-validation-errors branch from ecc26f5 to 90571ec Compare May 29, 2026 16:11
The blockchain test runner treated block validity as a bool: for a block
expected to be invalid it accepted ANY rejection and never checked that
the reason matched the fixture's `expectException`. So a block rejected
for the wrong reason still passed.

Make `validate_block` return a `std::error_code` instead of `bool`, with
new block-level entries appended (at the back, keeping existing values
stable) to `state::ErrorCode`. Each entry's message is the matching
execution-spec-tests `BlockException` constant (INVALID_GASLIMIT,
INVALID_BASEFEE_PER_GAS, INCORRECT_EXCESS_BLOB_GAS,
RLP_BLOCK_LIMIT_EXCEEDED, INVALID_BLOCK_TIMESTAMP_OLDER_THAN_PARENT,
INVALID_BLOCK_NUMBER, INCORRECT_BLOCK_FORMAT for the rest), except the
missing-parent check which uses evmone's own INVALID_BLOCK_PARENT (a
broader condition than EEST's UNKNOWN_PARENT). The loader captures the
`expectException` string; the runner substring-matches the actual error's
constant against it, which also handles the fixtures' `|`-separated
alternatives.

Legacy ethereum/tests fixtures use older, sometimes finer-grained
exception names (e.g. uncles after Paris, a number gap, a wrong base
fee). The loader maps those (many-to-one) onto the `BlockException`
constant evmone reports, so they match by reason as well.
@chfast chfast force-pushed the test/block-validation-errors branch from 90571ec to dc1ce13 Compare May 29, 2026 21:12
@chfast chfast requested a review from Copilot May 29, 2026 21:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

Comment thread test/utils/blockchaintest_loader.cpp
Comment on lines +392 to 396
EXPECT_NE(test_block.expected_exception.find(block_error.message()),
std::string::npos)
<< "Block invalidity reason mismatch: got " << block_error.message()
<< ", expected " << test_block.expected_exception;
continue;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chfast chfast merged commit b76a4f8 into master May 29, 2026
22 of 24 checks passed
@chfast chfast deleted the test/block-validation-errors branch May 29, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants