Skip to content

Commit 293fa01

Browse files
refactor(benchmark): add contract deployment before tx generation
1 parent 8013d6e commit 293fa01

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

tests/benchmark/test_worst_compute.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ def test_worst_calldatasize(
106106
):
107107
"""Test running a block with as many CALLDATASIZE as possible."""
108108
generator = JumpLoopGenerator(setup=Bytecode(), attack_block=Op.POP(Op.CALLDATASIZE))
109+
generator.deploy_contracts(pre, fork)
109110
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
110111
tx.data = Bytes(b"\x00" * calldata_length)
111112

@@ -254,7 +255,7 @@ def test_worst_msize(
254255
setup=Op.MLOAD(Op.CALLVALUE) + Op.POP,
255256
attack_block=Op.MSIZE,
256257
)
257-
258+
generator.deploy_contracts(pre, fork)
258259
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
259260
tx.value = HexNumber(mem_size)
260261

@@ -1195,9 +1196,11 @@ def test_worst_modexp(
11951196
Op.STATICCALL(Op.GAS, 0x5, Op.PUSH0, Op.CALLDATASIZE, Op.PUSH0, Op.PUSH0)
11961197
)
11971198

1198-
tx = JumpLoopGenerator(
1199+
generator = JumpLoopGenerator(
11991200
setup=Op.CALLDATACOPY(0, 0, Op.CALLDATASIZE), attack_block=attack_block
1200-
).generate_transaction(pre, gas_benchmark_value, fork)
1201+
)
1202+
generator.deploy_contracts(pre, fork)
1203+
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
12011204
tx.data = Bytes(bytes(mod_exp_input).rstrip(b"\x00"))
12021205

12031206
benchmark_test(
@@ -2150,6 +2153,7 @@ def test_worst_blobhash(
21502153
):
21512154
"""Test running a block with as many BLOBHASH instructions as possible."""
21522155
generator = ExtCallGenerator(setup=Bytecode(), attack_block=Op.BLOBHASH(blob_index))
2156+
generator.deploy_contracts(pre, fork)
21532157
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
21542158

21552159
tx_type = TransactionType.LEGACY
@@ -2272,6 +2276,7 @@ def test_worst_mod(
22722276
)
22732277

22742278
generator = JumpLoopGenerator(setup=code_constant_pool, attack_block=code_segment)
2279+
generator.deploy_contracts(pre, fork)
22752280
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
22762281

22772282
input_value = initial_mod if not should_negate else neg(initial_mod)
@@ -2396,6 +2401,7 @@ def test_worst_modarith(
23962401
)
23972402

23982403
generator = JumpLoopGenerator(setup=code_constant_pool, attack_block=code_segment)
2404+
generator.deploy_contracts(pre, fork)
23992405
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
24002406
tx.data = Bytes(initial_mod.to_bytes(32, byteorder="big"))
24012407

@@ -2468,6 +2474,7 @@ def test_amortized_bn128_pairings(
24682474
attack_block = Op.POP(Op.STATICCALL(Op.GAS, 0x08, 0, Op.CALLDATASIZE, 0, 0))
24692475

24702476
generator = JumpLoopGenerator(setup=code_prefix, attack_block=attack_block)
2477+
generator.deploy_contracts(pre, fork)
24712478
tx = generator.generate_transaction(pre, gas_benchmark_value, fork)
24722479
tx.data = _generate_bn128_pairs(optimal_per_call_num_pairings, 42)
24732480

tests/benchmark/test_worst_stateful_opcodes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
from ethereum_test_benchmark.benchmark_code_generator import ExtCallGenerator, JumpLoopGenerator
1313
from ethereum_test_forks import Fork
14+
from ethereum_test_specs import BlockchainTestFiller
15+
from ethereum_test_specs.benchmark import BenchmarkTestFiller
1416
from ethereum_test_tools import (
1517
Account,
1618
Address,

0 commit comments

Comments
 (0)