77 Block ,
88 BlockchainTestFiller ,
99 Op ,
10- Storage ,
1110 Transaction ,
1211)
12+ from execution_testing .forks import Byzantium
13+ from execution_testing .forks .helpers import Fork
1314
1415
1516@pytest .mark .valid_from ("Frontier" )
17+ @pytest .mark .parametrize (
18+ "setup_blocks_num,setup_blocks_empty" ,
19+ [
20+ pytest .param (0 , True , id = "no_blocks" ),
21+ pytest .param (1 , False , id = "one_empty_block" ),
22+ pytest .param (1 , True , id = "one_block_with_tx" ),
23+ pytest .param (256 , True , id = "256_empty_blocks" ),
24+ ],
25+ )
1626def test_genesis_hash_available (
17- blockchain_test : BlockchainTestFiller , pre : Alloc
27+ blockchain_test : BlockchainTestFiller ,
28+ pre : Alloc ,
29+ fork : Fork ,
30+ setup_blocks_num : int ,
31+ setup_blocks_empty : bool ,
1832) -> None :
1933 """
2034 Verify BLOCKHASH returns genesis and block 1 hashes.
@@ -29,45 +43,53 @@ def test_genesis_hash_available(
2943 Bug context: revm blockchaintest runner wasn't inserting block_hashes,
3044 causing failures in tests with BLOCKHASH-derived addresses.
3145 """
32- storage = Storage ()
33-
3446 # Store ISZERO(BLOCKHASH(0)) and ISZERO(BLOCKHASH(1))
3547 # 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 )))
48+ code = Op .SSTORE (0 , Op . ISZERO ( Op . BLOCKHASH ( 0 ))) + Op . SSTORE (
49+ 1 , Op .ISZERO (Op .BLOCKHASH (1 ))
50+ )
3951
4052 contract = pre .deploy_contract (code = code )
4153 sender = pre .fund_eoa ()
4254
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- ]
55+ blocks = (
56+ [
57+ Block (
58+ txs = [
59+ Transaction (
60+ sender = sender ,
61+ to = contract ,
62+ gas_limit = 100_000 ,
63+ protected = fork >= Byzantium ,
64+ )
65+ ]
66+ if not setup_blocks_empty
67+ else []
68+ )
69+ for _ in range (setup_blocks_num )
70+ ]
71+ ) + (
72+ [
73+ Block (
74+ txs = [
75+ Transaction (
76+ sender = sender ,
77+ to = contract ,
78+ gas_limit = 100_000 ,
79+ protected = fork >= Byzantium ,
80+ )
81+ ]
82+ )
83+ ]
84+ )
6585
6686 post = {
6787 contract : Account (
6888 storage = {
69- 0 : 0 , # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
70- 1 : 0 , # ISZERO(BLOCKHASH(1)) = 0 (block 1 hash exists)
89+ # ISZERO(BLOCKHASH(0)) = 0 (genesis hash exists)
90+ 0 : 1 if setup_blocks_num >= 256 else 0 ,
91+ # ISZERO(BLOCKHASH(1)) = 0 (if block 1 hash exists)
92+ 1 : 1 if setup_blocks_num == 0 else 0 ,
7193 }
7294 )
7395 }
0 commit comments