Skip to content

Commit 9bc5127

Browse files
fix: update benchmark wrapper for execute mode
1 parent 3d638d9 commit 9bc5127

File tree

2 files changed

+51
-6
lines changed

2 files changed

+51
-6
lines changed

packages/testing/src/execution_testing/specs/benchmark.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,52 @@ def generate_blocks_from_code_generator(self) -> List[Block]:
290290

291291
return [execution_block]
292292

293-
def generate_blockchain_test(self) -> BlockchainTest:
293+
def generate_blocks(self, fork: Fork) -> List[Block]:
294+
"""Generate blocks for the benchmark test."""
295+
set_props = [
296+
name
297+
for name, val in [
298+
("code_generator", self.code_generator),
299+
("blocks", self.blocks),
300+
("tx", self.tx),
301+
]
302+
if val is not None
303+
]
304+
305+
if len(set_props) != 1:
306+
raise ValueError(
307+
f"Exactly one must be set, but got {len(set_props)}: {', '.join(set_props)}"
308+
)
309+
310+
blocks: List[Block] = []
311+
312+
if self.code_generator is not None:
313+
generated_blocks = self.generate_blocks_from_code_generator(fork)
314+
blocks += generated_blocks
315+
316+
elif self.blocks is not None:
317+
blocks += self.blocks
318+
319+
elif self.tx is not None:
320+
gas_limit = (
321+
fork.transaction_gas_limit_cap() or self.gas_benchmark_value
322+
)
323+
324+
transactions = self.split_transaction(self.tx, gas_limit)
325+
326+
blocks.append(Block(txs=transactions))
327+
328+
else:
329+
raise ValueError(
330+
"Cannot create BlockchainTest without a code generator, transactions, or blocks"
331+
)
332+
333+
return blocks
334+
335+
def generate_blockchain_test(self, fork: Fork) -> BlockchainTest:
294336
"""Create a BlockchainTest from this BenchmarkTest."""
337+
blocks: List[Block] = self.setup_blocks + self.generate_blocks(fork)
338+
295339
return BlockchainTest.from_test(
296340
base_test=self,
297341
genesis_environment=self.env,
@@ -323,8 +367,9 @@ def execute(
323367
) -> BaseExecute:
324368
"""Execute the benchmark test by sending it to the live network."""
325369
if execute_format == TransactionPost:
370+
blocks = self.generate_blocks(fork)
326371
return TransactionPost(
327-
blocks=[[self.tx]],
372+
blocks=[block.txs for block in blocks],
328373
post=self.post,
329374
)
330375
raise Exception(f"Unsupported execute format: {execute_format}")

tests/benchmark/test_worst_stateful_opcodes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def test_worst_address_state_cold(
9595

9696
setup_tx = Transaction(
9797
to=factory_address,
98-
gas_limit=env.gas_limit,
98+
gas_limit=20 * gas_benchmark_value,
9999
sender=pre.fund_eoa(),
100100
)
101101
blocks.append(Block(txs=[setup_tx]))
@@ -362,7 +362,7 @@ def test_worst_storage_access_cold(
362362
sender_addr = pre.fund_eoa()
363363
setup_tx = Transaction(
364364
to=None,
365-
gas_limit=env.gas_limit,
365+
gas_limit=20 * gas_benchmark_value,
366366
data=creation_code,
367367
sender=sender_addr,
368368
)
@@ -441,7 +441,7 @@ def test_worst_storage_access_warm(
441441
sender_addr = pre.fund_eoa()
442442
setup_tx = Transaction(
443443
to=None,
444-
gas_limit=env.gas_limit,
444+
gas_limit=20 * gas_benchmark_value,
445445
data=creation_code,
446446
sender=sender_addr,
447447
)
@@ -631,7 +631,7 @@ def test_worst_selfdestruct_existing(
631631

632632
contracts_deployment_tx = Transaction(
633633
to=factory_caller_address,
634-
gas_limit=env.gas_limit,
634+
gas_limit=20 * gas_benchmark_value,
635635
data=Hash(num_contracts),
636636
sender=pre.fund_eoa(),
637637
)

0 commit comments

Comments
 (0)