Skip to content

Commit

Permalink
Close the catalogue of potential exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Sep 27, 2024
1 parent 2cfa4df commit e904236
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
17 changes: 14 additions & 3 deletions src/ethereum_test_specs/eof.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,23 @@ def make_eof_test_fixture(
if self.no_expectations_on_validity:
parser = EvmoneExceptionMapper()
actual_message = result.stdout.strip()
actual_exception = parser.message_to_exception(actual_message)
if "OK" in actual_message:
expected_result.valid = True
else:
expected_result.exception = None
elif not self.expect_exception:
raise Exception(
f"no_expectations_on_validity should come with a catalogue of expected exceptions"
)
elif actual_exception in self.expect_exception:
expected_result.valid = False
actual_exception = parser.message_to_exception(actual_message)
expected_result.exception = actual_exception
expected_result.exception = self.expect_exception
else:
raise EOFExceptionMismatch(
code=vector.code,
expected=f"{to_pipe_str(expected_result.exception)}",
got=f"{actual_exception} ({actual_message})",
)
else:
self.verify_result(result, expected_result, vector.code)

Expand Down
27 changes: 18 additions & 9 deletions tests/prague/eip7692_eof_v1/eip5450_stack/test_code_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from ethereum_test_exceptions.exceptions import EOFException
from ethereum_test_tools import EOFTestFiller
from ethereum_test_tools.eof.v1 import Container, Section
from ethereum_test_tools.vm.opcode import Opcodes as Op
Expand Down Expand Up @@ -245,15 +246,23 @@ def test_eof_validity(
)
else:
sections.append(Section.Code(code))

# Some RJUMP* snippets always validate successfully, so they act as sanity check
always_valid = rjump_kind in [
RjumpKind.EMPTY_RJUMP,
RjumpKind.EMPTY_RJUMPI,
RjumpKind.RJUMPI_OVER_NOOP,
RjumpKind.RJUMPI_OVER_STOP,
RjumpKind.RJUMPI_OVER_PUSH_POP,
]
possible_exceptions = [
EOFException.STACK_HEIGHT_MISMATCH,
EOFException.STACK_HIGHER_THAN_OUTPUTS,
EOFException.STACK_UNDERFLOW,
]

eof_test(
data=bytes(Container(sections=sections)),
# Some RJUMP* snippets always validate successfully, so they act as sanity check
no_expectations_on_validity=rjump_kind
not in [
RjumpKind.EMPTY_RJUMP,
RjumpKind.EMPTY_RJUMPI,
RjumpKind.RJUMPI_OVER_NOOP,
RjumpKind.RJUMPI_OVER_STOP,
RjumpKind.RJUMPI_OVER_PUSH_POP,
],
no_expectations_on_validity=not always_valid,
expect_exception=possible_exceptions if not always_valid else None,
)

0 comments on commit e904236

Please sign in to comment.