Skip to content

Commit

Permalink
feat(tests) Add "multiple exceptions" eof exception
Browse files Browse the repository at this point in the history
There are some tests that are impossible to express without causing
multiple validation exceptions. Clients should be free to expose any of
those exceptions. To allow this, the MULTIPLE_EXCEPTIONS exception marks
that any exception is valid, so long as the validation fails.

Signed-off-by: Danno Ferrin <[email protected]>
  • Loading branch information
shemnon committed Aug 22, 2024
1 parent 67a2cac commit 29d124c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/ethereum_test_exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,17 +550,18 @@ class EOFException(ExceptionBase):
"""
Expect some exception, not yet known.
"""

UNDEFINED_EXCEPTION = auto()
"""
Indicates that exception string is not mapped to an exception enum.
"""

MULTIPLE_EXCEPTIONS = auto()
"""
Indicates that there are multiple errors and clients may have different exceptions
"""
UNDEFINED_INSTRUCTION = auto()
"""
EOF container has undefined instruction in it's body code.
"""

UNKNOWN_VERSION = auto()
"""
EOF container has an unknown version.
Expand Down
9 changes: 8 additions & 1 deletion src/ethereum_test_specs/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ def verify_result(self, result: CompletedProcess, expected_result: Result, code:
code=code, expected=f"{expected_exception} ({expected_message})"
)

if expected_exception != actual_exception:
if expected_exception == EOFException.MULTIPLE_EXCEPTIONS:
if actual_exception is None:
raise EOFExceptionMismatch(
code=code,
expected="Multiple possible exceptions",
got="No exception",
)
elif expected_exception != actual_exception:
raise EOFExceptionMismatch(
code=code,
expected=f"{expected_exception} ({expected_message})",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,23 +272,23 @@ def test_example_valid_invalid(
False, # but it's code input bytes still listed in container's body
False, # but it's code input bytes size still added to types section size
"ef000101000802000100030400040000800001000000003050000bad60A7",
EOFException.INVALID_TYPE_SECTION_SIZE,
EOFException.MULTIPLE_EXCEPTIONS,
),
(
True, # second section is not in code header array
False, # second section code is in container's body (3050000)
False, # but it's code input bytes still listed in container's body
False, # but it's code input bytes size still added to types section size
"ef000101000802000100030400040000800001000000003050003050000bad60A7",
EOFException.INVALID_TYPE_SECTION_SIZE,
EOFException.MULTIPLE_EXCEPTIONS,
),
(
False, # second section is mentioned in code header array (0003)
True, # second section is not in container's body (it's code bytes)
False, # but it's code input bytes still listed in container's body
False, # but it's code input bytes size still added to types section size
"ef0001010008020002000300030400040000800001000000003050000bad60A7",
EOFException.UNREACHABLE_CODE_SECTIONS,
EOFException.MULTIPLE_EXCEPTIONS,
),
(
False, # second section is mentioned in code header array (0003)
Expand All @@ -305,7 +305,7 @@ def test_example_valid_invalid(
True, # it's code input bytes are not listed in container's body (00000000)
False, # but it's code input bytes size still added to types section size
"ef0001010008020001000304000400008000013050000bad60a7",
EOFException.INVALID_TYPE_SECTION_SIZE,
EOFException.MULTIPLE_EXCEPTIONS,
),
(
True, # second section is not in code header array
Expand Down

0 comments on commit 29d124c

Please sign in to comment.