Skip to content

Commit a4dd890

Browse files
committed
new(tests): add tests for EOF container prefix
Also remove similar "manual" tests in container.py.
1 parent 2321199 commit a4dd890

File tree

3 files changed

+55
-33
lines changed

3 files changed

+55
-33
lines changed

tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from typing import List
66

7-
from ethereum_test_tools.eof import LATEST_EOF_VERSION
87
from ethereum_test_tools.eof.v1 import VERSION_MAX_SECTION_KIND, AutoSection, Container, Section
98
from ethereum_test_tools.eof.v1 import SectionKind as Kind
109
from ethereum_test_tools.eof.v1.constants import (
@@ -184,36 +183,6 @@
184183
auto_type_section=AutoSection.NONE,
185184
validity_error=EOFException.MISSING_TYPE_HEADER,
186185
),
187-
Container(
188-
name="invalid_magic_01",
189-
magic=b"\xef\x01",
190-
sections=[Section.Code(Op.STOP)],
191-
validity_error=EOFException.INVALID_MAGIC,
192-
),
193-
Container(
194-
name="invalid_magic_ff",
195-
magic=b"\xef\xFF",
196-
sections=[Section.Code(Op.STOP)],
197-
validity_error=EOFException.INVALID_MAGIC,
198-
),
199-
Container(
200-
name="invalid_version_zero",
201-
version=b"\x00",
202-
sections=[Section.Code(Op.STOP)],
203-
validity_error=EOFException.INVALID_VERSION,
204-
),
205-
Container(
206-
name="invalid_version_plus_one",
207-
version=int.to_bytes(LATEST_EOF_VERSION + 1, length=1, byteorder="big"),
208-
sections=[Section.Code(Op.STOP)],
209-
validity_error=EOFException.INVALID_VERSION,
210-
),
211-
Container(
212-
name="invalid_version_high",
213-
version=b"\xFF",
214-
sections=[Section.Code(Op.STOP)],
215-
validity_error=EOFException.INVALID_VERSION,
216-
),
217186
Container(
218187
name="no_code_section",
219188
sections=[
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""
2+
EOF validation tests for EIP-3540 container format
3+
"""
4+
5+
import pytest
6+
7+
from ethereum_test_tools import EOFTestFiller
8+
from ethereum_test_tools import Opcodes as Op
9+
from ethereum_test_tools.eof.v1 import Container, EOFException, Section
10+
11+
from .. import EOF_FORK_NAME
12+
13+
REFERENCE_SPEC_GIT_PATH = "EIPS/eip-3540.md"
14+
REFERENCE_SPEC_VERSION = "8dcb0a8c1c0102c87224308028632cc986a61183"
15+
16+
pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)
17+
18+
VALID_CONTAINER = Container(sections=[Section.Code(code=Op.STOP)])
19+
20+
21+
@pytest.mark.parametrize("magic_0", [0, 1, 0xEE, 0xEF, 0xF0, 0xFF])
22+
@pytest.mark.parametrize("magic_1", [0, 1, 2, 0xFE, 0xFF])
23+
def test_magic_validation(
24+
eof_test: EOFTestFiller,
25+
magic_0: int,
26+
magic_1: int,
27+
):
28+
"""
29+
Verify EOF container 2-byte magic
30+
"""
31+
code = bytearray(bytes(VALID_CONTAINER))
32+
code[0] = magic_0
33+
code[1] = magic_1
34+
eof_test(
35+
data=bytes(code),
36+
expect_exception=None if magic_0 == 0xEF and magic_1 == 0 else EOFException.INVALID_MAGIC,
37+
)
38+
39+
40+
@pytest.mark.parametrize("version", [0, 1, 2, 0xFE, 0xFF])
41+
def test_version_validation(
42+
eof_test: EOFTestFiller,
43+
version: int,
44+
):
45+
"""
46+
Verify EOF container version
47+
"""
48+
code = bytearray(bytes(VALID_CONTAINER))
49+
code[2] = version
50+
eof_test(
51+
data=bytes(code),
52+
expect_exception=None if version == 1 else EOFException.INVALID_VERSION,
53+
)

tests/prague/eip7692_eof_v1/tracker.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
- [ ] Valid containers with max number of code sections (ethereum/tests: src/EOFTestsFiller/efValidation/many_code_sections_1024_Copier.json)
1818
- [ ] Too many code sections (ethereum/tests: ./src/EOFTestsFiller/efValidation/EOF1_too_many_code_sections_Copier.json src/EOFTestsFiller/efValidation/too_many_code_sections_Copier.json)
1919
- [ ] Truncated magic (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
20-
- [ ] Valid container except magic (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_prefix_Copier.json)
20+
- [x] Valid container except magic (./eip3540_eof_v1/test_container_validation.py::test_magic_validation ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_prefix_Copier.json)
2121
- [ ] Truncated before version (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
22-
- [ ] Valid container except version (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_version_Copier.json)
22+
- [x] Valid container except version (./eip3540_eof_v1/test_container_validation.py::test_version_validation ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_version_Copier.json)
2323
- [ ] Truncated before type section header (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
2424
- [ ] Truncated before type section size (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/EOF1_incomplete_section_size_Copier.json)
2525
- [ ] Truncated type section size (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/EOF1_incomplete_section_size_Copier.json)

0 commit comments

Comments
 (0)