Skip to content

Commit d55a2d3

Browse files
committed
Validate genesis RLP in tests
Making sure that London headers are created properly
1 parent 6aaf268 commit d55a2d3

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/json-fixtures/blockchain/test_blockchain.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from eth.tools.rlp import (
1212
assert_mined_block_unchanged,
13+
assert_headers_eq,
1314
)
1415
from eth.tools._utils.normalization import (
1516
normalize_blockchain_fixtures,
@@ -24,6 +25,7 @@
2425
should_run_slow_tests,
2526
verify_state,
2627
)
28+
from eth.vm.header import HeaderSedes
2729

2830

2931
ROOT_PROJECT_DIR = Path(__file__).parents[3]
@@ -325,15 +327,22 @@ def test_blockchain_fixtures(fixture_data, fixture):
325327
except ValueError as e:
326328
raise AssertionError(f"could not load chain for {fixture_data}") from e
327329

328-
# TODO: find out if this is supposed to pass?
329-
# if 'genesisRLP' in fixture:
330-
# assert rlp.encode(genesis_header) == fixture['genesisRLP']
331-
332330
genesis_fields = genesis_fields_from_fixture(fixture)
333331

334332
genesis_block = chain.get_canonical_block_by_number(0)
335333
genesis_header = genesis_block.header
336334

335+
# Validate the genesis header RLP against the generated header
336+
if 'genesisRLP' in fixture:
337+
# Super hacky, but better than nothing: extract the header, then re-decode it
338+
fixture_decoded_block = rlp.decode(fixture['genesisRLP'])
339+
fixture_encoded_header = rlp.encode(fixture_decoded_block[0])
340+
fixture_header = rlp.decode(fixture_encoded_header, sedes=HeaderSedes)
341+
# Error message with pretty output if header doesn't match
342+
assert_headers_eq(fixture_header, genesis_header)
343+
# Last gut check that transactions & receipts are valid, too
344+
assert rlp.encode(genesis_block) == fixture['genesisRLP']
345+
337346
assert_imported_genesis_header_unchanged(genesis_fields, genesis_header)
338347

339348
# 1 - mine the genesis block

0 commit comments

Comments
 (0)