Skip to content

Commit 67d8f43

Browse files
committed
tests: BlockchainTest to StateTest conversions (#370)
1 parent 340b011 commit 67d8f43

File tree

7 files changed

+174
-69
lines changed

7 files changed

+174
-69
lines changed

docs/CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Test fixtures for use by clients are available for each release on the [Github r
99
### 🧪 Test Cases
1010

1111
- 🔀 Add reentrancy suicide revert test ([#372](https://github.com/ethereum/execution-spec-tests/pull/372)).
12-
- 🔀 BlockchainTests converted to StateTest (also automatically generate BlockchainTest) ([#368](https://github.com/ethereum/execution-spec-tests/pull/368)):
12+
- 🔀 BlockchainTests converted to StateTest (also automatically generate BlockchainTest) ([#368](https://github.com/ethereum/execution-spec-tests/pull/368), [#370](https://github.com/ethereum/execution-spec-tests/pull/370)):
1313
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_invalid_normal_gas
1414
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_insufficient_balance_blob_tx
1515
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_invalid_tx_blob_count
@@ -19,6 +19,17 @@ Test fixtures for use by clients are available for each release on the [Github r
1919
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_blob_tx_attribute_calldata_opcodes
2020
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_blob_tx_attribute_gasprice_opcode
2121
- tests/cancun/eip4844_blobs/test_blob_txs.py::test_blob_type_tx_pre_fork
22+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py::test_point_evaluation_precompile_gas_usage
23+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_valid_precompile_calls
24+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_invalid_precompile_calls
25+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_point_evaluation_precompile_external_vectors
26+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_point_evaluation_precompile_calls
27+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_point_evaluation_precompile_gas_tx_to
28+
- tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py::test_point_evaluation_precompile_before_fork
29+
- tests/cancun/eip7516_blobgasfee/test_blobgasfee_opcode.py::test_blobbasefee_before_fork
30+
- tests/shanghai/eip3860_initcode/test_initcode.py::test_contract_creating_tx
31+
- tests/shanghai/eip3860_initcode/test_initcode.py::TestContractCreationGasUsage
32+
- 🐞 Fixed `tests/cancun/eip4844_blobs/test_blob_txs.py:test_invalid_tx_max_fee_per_blob_gas` to account for extra gas required in the case where the account is incorrectly deduced the balance as if it had the correct block blob gas fee ([#370](https://github.com/ethereum/execution-spec-tests/pull/370)).
2233

2334
### 🛠️ Framework
2435

tests/cancun/eip4844_blobs/test_blob_txs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,10 @@ def test_valid_blob_tx_combinations(
589589
),
590590
],
591591
)
592+
@pytest.mark.parametrize(
593+
"account_balance_modifier",
594+
[1_000_000_000],
595+
) # Extra balance to cover block blob gas cost
592596
@pytest.mark.valid_from("Cancun")
593597
def test_invalid_tx_max_fee_per_blob_gas(
594598
blockchain_test: BlockchainTestFiller,

tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py

Lines changed: 99 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
Add a function that is named `test_<test_name>` and takes at least the following arguments:
99
10-
- blockchain_test
10+
- blockchain_test | state_test
1111
- pre
1212
- tx
1313
- post
@@ -31,15 +31,16 @@
3131
import glob
3232
import json
3333
import os
34-
from typing import Dict, Iterator, List
34+
from typing import Dict, Iterator, List, Optional
3535

3636
import pytest
3737

3838
from ethereum_test_tools import (
3939
Account,
40-
Auto,
4140
Block,
4241
BlockchainTestFiller,
42+
Environment,
43+
StateTestFiller,
4344
Storage,
4445
TestAddress,
4546
Transaction,
@@ -54,12 +55,10 @@
5455
REFERENCE_SPEC_GIT_PATH = ref_spec_4844.git_path
5556
REFERENCE_SPEC_VERSION = ref_spec_4844.version
5657

57-
auto = Auto()
58-
5958

6059
@pytest.fixture
6160
def precompile_input(
62-
versioned_hash: bytes | int | Auto,
61+
versioned_hash: Optional[bytes | int],
6362
kzg_commitment: bytes | int,
6463
z: bytes | int,
6564
y: bytes | int,
@@ -76,7 +75,7 @@ def precompile_input(
7675
kzg_commitment = kzg_commitment.to_bytes(48, "big")
7776
if isinstance(kzg_proof, int):
7877
kzg_proof = kzg_proof.to_bytes(48, "big")
79-
if isinstance(versioned_hash, Auto):
78+
if versioned_hash is None:
8079
versioned_hash = Spec.kzg_to_versioned_hash(kzg_commitment)
8180
elif isinstance(versioned_hash, int):
8281
versioned_hash = versioned_hash.to_bytes(32, "big")
@@ -245,13 +244,13 @@ def post(
245244
@pytest.mark.parametrize(
246245
"z,y,kzg_commitment,kzg_proof,versioned_hash",
247246
[
248-
pytest.param(Spec.BLS_MODULUS - 1, 0, INF_POINT, INF_POINT, auto, id="in_bounds_z"),
247+
pytest.param(Spec.BLS_MODULUS - 1, 0, INF_POINT, INF_POINT, None, id="in_bounds_z"),
249248
],
250249
)
251250
@pytest.mark.parametrize("success", [True])
252251
@pytest.mark.valid_from("Cancun")
253252
def test_valid_precompile_calls(
254-
blockchain_test: BlockchainTestFiller,
253+
state_test: StateTestFiller,
255254
pre: Dict,
256255
tx: Transaction,
257256
post: Dict,
@@ -262,25 +261,26 @@ def test_valid_precompile_calls(
262261
- `kzg_commitment` and `kzg_proof` are set to values such that `p(z)==0` for all values of `z`,
263262
hence `y` is tested to be zero, and call to be successful.
264263
"""
265-
blockchain_test(
264+
state_test(
265+
env=Environment(),
266266
pre=pre,
267267
post=post,
268-
blocks=[Block(txs=[tx])],
268+
tx=tx,
269269
)
270270

271271

272272
@pytest.mark.parametrize(
273273
"z,y,kzg_commitment,kzg_proof,versioned_hash",
274274
[
275-
(Spec.BLS_MODULUS, 0, INF_POINT, INF_POINT, auto),
276-
(0, Spec.BLS_MODULUS, INF_POINT, INF_POINT, auto),
277-
(Z, 0, INF_POINT, INF_POINT[:-1], auto),
278-
(Z, 0, INF_POINT, INF_POINT[0:1], auto),
279-
(Z, 0, INF_POINT, INF_POINT + bytes([0]), auto),
280-
(Z, 0, INF_POINT, INF_POINT + bytes([0] * 1023), auto),
275+
(Spec.BLS_MODULUS, 0, INF_POINT, INF_POINT, None),
276+
(0, Spec.BLS_MODULUS, INF_POINT, INF_POINT, None),
277+
(Z, 0, INF_POINT, INF_POINT[:-1], None),
278+
(Z, 0, INF_POINT, INF_POINT[0:1], None),
279+
(Z, 0, INF_POINT, INF_POINT + bytes([0]), None),
280+
(Z, 0, INF_POINT, INF_POINT + bytes([0] * 1023), None),
281281
(bytes(), bytes(), bytes(), bytes(), bytes()),
282282
(0, 0, 0, 0, 0),
283-
(0, 0, 0, 0, auto),
283+
(0, 0, 0, 0, None),
284284
(Z, 0, INF_POINT, INF_POINT, Spec.kzg_to_versioned_hash(0xC0 << 376, 0x00)),
285285
(Z, 0, INF_POINT, INF_POINT, Spec.kzg_to_versioned_hash(0xC0 << 376, 0x02)),
286286
(Z, 0, INF_POINT, INF_POINT, Spec.kzg_to_versioned_hash(0xC0 << 376, 0xFF)),
@@ -303,7 +303,7 @@ def test_valid_precompile_calls(
303303
@pytest.mark.parametrize("success", [False])
304304
@pytest.mark.valid_from("Cancun")
305305
def test_invalid_precompile_calls(
306-
blockchain_test: BlockchainTestFiller,
306+
state_test: StateTestFiller,
307307
pre: Dict,
308308
tx: Transaction,
309309
post: Dict,
@@ -317,10 +317,11 @@ def test_invalid_precompile_calls(
317317
- Zero inputs
318318
- Correct proof, commitment, z and y, but incorrect version versioned hash
319319
"""
320-
blockchain_test(
320+
state_test(
321+
env=Environment(),
321322
pre=pre,
322323
post=post,
323-
blocks=[Block(txs=[tx])],
324+
tx=tx,
324325
)
325326

326327

@@ -417,10 +418,10 @@ def all_external_vectors() -> List:
417418
"z,y,kzg_commitment,kzg_proof,success",
418419
all_external_vectors(),
419420
)
420-
@pytest.mark.parametrize("versioned_hash", [auto])
421+
@pytest.mark.parametrize("versioned_hash", [None])
421422
@pytest.mark.valid_from("Cancun")
422423
def test_point_evaluation_precompile_external_vectors(
423-
blockchain_test: BlockchainTestFiller,
424+
state_test: StateTestFiller,
424425
pre: Dict,
425426
tx: Transaction,
426427
post: Dict,
@@ -431,10 +432,11 @@ def test_point_evaluation_precompile_external_vectors(
431432
- `go_kzg_4844_verify_kzg_proof.json`: test vectors from the
432433
[go-kzg-4844](https://github.com/crate-crypto/go-kzg-4844) repository.
433434
"""
434-
blockchain_test(
435+
state_test(
436+
env=Environment(),
435437
pre=pre,
436438
post=post,
437-
blocks=[Block(txs=[tx])],
439+
tx=tx,
438440
)
439441

440442

@@ -458,12 +460,12 @@ def test_point_evaluation_precompile_external_vectors(
458460
)
459461
@pytest.mark.parametrize(
460462
"z,kzg_commitment,kzg_proof,versioned_hash",
461-
[[Z, INF_POINT, INF_POINT, auto]],
463+
[[Z, INF_POINT, INF_POINT, None]],
462464
ids=[""],
463465
)
464466
@pytest.mark.valid_from("Cancun")
465467
def test_point_evaluation_precompile_calls(
466-
blockchain_test: BlockchainTestFiller,
468+
state_test: StateTestFiller,
467469
pre: Dict,
468470
tx: Transaction,
469471
post: Dict,
@@ -476,10 +478,11 @@ def test_point_evaluation_precompile_calls(
476478
- Using correct and incorrect proofs
477479
- Using barely insufficient gas
478480
"""
479-
blockchain_test(
481+
state_test(
482+
env=Environment(),
480483
pre=pre,
481484
post=post,
482-
blocks=[Block(txs=[tx])],
485+
tx=tx,
483486
)
484487

485488

@@ -495,14 +498,14 @@ def test_point_evaluation_precompile_calls(
495498
@pytest.mark.parametrize(
496499
"z,y,kzg_commitment,kzg_proof,versioned_hash,proof_correct",
497500
[
498-
[Z, 0, INF_POINT, INF_POINT, auto, True],
499-
[Z, 1, INF_POINT, INF_POINT, auto, False],
501+
[Z, 0, INF_POINT, INF_POINT, None, True],
502+
[Z, 1, INF_POINT, INF_POINT, None, False],
500503
],
501504
ids=["correct_proof", "incorrect_proof"],
502505
)
503506
@pytest.mark.valid_from("Cancun")
504507
def test_point_evaluation_precompile_gas_tx_to(
505-
blockchain_test: BlockchainTestFiller,
508+
state_test: StateTestFiller,
506509
precompile_input: bytes,
507510
call_gas: int,
508511
proof_correct: bool,
@@ -554,20 +557,80 @@ def test_point_evaluation_precompile_gas_tx_to(
554557
)
555558
}
556559

557-
blockchain_test(
560+
state_test(
561+
env=Environment(),
558562
pre=pre,
559563
post=post,
560-
blocks=[Block(txs=[tx])],
564+
tx=tx,
561565
)
562566

563567

564568
@pytest.mark.parametrize(
565569
"z,y,kzg_commitment,kzg_proof,versioned_hash",
566-
[[Z, 0, INF_POINT, INF_POINT, auto]],
570+
[[Z, 0, INF_POINT, INF_POINT, None]],
567571
ids=["correct_proof"],
568572
)
569573
@pytest.mark.valid_at_transition_to("Cancun")
570574
def test_point_evaluation_precompile_before_fork(
575+
state_test: StateTestFiller,
576+
pre: Dict,
577+
tx: Transaction,
578+
):
579+
"""
580+
Test calling the Point Evaluation Precompile before the appropriate fork.
581+
"""
582+
precompile_caller_code = Op.SSTORE(
583+
Op.NUMBER,
584+
Op.CALL(
585+
Op.GAS,
586+
Spec.POINT_EVALUATION_PRECOMPILE_ADDRESS,
587+
1, # Value
588+
0, # Zero-length calldata
589+
0,
590+
0, # Zero-length return
591+
0,
592+
),
593+
)
594+
precompile_caller_address = to_address(0x100)
595+
596+
pre = {
597+
TestAddress: Account(
598+
nonce=0,
599+
balance=0x10**18,
600+
),
601+
precompile_caller_address: Account(
602+
nonce=0,
603+
code=precompile_caller_code,
604+
balance=0x10**18,
605+
),
606+
}
607+
608+
post = {
609+
precompile_caller_address: Account(
610+
storage={1: 1},
611+
# The call succeeds because precompile is not there yet
612+
),
613+
to_address(Spec.POINT_EVALUATION_PRECOMPILE_ADDRESS): Account(
614+
balance=1,
615+
),
616+
}
617+
618+
state_test(
619+
tag="point_evaluation_precompile_before_fork",
620+
pre=pre,
621+
env=Environment(timestamp=7_500),
622+
post=post,
623+
tx=tx,
624+
)
625+
626+
627+
@pytest.mark.parametrize(
628+
"z,y,kzg_commitment,kzg_proof,versioned_hash",
629+
[[Z, 0, INF_POINT, INF_POINT, None]],
630+
ids=["correct_proof"],
631+
)
632+
@pytest.mark.valid_at_transition_to("Cancun")
633+
def test_point_evaluation_precompile_during_fork(
571634
blockchain_test: BlockchainTestFiller,
572635
pre: Dict,
573636
tx: Transaction,
@@ -620,7 +683,7 @@ def tx_generator() -> Iterator[Transaction]:
620683
post = {
621684
precompile_caller_address: Account(
622685
storage={b: 1 for b in range(1, len(PRE_FORK_BLOCK_RANGE) + 1)},
623-
# The tx in last block succeeds; storage 0 by default.
686+
# Only the call in the last block's tx fails; storage 0 by default.
624687
),
625688
to_address(Spec.POINT_EVALUATION_PRECOMPILE_ADDRESS): Account(
626689
balance=len(PRE_FORK_BLOCK_RANGE),

tests/cancun/eip4844_blobs/test_point_evaluation_precompile_gas.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
from ethereum_test_tools import (
1212
Account,
13-
Block,
14-
BlockchainTestFiller,
1513
CodeGasMeasure,
14+
Environment,
15+
StateTestFiller,
1616
TestAddress,
1717
Transaction,
1818
copy_opcode_cost,
@@ -213,7 +213,7 @@ def post(
213213
@pytest.mark.parametrize("proof", ["correct", "incorrect"])
214214
@pytest.mark.valid_from("Cancun")
215215
def test_point_evaluation_precompile_gas_usage(
216-
blockchain_test: BlockchainTestFiller,
216+
state_test: StateTestFiller,
217217
pre: Dict,
218218
tx: Transaction,
219219
post: Dict,
@@ -225,8 +225,9 @@ def test_point_evaluation_precompile_gas_usage(
225225
- Test using different gas limits (exact gas, insufficient gas, extra gas)
226226
- Test using correct and incorrect proofs
227227
"""
228-
blockchain_test(
228+
state_test(
229+
env=Environment(),
229230
pre=pre,
230231
post=post,
231-
blocks=[Block(txs=[tx])],
232+
tx=tx,
232233
)

0 commit comments

Comments
 (0)