Skip to content

test: Check the transaction codec against every fixture encoding - #1617

Merged
chfast merged 1 commit into
masterfrom
test/tx-codec-round-trip
Jul 27, 2026
Merged

test: Check the transaction codec against every fixture encoding#1617
chfast merged 1 commit into
masterfrom
test/tx-codec-round-trip

Conversation

@chfast

@chfast chfast commented Jul 27, 2026

Copy link
Copy Markdown
Member

decode_transaction() is meant to be the inverse of rlp_encode(), but nothing held it to that. The state test runner dropped the input bytes once it had decoded them, and the blockchain runner never looked at a block's serialization at all -- it took the transactions from the fixture's JSON.

Re-encode each decoded transaction and compare it with the bytes it came from: the state test's txbytes, and every transaction sliced out of a valid block's RLP. A legacy transaction is a list item there, a typed one an RLP string wrapping the EIP-2718 envelope. Invalid blocks are skipped, their transactions need not decode at all.

Keeping the block's serialization for that also replaces TestBlock's rlp_size, which was all the runner needed from it so far.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.46%. Comparing base (aa82563) to head (e928eaa).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1617   +/-   ##
=======================================
  Coverage   97.46%   97.46%           
=======================================
  Files         170      170           
  Lines       15381    15402   +21     
  Branches     3593     3604   +11     
=======================================
+ Hits        14991    15012   +21     
  Misses        282      282           
  Partials      108      108           
Flag Coverage Δ
eest-develop 88.34% <100.00%> (+0.04%) ⬆️
eest-develop-gmp 25.78% <4.16%> (+0.17%) ⬆️
eest-legacy 17.37% <91.66%> (+0.61%) ⬆️
eest-libsecp256k1 27.91% <4.16%> (+0.17%) ⬆️
eest-stable 88.30% <100.00%> (+0.04%) ⬆️
evmone-unittests 93.00% <79.16%> (-0.01%) ⬇️

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

Components Coverage Δ
core 95.99% <ø> (ø)
tooling 90.42% <100.00%> (+0.11%) ⬆️
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
test/blockchaintest/blockchaintest_runner.cpp 85.24% <100.00%> (+1.31%) ⬆️
test/statetest/statetest_runner.cpp 85.71% <100.00%> (+0.34%) ⬆️
test/utils/blockchaintest_loader.cpp 95.41% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

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 strengthens fixture-based testing by asserting that state::decode_transaction() is a true inverse of the transaction encoder, using both state-test txbytes and transaction bytes extracted from a block’s own RLP serialization in blockchain tests.

Changes:

  • Store full block RLP bytes in TestBlock and use them for block size checks.
  • In state tests, re-encode each successfully decoded txbytes and compare byte-for-byte.
  • In blockchain tests, for valid blocks, slice each transaction out of the block RLP, decode it, and assert the encoding round-trips to the original bytes.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/utils/blockchaintest.hpp Replace stored rlp_size with full block RLP bytes on TestBlock.
test/utils/blockchaintest_loader.cpp Load and persist the full rlp bytes from fixtures into TestBlock.
test/statetest/statetest_runner.cpp Add encode-vs-txbytes round-trip assertion for decoded transactions.
test/blockchaintest/blockchaintest_runner.cpp Add per-transaction round-trip checks against bytes extracted from the block’s RLP; switch size checks to rlp.size().

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

Comment thread test/blockchaintest/blockchaintest_runner.cpp Outdated
decode_transaction() is meant to be the inverse of rlp_encode(), but
nothing held it to that. The state test runner dropped the input bytes
once it had decoded them, and the blockchain runner never looked at a
block's serialization at all -- it took the transactions from the
fixture's JSON.

Re-encode each decoded transaction and compare it with the bytes it came
from: the state test's txbytes, and every transaction sliced out of a
valid block's RLP. A legacy transaction is a list item there, a typed one
an RLP string wrapping the EIP-2718 envelope. Invalid blocks are skipped,
their transactions need not decode at all.

Keeping the block's serialization for that also replaces TestBlock's
rlp_size, which was all the runner needed from it so far. The hand-written
eip7778_block_gas fixture had only a placeholder there, since nothing but
its length was ever read; it now carries the encoding of the block it
describes.
@chfast
chfast force-pushed the test/tx-codec-round-trip branch from f5e90e3 to e928eaa Compare July 27, 2026 13:44
@chfast
chfast requested a review from Copilot July 27, 2026 13:56

Copilot AI left a comment

Copy link
Copy Markdown

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 5 out of 5 changed files in this pull request and generated no new comments.

@chfast
chfast merged commit d8508b9 into master Jul 27, 2026
24 checks passed
@chfast
chfast deleted the test/tx-codec-round-trip branch July 27, 2026 14:05
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