77
88import pytest
99
10+ from ethereum_test_base_types import HexNumber
1011from ethereum_test_benchmark .benchmark_code_generator import ExtCallGenerator , JumpLoopGenerator
1112from ethereum_test_forks import Fork
1213from ethereum_test_specs import StateTestFiller
@@ -442,7 +443,7 @@ def test_worst_blockhash(
442443 # Create 256 dummy blocks to fill the blockhash window.
443444 blocks = [Block ()] * 256
444445
445- code = ExtCallGenerator (setup = Bytecode (), attack_block = Op .BLOCKHASH (0 )).generate_repeated_code (
446+ code = ExtCallGenerator (setup = Bytecode (), attack_block = Op .BLOCKHASH (1 )).generate_repeated_code (
446447 repeated_code = Op .BLOCKHASH (1 ),
447448 setup = Bytecode (),
448449 cleanup = Bytecode (),
@@ -452,16 +453,14 @@ def test_worst_blockhash(
452453 iteration_count = math .ceil (gas_benchmark_value / tx_gas_limit_cap )
453454 code_address = pre .deploy_contract (code = code )
454455
456+ gas_remaining = gas_benchmark_value
455457 txs = []
456- for i in range (iteration_count ):
457- tx_gas_limit = (
458- tx_gas_limit_cap
459- if i != iteration_count - 1
460- else gas_benchmark_value % tx_gas_limit_cap
461- )
458+ for _ in range (iteration_count ):
459+ tx_gas_limit = min (tx_gas_limit_cap , gas_remaining )
460+ gas_remaining -= tx_gas_limit
462461 tx = Transaction (
463462 to = code_address ,
464- gas_limit = tx_gas_limit ,
463+ gas_limit = HexNumber ( tx_gas_limit ) ,
465464 sender = pre .fund_eoa (),
466465 )
467466 txs .append (tx )
@@ -471,6 +470,7 @@ def test_worst_blockhash(
471470 pre = pre ,
472471 post = {},
473472 blocks = blocks ,
473+ expected_benchmark_gas_used = gas_benchmark_value ,
474474 )
475475
476476
0 commit comments