1313
1414
1515@pytest .mark .valid_from ("Frontier" )
16+ @pytest .mark .parametrize (
17+ "first_block" , ["none" , "empty" , "with_tx" , "over_256" ]
18+ )
1619def test_genesis_hash_available (
17- blockchain_test : BlockchainTestFiller , pre : Alloc
20+ blockchain_test : BlockchainTestFiller ,
21+ pre : Alloc ,
22+ first_block : str ,
1823) -> None :
1924 """
2025 Verify BLOCKHASH returns genesis and block 1 hashes.
@@ -29,45 +34,58 @@ def test_genesis_hash_available(
2934 Bug context: revm blockchaintest runner wasn't inserting block_hashes,
3035 causing failures in tests with BLOCKHASH-derived addresses.
3136 """
32- storage = Storage ()
37+ Storage ()
3338
3439 # Store ISZERO(BLOCKHASH(0)) and ISZERO(BLOCKHASH(1))
3540 # Both should be 0 (false) if hashes exist
36- code = Op .SSTORE (
37- storage . store_next ( 0 ) , Op .ISZERO (Op .BLOCKHASH (0 ))
38- ) + Op . SSTORE ( storage . store_next ( 0 ), Op . ISZERO ( Op . BLOCKHASH ( 1 )))
41+ code = Op .SSTORE (0 , Op . ISZERO ( Op . BLOCKHASH ( 0 ))) + Op . SSTORE (
42+ 1 , Op .ISZERO (Op .BLOCKHASH (1 ))
43+ )
3944
4045 contract = pre .deploy_contract (code = code )
4146 sender = pre .fund_eoa ()
4247
43- blocks = [
44- Block (
45- txs = [
46- Transaction (
47- sender = sender ,
48- to = contract ,
49- gas_limit = 100_000 ,
50- protected = False ,
51- )
52- ]
53- ),
54- Block (
55- txs = [
56- Transaction (
57- sender = sender ,
58- to = contract ,
59- gas_limit = 100_000 ,
60- protected = False ,
61- )
62- ]
63- ),
64- ]
48+ blocks = (
49+ [
50+ Block (
51+ txs = [
52+ Transaction (
53+ sender = sender ,
54+ to = contract ,
55+ gas_limit = 100_000 ,
56+ protected = False ,
57+ )
58+ ]
59+ )
60+ ]
61+ if first_block == "with_tx"
62+ else [Block ()]
63+ if first_block == "empty"
64+ else [Block ()] * 256
65+ if first_block == "over_256"
66+ else []
67+ ) + (
68+ [
69+ Block (
70+ txs = [
71+ Transaction (
72+ sender = sender ,
73+ to = contract ,
74+ gas_limit = 100_000 ,
75+ protected = False ,
76+ )
77+ ]
78+ )
79+ ]
80+ )
6581
6682 post = {
6783 contract : Account (
6884 storage = {
69- 0 : 0 , # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
70- 1 : 0 , # ISZERO(BLOCKHASH(1)) = 0 (block 1 hash exists)
85+ # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
86+ 0 : 1 if first_block == "over_256" else 0 ,
87+ # ISZERO(BLOCKHASH(1)) = 0 (if block 1 hash exists)
88+ 1 : 1 if first_block == "none" else 0 ,
7189 }
7290 )
7391 }
0 commit comments