Skip to content

Commit

Permalink
new(tests): add tests for EOF container prefix
Browse files Browse the repository at this point in the history
Also remove similar "manual" tests in container.py.
  • Loading branch information
chfast committed Jun 11, 2024
1 parent 2321199 commit a4dd890
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 33 deletions.
31 changes: 0 additions & 31 deletions tests/prague/eip7692_eof_v1/eip3540_eof_v1/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from typing import List

from ethereum_test_tools.eof import LATEST_EOF_VERSION
from ethereum_test_tools.eof.v1 import VERSION_MAX_SECTION_KIND, AutoSection, Container, Section
from ethereum_test_tools.eof.v1 import SectionKind as Kind
from ethereum_test_tools.eof.v1.constants import (
Expand Down Expand Up @@ -184,36 +183,6 @@
auto_type_section=AutoSection.NONE,
validity_error=EOFException.MISSING_TYPE_HEADER,
),
Container(
name="invalid_magic_01",
magic=b"\xef\x01",
sections=[Section.Code(Op.STOP)],
validity_error=EOFException.INVALID_MAGIC,
),
Container(
name="invalid_magic_ff",
magic=b"\xef\xFF",
sections=[Section.Code(Op.STOP)],
validity_error=EOFException.INVALID_MAGIC,
),
Container(
name="invalid_version_zero",
version=b"\x00",
sections=[Section.Code(Op.STOP)],
validity_error=EOFException.INVALID_VERSION,
),
Container(
name="invalid_version_plus_one",
version=int.to_bytes(LATEST_EOF_VERSION + 1, length=1, byteorder="big"),
sections=[Section.Code(Op.STOP)],
validity_error=EOFException.INVALID_VERSION,
),
Container(
name="invalid_version_high",
version=b"\xFF",
sections=[Section.Code(Op.STOP)],
validity_error=EOFException.INVALID_VERSION,
),
Container(
name="no_code_section",
sections=[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""
EOF validation tests for EIP-3540 container format
"""

import pytest

from ethereum_test_tools import EOFTestFiller
from ethereum_test_tools import Opcodes as Op
from ethereum_test_tools.eof.v1 import Container, EOFException, Section

from .. import EOF_FORK_NAME

REFERENCE_SPEC_GIT_PATH = "EIPS/eip-3540.md"
REFERENCE_SPEC_VERSION = "8dcb0a8c1c0102c87224308028632cc986a61183"

pytestmark = pytest.mark.valid_from(EOF_FORK_NAME)

VALID_CONTAINER = Container(sections=[Section.Code(code=Op.STOP)])


@pytest.mark.parametrize("magic_0", [0, 1, 0xEE, 0xEF, 0xF0, 0xFF])
@pytest.mark.parametrize("magic_1", [0, 1, 2, 0xFE, 0xFF])
def test_magic_validation(
eof_test: EOFTestFiller,
magic_0: int,
magic_1: int,
):
"""
Verify EOF container 2-byte magic
"""
code = bytearray(bytes(VALID_CONTAINER))
code[0] = magic_0
code[1] = magic_1
eof_test(
data=bytes(code),
expect_exception=None if magic_0 == 0xEF and magic_1 == 0 else EOFException.INVALID_MAGIC,
)


@pytest.mark.parametrize("version", [0, 1, 2, 0xFE, 0xFF])
def test_version_validation(
eof_test: EOFTestFiller,
version: int,
):
"""
Verify EOF container version
"""
code = bytearray(bytes(VALID_CONTAINER))
code[2] = version
eof_test(
data=bytes(code),
expect_exception=None if version == 1 else EOFException.INVALID_VERSION,
)
4 changes: 2 additions & 2 deletions tests/prague/eip7692_eof_v1/tracker.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
- [ ] Valid containers with max number of code sections (ethereum/tests: src/EOFTestsFiller/efValidation/many_code_sections_1024_Copier.json)
- [ ] 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)
- [ ] Truncated magic (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
- [ ] Valid container except magic (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_prefix_Copier.json)
- [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)
- [ ] Truncated before version (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
- [ ] Valid container except version (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/validate_EOF_version_Copier.json)
- [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)
- [ ] Truncated before type section header (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml)
- [ ] Truncated before type section size (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/EOF1_incomplete_section_size_Copier.json)
- [ ] Truncated type section size (ethereum/tests: ./src/EOFTestsFiller/EIP3540/validInvalidFiller.yml src/EOFTestsFiller/efValidation/EOF1_incomplete_section_size_Copier.json)
Expand Down

0 comments on commit a4dd890

Please sign in to comment.