7
7
8
8
import pytest
9
9
10
+ from ethereum_test_base_types import HexNumber
10
11
from ethereum_test_benchmark .benchmark_code_generator import ExtCallGenerator , JumpLoopGenerator
11
12
from ethereum_test_forks import Fork
12
13
from ethereum_test_specs import StateTestFiller
@@ -442,7 +443,7 @@ def test_worst_blockhash(
442
443
# Create 256 dummy blocks to fill the blockhash window.
443
444
blocks = [Block ()] * 256
444
445
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 (
446
447
repeated_code = Op .BLOCKHASH (1 ),
447
448
setup = Bytecode (),
448
449
cleanup = Bytecode (),
@@ -452,16 +453,14 @@ def test_worst_blockhash(
452
453
iteration_count = math .ceil (gas_benchmark_value / tx_gas_limit_cap )
453
454
code_address = pre .deploy_contract (code = code )
454
455
456
+ gas_remaining = gas_benchmark_value
455
457
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
462
461
tx = Transaction (
463
462
to = code_address ,
464
- gas_limit = tx_gas_limit ,
463
+ gas_limit = HexNumber ( tx_gas_limit ) ,
465
464
sender = pre .fund_eoa (),
466
465
)
467
466
txs .append (tx )
@@ -471,6 +470,7 @@ def test_worst_blockhash(
471
470
pre = pre ,
472
471
post = {},
473
472
blocks = blocks ,
473
+ expected_benchmark_gas_used = gas_benchmark_value ,
474
474
)
475
475
476
476
0 commit comments