Skip to content

Commit a1c3984

Browse files
authored
refactor(tests/zkevm): downgrade to state tests (#1660)
Convert benchmarks with single transaction to `state_test()`.
1 parent 4a21fb3 commit a1c3984

File tree

2 files changed

+53
-65
lines changed

2 files changed

+53
-65
lines changed

tests/zkevm/test_worst_compute.py

Lines changed: 40 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def make_dup(index: int) -> Opcode:
5757

5858
@pytest.mark.valid_from("Cancun")
5959
def test_worst_keccak(
60-
blockchain_test: BlockchainTestFiller,
60+
state_test: StateTestFiller,
6161
pre: Alloc,
6262
fork: Fork,
6363
):
@@ -122,11 +122,11 @@ def test_worst_keccak(
122122
sender=pre.fund_eoa(),
123123
)
124124

125-
blockchain_test(
125+
state_test(
126126
env=env,
127127
pre=pre,
128128
post={},
129-
blocks=[Block(txs=[tx])],
129+
tx=tx,
130130
)
131131

132132

@@ -141,7 +141,7 @@ def test_worst_keccak(
141141
)
142142
@pytest.mark.slow()
143143
def test_worst_precompile_only_data_input(
144-
blockchain_test: BlockchainTestFiller,
144+
state_test: StateTestFiller,
145145
pre: Alloc,
146146
fork: Fork,
147147
address: Address,
@@ -203,19 +203,18 @@ def test_worst_precompile_only_data_input(
203203
sender=pre.fund_eoa(),
204204
)
205205

206-
blockchain_test(
206+
state_test(
207207
env=env,
208208
pre=pre,
209209
post={},
210-
blocks=[Block(txs=[tx])],
210+
tx=tx,
211211
)
212212

213213

214214
@pytest.mark.valid_from("Cancun")
215215
def test_worst_modexp(
216-
blockchain_test: BlockchainTestFiller,
216+
state_test: StateTestFiller,
217217
pre: Alloc,
218-
fork: Fork,
219218
):
220219
"""Test running a block with as many MODEXP calls as possible."""
221220
env = Environment()
@@ -252,11 +251,11 @@ def test_worst_modexp(
252251
sender=pre.fund_eoa(),
253252
)
254253

255-
blockchain_test(
254+
state_test(
256255
env=env,
257256
pre=pre,
258257
post={},
259-
blocks=[Block(txs=[tx])],
258+
tx=tx,
260259
)
261260

262261

@@ -407,7 +406,7 @@ def test_worst_modexp(
407406
)
408407
@pytest.mark.slow()
409408
def test_worst_precompile_fixed_cost(
410-
blockchain_test: BlockchainTestFiller,
409+
state_test: StateTestFiller,
411410
pre: Alloc,
412411
precompile_address: Address,
413412
parameters: list[str] | list[BytesConcatenation] | list[bytes],
@@ -452,11 +451,11 @@ def test_worst_precompile_fixed_cost(
452451
sender=pre.fund_eoa(),
453452
)
454453

455-
blockchain_test(
454+
state_test(
456455
env=env,
457456
pre=pre,
458457
post={},
459-
blocks=[Block(txs=[tx])],
458+
tx=tx,
460459
)
461460

462461

@@ -480,9 +479,8 @@ def code_loop_precompile_call(calldata: Bytecode, attack_block: Bytecode):
480479
@pytest.mark.valid_from("Cancun")
481480
@pytest.mark.slow
482481
def test_worst_jumps(
483-
blockchain_test: BlockchainTestFiller,
482+
state_test: StateTestFiller,
484483
pre: Alloc,
485-
fork: Fork,
486484
):
487485
"""Test running a JUMP-intensive contract."""
488486
env = Environment()
@@ -501,29 +499,26 @@ def jump_seq():
501499
caller_code = While(body=Op.POP(Op.CALL(address=jumps_address)))
502500
caller_address = pre.deploy_contract(caller_code)
503501

504-
txs = [
505-
Transaction(
506-
to=caller_address,
507-
gas_limit=env.gas_limit,
508-
sender=pre.fund_eoa(),
509-
)
510-
]
502+
tx = Transaction(
503+
to=caller_address,
504+
gas_limit=env.gas_limit,
505+
sender=pre.fund_eoa(),
506+
)
511507

512-
blockchain_test(
508+
state_test(
513509
genesis_environment=env,
514510
pre=pre,
515511
post={},
516-
blocks=[Block(txs=txs)],
512+
tx=tx,
517513
)
518514

519515

520516
@pytest.mark.zkevm
521517
@pytest.mark.valid_from("Cancun")
522518
@pytest.mark.slow
523519
def test_worst_jumpdests(
524-
blockchain_test: BlockchainTestFiller,
520+
state_test: StateTestFiller,
525521
pre: Alloc,
526-
fork: Fork,
527522
):
528523
"""Test running a JUMPDEST-intensive contract."""
529524
env = Environment()
@@ -536,19 +531,17 @@ def test_worst_jumpdests(
536531
caller_code = While(body=Op.POP(Op.CALL(address=jumpdests_address)))
537532
caller_address = pre.deploy_contract(caller_code)
538533

539-
txs = [
540-
Transaction(
541-
to=caller_address,
542-
gas_limit=env.gas_limit,
543-
sender=pre.fund_eoa(),
544-
)
545-
]
534+
tx = Transaction(
535+
to=caller_address,
536+
gas_limit=env.gas_limit,
537+
sender=pre.fund_eoa(),
538+
)
546539

547-
blockchain_test(
540+
state_test(
548541
genesis_environment=env,
549542
pre=pre,
550543
post={},
551-
blocks=[Block(txs=txs)],
544+
tx=tx,
552545
)
553546

554547

@@ -676,7 +669,7 @@ def test_worst_jumpdests(
676669
ids=lambda param: "" if isinstance(param, tuple) else param,
677670
)
678671
def test_worst_binop_simple(
679-
blockchain_test: BlockchainTestFiller,
672+
state_test: StateTestFiller,
680673
pre: Alloc,
681674
opcode: Op,
682675
opcode_args: tuple[int, int],
@@ -704,18 +697,18 @@ def test_worst_binop_simple(
704697
sender=pre.fund_eoa(),
705698
)
706699

707-
blockchain_test(
700+
state_test(
708701
env=env,
709702
pre=pre,
710703
post={},
711-
blocks=[Block(txs=[tx])],
704+
tx=tx,
712705
)
713706

714707

715708
@pytest.mark.valid_from("Cancun")
716709
@pytest.mark.parametrize("opcode", [Op.ISZERO, Op.NOT])
717710
def test_worst_unop(
718-
blockchain_test: BlockchainTestFiller,
711+
state_test: StateTestFiller,
719712
pre: Alloc,
720713
opcode: Op,
721714
):
@@ -738,18 +731,18 @@ def test_worst_unop(
738731
sender=pre.fund_eoa(),
739732
)
740733

741-
blockchain_test(
734+
state_test(
742735
env=env,
743736
pre=pre,
744737
post={},
745-
blocks=[Block(txs=[tx])],
738+
tx=tx,
746739
)
747740

748741

749742
@pytest.mark.valid_from("Cancun")
750743
@pytest.mark.parametrize("shift_right", [Op.SHR, Op.SAR])
751744
def test_worst_shifts(
752-
blockchain_test: BlockchainTestFiller,
745+
state_test: StateTestFiller,
753746
pre: Alloc,
754747
shift_right: Op,
755748
):
@@ -822,19 +815,19 @@ def select_shift_amount(shift_fn, v):
822815
sender=pre.fund_eoa(),
823816
)
824817

825-
blockchain_test(
818+
state_test(
826819
env=env,
827820
pre=pre,
828821
post={},
829-
blocks=[Block(txs=[tx])],
822+
tx=tx,
830823
)
831824

832825

833826
@pytest.mark.valid_from("Cancun")
834827
@pytest.mark.parametrize("mod_bits", [255, 191, 127, 63])
835828
@pytest.mark.parametrize("op", [Op.MOD, Op.SMOD])
836829
def test_worst_mod(
837-
blockchain_test: BlockchainTestFiller,
830+
state_test: StateTestFiller,
838831
pre: Alloc,
839832
mod_bits: int,
840833
op: Op,
@@ -944,19 +937,18 @@ def test_worst_mod(
944937
sender=pre.fund_eoa(),
945938
)
946939

947-
blockchain_test(
940+
state_test(
948941
env=env,
949942
pre=pre,
950943
post={},
951-
blocks=[Block(txs=[tx])],
944+
tx=tx,
952945
)
953946

954947

955948
@pytest.mark.valid_from("Cancun")
956949
def test_empty_block(
957950
blockchain_test: BlockchainTestFiller,
958951
pre: Alloc,
959-
fork: Fork,
960952
):
961953
"""Test running an empty block as a baseline for fixed proving costs."""
962954
env = Environment()

tests/zkevm/test_worst_stateful_opcodes.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
BlockchainTestFiller,
1717
Bytecode,
1818
Environment,
19+
StateTestFiller,
1920
Transaction,
2021
While,
2122
compute_create_address,
@@ -134,9 +135,8 @@ def test_worst_address_state_cold(
134135
)
135136
@pytest.mark.slow()
136137
def test_worst_address_state_warm(
137-
blockchain_test: BlockchainTestFiller,
138+
state_test: StateTestFiller,
138139
pre: Alloc,
139-
fork: Fork,
140140
opcode: Op,
141141
absent_target: bool,
142142
):
@@ -165,17 +165,17 @@ def test_worst_address_state_warm(
165165
# Must never happen, but keep it as a sanity check.
166166
raise ValueError(f"Code size {len(op_code)} exceeds maximum code size {MAX_CODE_SIZE}")
167167
op_address = pre.deploy_contract(code=op_code)
168-
op_tx = Transaction(
168+
tx = Transaction(
169169
to=op_address,
170170
gas_limit=attack_gas_limit,
171171
sender=pre.fund_eoa(),
172172
)
173173

174-
blockchain_test(
174+
state_test(
175175
genesis_environment=env,
176176
pre=pre,
177177
post=post,
178-
blocks=[Block(txs=[op_tx])],
178+
tx=tx,
179179
)
180180

181181

@@ -313,7 +313,6 @@ def test_worst_storage_access_cold(
313313
def test_worst_storage_access_warm(
314314
blockchain_test: BlockchainTestFiller,
315315
pre: Alloc,
316-
fork: Fork,
317316
storage_action: StorageAction,
318317
):
319318
"""Test running a block with as many warm storage slot accesses as possible."""
@@ -380,7 +379,6 @@ def test_worst_storage_access_warm(
380379
def test_worst_blockhash(
381380
blockchain_test: BlockchainTestFiller,
382381
pre: Alloc,
383-
fork: Fork,
384382
):
385383
"""Test running a block with as many blockhash accessing oldest allowed block as possible."""
386384
env = Environment()
@@ -411,9 +409,8 @@ def test_worst_blockhash(
411409
@pytest.mark.valid_from("Cancun")
412410
@pytest.mark.slow()
413411
def test_worst_selfbalance(
414-
blockchain_test: BlockchainTestFiller,
412+
state_test: StateTestFiller,
415413
pre: Alloc,
416-
fork: Fork,
417414
):
418415
"""Test running a block with as many SELFBALANCE opcodes as possible."""
419416
env = Environment()
@@ -422,17 +419,17 @@ def test_worst_selfbalance(
422419
body=Op.POP(Op.SELFBALANCE),
423420
)
424421
execution_code_address = pre.deploy_contract(code=execution_code)
425-
op_tx = Transaction(
422+
tx = Transaction(
426423
to=execution_code_address,
427424
gas_limit=env.gas_limit,
428425
sender=pre.fund_eoa(),
429426
)
430427

431-
blockchain_test(
428+
state_test(
432429
genesis_environment=env,
433430
pre=pre,
434431
post={},
435-
blocks=[Block(txs=[op_tx])],
432+
tx=tx,
436433
)
437434

438435

@@ -447,9 +444,8 @@ def test_worst_selfbalance(
447444
)
448445
@pytest.mark.slow()
449446
def test_worst_extcodecopy_warm(
450-
blockchain_test: BlockchainTestFiller,
447+
state_test: StateTestFiller,
451448
pre: Alloc,
452-
fork: Fork,
453449
copied_size: int,
454450
):
455451
"""Test running a block with as many wamr EXTCODECOPY work as possible."""
@@ -467,15 +463,15 @@ def test_worst_extcodecopy_warm(
467463
)
468464
)
469465
execution_code_address = pre.deploy_contract(code=execution_code)
470-
op_tx = Transaction(
466+
tx = Transaction(
471467
to=execution_code_address,
472468
gas_limit=env.gas_limit,
473469
sender=pre.fund_eoa(),
474470
)
475471

476-
blockchain_test(
472+
state_test(
477473
genesis_environment=env,
478474
pre=pre,
479475
post={},
480-
blocks=[Block(txs=[op_tx])],
476+
tx=tx,
481477
)

0 commit comments

Comments
 (0)