Skip to content

Commit d22bdf1

Browse files
committed
feat(pytest,tests): tests added by fork introduced.
1 parent bf3eb32 commit d22bdf1

File tree

10 files changed

+45
-16
lines changed

10 files changed

+45
-16
lines changed

Diff for: docs/writing_tests/adding_a_new_test.md

+14-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ All test cases are located underneath the `tests` directory, which are then orga
1414
| | ├── 📄 test_excess_blob_gas.py
1515
| | └── 📄 ...
1616
| ├── 📁 shanghai
17+
| | ├── 📄 __init__.py
1718
| | ├── 📁 eip3651_warm_coinbase
1819
| | | ├── 📄 __init__.py
1920
| | | └── 📄 test_warm_coinbase.py
@@ -22,13 +23,25 @@ All test cases are located underneath the `tests` directory, which are then orga
2223
| | | └── 📄 test_push0.py
2324
| | ├── 📁...
2425
| | ...
26+
| ├── 📁 frontier
27+
| | ├── 📄 __init__.py
28+
| | ├── 📁 opcodes
29+
| | | ├── 📄 __init__.py
30+
| | | └── 📄 test_dup.py
31+
| | | └── 📄 test_call.py
32+
| | | └── 📄 ...
33+
| | ├── 📁...
2534
│ └── 📁 ...
2635
```
2736

28-
Each category/sub-directory may have multiple Python test modules (`*.py`) which in turn may contain many test functions. The test functions themselves are always parametrized by fork (by the framework).
37+
Each fork/sub-directory may have multiple Python test modules (`*.py`) which in turn may contain many test functions. The test functions themselves are always parametrized by fork (by the framework). In general, sub-directories can be feature categories such as opcodes or eips.
2938

3039
A new test can be added by either:
3140

3241
- Adding a new `test_` python function to an existing file in any of the existing category subdirectories within `tests`.
3342
- Creating a new source file in an existing category, and populating it with the new test function(s).
3443
- Creating an entirely new category by adding a subdirectory in `tests` with the appropriate source files and test functions.
44+
45+
!!! note "Which fork does my test belong?"
46+
Tests should be added to the fork folder where the feature or EIP was introduced. For example, if the callcode opcode is being tested it should be added to the
47+
Frontier fork folder as this opcode was first introduced in Frontier. This remains true for cases where the test is [valid from](../writing_a_new_test/#specifying-which-forks-tests-are-valid-for) a later fork, such as a callcode specific bug introduced in London.

Diff for: src/pytest_plugins/forks/forks.py

+17-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,19 @@
1010
import pytest
1111
from pytest import Metafunc
1212

13-
from ethereum_test_forks import (
13+
from ethereum_test_forks import ( # noqa: F401
14+
Berlin,
15+
Byzantium,
16+
Cancun,
17+
Constantinople,
1418
Fork,
1519
ForkAttribute,
20+
Frontier,
21+
Homestead,
22+
Istanbul,
23+
London,
24+
Paris,
25+
Shanghai,
1626
forks_from_until,
1727
get_deployed_forks,
1828
get_forks,
@@ -345,6 +355,12 @@ def get_validity_marker_args(
345355
f"'{validity_marker_name}'. "
346356
f"List of valid forks: {', '.join(metafunc.config.fork_names)}" # type: ignore
347357
)
358+
fork_folder = metafunc.module.__name__.split(".")[1].capitalize()
359+
if globals()[fork_name] < globals()[fork_folder]:
360+
pytest.fail(
361+
f"Incorrect usage of '{validity_marker_name}'. The validity marker fork "
362+
f"'{fork_name}' must be greater than or equal to the test folder fork '{fork_folder}'."
363+
)
348364

349365
return fork_name
350366

Diff for: tests/cancun/eip6780_selfdestruct/test_dynamic_create2_selfdestruct_collision.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def env(): # noqa: D103
3939
)
4040

4141

42-
@pytest.mark.valid_from("Paris")
42+
@pytest.mark.valid_from("Cancun")
4343
@pytest.mark.parametrize(
4444
"create2_dest_already_in_state",
4545
(True, False),
@@ -230,7 +230,7 @@ def test_dynamic_create2_selfdestruct_collision(
230230
state_test(env=env, pre=pre, post=post, tx=tx)
231231

232232

233-
@pytest.mark.valid_from("Paris")
233+
@pytest.mark.valid_from("Cancun")
234234
@pytest.mark.parametrize(
235235
"selfdestruct_on_first_tx,recreate_on_first_tx",
236236
[

Diff for: tests/cancun/eip6780_selfdestruct/test_reentrancy_selfdestruct_revert.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def env(): # noqa: D103
3232
)
3333

3434

35-
@pytest.mark.valid_from("Paris")
35+
@pytest.mark.valid_from("Cancun")
3636
@pytest.mark.parametrize("first_suicide", [Op.CALL, Op.CALLCODE, Op.DELEGATECALL])
3737
@pytest.mark.parametrize("second_suicide", [Op.CALL, Op.CALLCODE, Op.DELEGATECALL])
3838
def test_reentrancy_selfdestruct_revert(

Diff for: tests/cancun/eip6780_selfdestruct/test_selfdestruct.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def pre(
263263
],
264264
)
265265
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 100_000])
266-
@pytest.mark.valid_from("Shanghai")
266+
@pytest.mark.valid_from("Cancun")
267267
def test_create_selfdestruct_same_tx(
268268
state_test: StateTestFiller,
269269
env: Environment,
@@ -418,7 +418,7 @@ def test_create_selfdestruct_same_tx(
418418
@pytest.mark.parametrize("call_times", [0, 1])
419419
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 100_000])
420420
@pytest.mark.parametrize("self_destructing_initcode", [True], ids=[""])
421-
@pytest.mark.valid_from("Shanghai")
421+
@pytest.mark.valid_from("Cancun")
422422
def test_self_destructing_initcode(
423423
state_test: StateTestFiller,
424424
env: Environment,
@@ -546,7 +546,7 @@ def test_self_destructing_initcode(
546546
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 100_000])
547547
@pytest.mark.parametrize("selfdestruct_contract_address", [compute_create_address(TestAddress, 0)])
548548
@pytest.mark.parametrize("self_destructing_initcode", [True], ids=[""])
549-
@pytest.mark.valid_from("Shanghai")
549+
@pytest.mark.valid_from("Cancun")
550550
def test_self_destructing_initcode_create_tx(
551551
state_test: StateTestFiller,
552552
env: Environment,
@@ -614,7 +614,7 @@ def test_self_destructing_initcode_create_tx(
614614
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 100_000])
615615
@pytest.mark.parametrize("recreate_times", [1])
616616
@pytest.mark.parametrize("call_times", [1])
617-
@pytest.mark.valid_from("Shanghai")
617+
@pytest.mark.valid_from("Cancun")
618618
def test_recreate_self_destructed_contract_different_txs(
619619
blockchain_test: BlockchainTestFiller,
620620
env: Environment,
@@ -753,7 +753,7 @@ def test_recreate_self_destructed_contract_different_txs(
753753
@pytest.mark.parametrize(
754754
"selfdestruct_contract_address", [PRE_EXISTING_SELFDESTRUCT_ADDRESS], ids=["pre_existing"]
755755
)
756-
@pytest.mark.valid_from("Shanghai")
756+
@pytest.mark.valid_from("Cancun")
757757
def test_selfdestruct_pre_existing(
758758
state_test: StateTestFiller,
759759
eip_enabled: bool,
@@ -880,7 +880,7 @@ def test_selfdestruct_pre_existing(
880880
"selfdestruct_contract_address,entry_code_address",
881881
[(compute_create_address(TestAddress, 0), compute_create_address(TestAddress, 1))],
882882
)
883-
@pytest.mark.valid_from("Shanghai")
883+
@pytest.mark.valid_from("Cancun")
884884
def test_selfdestruct_created_same_block_different_tx(
885885
blockchain_test: BlockchainTestFiller,
886886
eip_enabled: bool,
@@ -1018,7 +1018,7 @@ def test_selfdestruct_created_same_block_different_tx(
10181018
@pytest.mark.parametrize("call_times", [1])
10191019
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 1])
10201020
@pytest.mark.parametrize("create_opcode", [Op.CREATE])
1021-
@pytest.mark.valid_from("Shanghai")
1021+
@pytest.mark.valid_from("Cancun")
10221022
def test_delegatecall_from_new_contract_to_pre_existing_contract(
10231023
state_test: StateTestFiller,
10241024
env: Environment,
@@ -1154,7 +1154,7 @@ def test_delegatecall_from_new_contract_to_pre_existing_contract(
11541154
@pytest.mark.parametrize("call_opcode", [Op.DELEGATECALL, Op.CALLCODE])
11551155
@pytest.mark.parametrize("call_times", [1])
11561156
@pytest.mark.parametrize("selfdestruct_contract_initial_balance", [0, 1])
1157-
@pytest.mark.valid_from("Shanghai")
1157+
@pytest.mark.valid_from("Cancun")
11581158
def test_delegatecall_from_pre_existing_contract_to_new_contract(
11591159
state_test: StateTestFiller,
11601160
eip_enabled: bool,
File renamed without changes.

Diff for: tests/homestead/yul/test_yul_example.py renamed to tests/frontier/yul/test_yul_example.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
)
1616

1717

18-
@pytest.mark.valid_from("Homestead")
18+
@pytest.mark.valid_from("Frontier")
1919
def test_yul(state_test: StateTestFiller, yul: YulCompiler, fork: Fork):
2020
"""
2121
Test YUL compiled bytecode.
File renamed without changes.

Diff for: tests/paris/security/test_selfdestruct_balance_bug.py renamed to tests/homestead/opcodes/test_selfdestruct_contract_balance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
@pytest.mark.compile_yul_with("Paris") # Shanghai refuses to compile SELFDESTRUCT
3030
@pytest.mark.valid_from("Constantinople")
31-
def test_tx_selfdestruct_balance_bug(blockchain_test: BlockchainTestFiller, yul: YulCompiler):
31+
def test_selfdestruct_contract_balance(blockchain_test: BlockchainTestFiller, yul: YulCompiler):
3232
"""
3333
Test that the vulnerability is not present by checking the balance of the
3434
`0xaa` contract after executing specific transactions:

Diff for: tests/shanghai/eip3651_warm_coinbase/test_warm_coinbase.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ def test_warm_coinbase_call_out_of_gas(
209209
]
210210

211211

212-
@pytest.mark.valid_from("Paris") # these tests fill for fork >= Berlin
212+
@pytest.mark.valid_from("Shanghai")
213213
@pytest.mark.parametrize(
214214
"opcode,code_gas_measure",
215215
gas_measured_opcodes,

0 commit comments

Comments
 (0)