test: Check the transaction codec against every fixture encoding - #1617
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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
TestBlockand use them for block size checks. - In state tests, re-encode each successfully decoded
txbytesand 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.
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
force-pushed
the
test/tx-codec-round-trip
branch
from
July 27, 2026 13:44
f5e90e3 to
e928eaa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.