Skip to content

Commit 0cb595c

Browse files
authored
new(tests): Aggregate EOF tests for invalid first section type (#1377)
Move some basic tests for invalid first section type to the parametrized tests of EIP-6206. Extend the test coverage by using more exhaustive combination of params.
1 parent 49b038e commit 0cb595c

File tree

2 files changed

+45
-64
lines changed

2 files changed

+45
-64
lines changed

tests/osaka/eip7692_eof_v1/eip3540_eof_v1/test_container_validation.py

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -414,24 +414,6 @@ def test_valid_containers(
414414
raw_bytes="ef0001010008020003000100010001040000000080000000800000fefefe",
415415
validity_error=EOFException.INVALID_TYPE_SECTION_SIZE,
416416
),
417-
Container(
418-
# EOF code containing invalid first section type (1,0)
419-
name="EOF1I4750_0006",
420-
raw_bytes="ef000101000402000100010400000001000000fe",
421-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
422-
),
423-
Container(
424-
# EOF code containing invalid first section type (0,1)
425-
name="EOF1I4750_0007",
426-
raw_bytes="ef000101000402000100010400000000010000fe",
427-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
428-
),
429-
Container(
430-
# EOF code containing invalid first section type (2,3)
431-
name="EOF1I4750_0008",
432-
raw_bytes="ef000101000402000100010400000002030000fe",
433-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
434-
),
435417
Container(
436418
name="no_sections",
437419
sections=[],
@@ -1039,41 +1021,6 @@ def test_valid_containers(
10391021
auto_type_section=AutoSection.NONE,
10401022
validity_error=EOFException.INVALID_TYPE_SECTION_SIZE,
10411023
),
1042-
Container(
1043-
name="invalid_first_code_section_inputs_0x01",
1044-
sections=[Section.Code(code=Op.POP + Op.RETF, code_inputs=1)],
1045-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1046-
),
1047-
Container(
1048-
name="invalid_first_code_section_inputs_0x80",
1049-
sections=[Section.Code(code=Op.POP + Op.RETF, code_inputs=0x80)],
1050-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1051-
),
1052-
Container(
1053-
name="invalid_first_code_section_inputs_0xff",
1054-
sections=[Section.Code(code=Op.POP + Op.RETF, code_inputs=0xFF)],
1055-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1056-
),
1057-
Container(
1058-
name="invalid_first_code_section_outputs_0x00",
1059-
sections=[Section.Code(code=Op.PUSH0 + Op.RETF, code_outputs=0)],
1060-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1061-
),
1062-
Container(
1063-
name="invalid_first_code_section_outputs_0x7f",
1064-
sections=[Section.Code(code=Op.PUSH0 + Op.RETF, code_outputs=0x7F)],
1065-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1066-
),
1067-
Container(
1068-
name="invalid_first_code_section_outputs_0x81",
1069-
sections=[Section.Code(code=Op.PUSH0 + Op.RETF, code_outputs=0x81)],
1070-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1071-
),
1072-
Container(
1073-
name="invalid_first_code_section_outputs_0xff",
1074-
sections=[Section.Code(code=Op.PUSH0 + Op.RETF, code_outputs=0xFF)],
1075-
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
1076-
),
10771024
Container(
10781025
name="multiple_code_section_non_zero_inputs",
10791026
sections=[

tests/osaka/eip7692_eof_v1/eip6206_jumpf/test_nonreturning_validation.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,57 @@
1717

1818

1919
@pytest.mark.parametrize(
20-
"code_section",
20+
"code",
2121
[
22-
pytest.param(Section.Code(Op.STOP, code_outputs=0), id="stop"),
23-
pytest.param(Section.Code(Op.INVALID, code_outputs=0), id="invalid0"),
24-
pytest.param(
25-
Section.Code(Op.ADDRESS + Op.POP + Op.INVALID, code_outputs=0), id="invalid1"
26-
),
27-
pytest.param(Section.Code(Op.RETURN(0, 0), code_outputs=0), id="return"),
28-
pytest.param(Section.Code(Op.RETF, code_outputs=0), id="retf0"),
29-
pytest.param(Section.Code(Op.PUSH0 + Op.RETF, code_outputs=1), id="retf1"),
22+
pytest.param(Op.STOP, id="STOP"),
23+
pytest.param(Op.INVALID, id="INVALID"),
24+
pytest.param(Op.ADDRESS + Op.POP + Op.INVALID, id="ADDRESS_POP_INVALID"),
25+
pytest.param(Op.RETURN(0, 0), id="RETURN"),
26+
pytest.param(Op.RETF, id="RETF"),
27+
pytest.param(Op.PUSH0 + Op.RETF, id="PUSH0_RETF"),
3028
],
3129
)
32-
def test_first_section_returning(eof_test: EOFTestFiller, code_section: Section):
30+
@pytest.mark.parametrize(
31+
"outputs",
32+
[0, 1, 0x7F, 0x81, 0xFF],
33+
)
34+
def test_first_section_returning(eof_test: EOFTestFiller, code: Bytecode, outputs: int):
3335
"""Test EOF validation failing because the first section is not non-returning."""
3436
eof_test(
3537
container=Container(
36-
sections=[code_section], validity_error=EOFException.INVALID_FIRST_SECTION_TYPE
38+
sections=[Section.Code(code, code_outputs=outputs)],
39+
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
40+
)
41+
)
42+
43+
44+
@pytest.mark.parametrize(
45+
"code",
46+
[
47+
pytest.param(Op.INVALID, id="INVALID"),
48+
pytest.param(Op.RETF, id="RETF"),
49+
pytest.param(Op.POP + Op.RETF, id="POP_RETF"),
50+
],
51+
)
52+
@pytest.mark.parametrize(
53+
"inputs",
54+
[1, 2, 0x7F, 0x80, 0x81, 0xFF],
55+
)
56+
@pytest.mark.parametrize(
57+
"outputs",
58+
[
59+
0,
60+
NON_RETURNING_SECTION,
61+
],
62+
)
63+
def test_first_section_with_inputs(
64+
eof_test: EOFTestFiller, code: Bytecode, inputs: int, outputs: int
65+
):
66+
"""Test EOF validation failing because the first section has non-zero number of inputs."""
67+
eof_test(
68+
container=Container(
69+
sections=[Section.Code(code, code_inputs=inputs, code_outputs=outputs)],
70+
validity_error=EOFException.INVALID_FIRST_SECTION_TYPE,
3771
)
3872
)
3973

0 commit comments

Comments
 (0)