-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(fw): call
evmone-eofparse
on generated EOF fixtures in fill (#519
) Co-authored-by: Dimitry Kh <[email protected]> Co-authored-by: danceratopz <[email protected]>
- Loading branch information
1 parent
70d29ab
commit aa61d73
Showing
10 changed files
with
295 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
""" | ||
Evmone eof exceptions ENUM -> str mapper | ||
""" | ||
from dataclasses import dataclass | ||
|
||
from bidict import frozenbidict | ||
|
||
from .exceptions import EOFException | ||
|
||
|
||
@dataclass | ||
class ExceptionMessage: | ||
"""Defines a mapping between an exception and a message.""" | ||
|
||
exception: EOFException | ||
message: str | ||
|
||
|
||
class EvmoneExceptionMapper: | ||
""" | ||
Translate between EEST exceptions and error strings returned by evmone. | ||
""" | ||
|
||
_mapping_data = ( | ||
# TODO EVMONE needs to differentiate when the section is missing in the header or body | ||
ExceptionMessage(EOFException.MISSING_STOP_OPCODE, "err: no_terminating_instruction"), | ||
ExceptionMessage(EOFException.MISSING_CODE_HEADER, "err: code_section_missing"), | ||
ExceptionMessage(EOFException.MISSING_TYPE_HEADER, "err: type_section_missing"), | ||
# TODO EVMONE these exceptions are too similar, this leeds to ambiguity | ||
ExceptionMessage(EOFException.MISSING_TERMINATOR, "err: header_terminator_missing"), | ||
ExceptionMessage( | ||
EOFException.MISSING_HEADERS_TERMINATOR, "err: section_headers_not_terminated" | ||
), | ||
ExceptionMessage(EOFException.INVALID_VERSION, "err: eof_version_unknown"), | ||
ExceptionMessage(EOFException.INVALID_MAGIC, "err: invalid_prefix"), | ||
ExceptionMessage( | ||
EOFException.INVALID_FIRST_SECTION_TYPE, "err: invalid_first_section_type" | ||
), | ||
ExceptionMessage( | ||
EOFException.INVALID_SECTION_BODIES_SIZE, "err: invalid_section_bodies_size" | ||
), | ||
ExceptionMessage(EOFException.INVALID_TYPE_SIZE, "err: invalid_type_section_size"), | ||
ExceptionMessage(EOFException.INCOMPLETE_SECTION_SIZE, "err: incomplete_section_size"), | ||
ExceptionMessage(EOFException.INCOMPLETE_SECTION_NUMBER, "err: incomplete_section_number"), | ||
ExceptionMessage(EOFException.TOO_MANY_CODE_SECTIONS, "err: too_many_code_sections"), | ||
ExceptionMessage(EOFException.ZERO_SECTION_SIZE, "err: zero_section_size"), | ||
) | ||
|
||
def __init__(self) -> None: | ||
assert len(set(entry.exception for entry in self._mapping_data)) == len( | ||
self._mapping_data | ||
), "Duplicate exception in _mapping_data" | ||
assert len(set(entry.message for entry in self._mapping_data)) == len( | ||
self._mapping_data | ||
), "Duplicate message in _mapping_data" | ||
self.exception_to_message_map: frozenbidict = frozenbidict( | ||
{entry.exception: entry.message for entry in self._mapping_data} | ||
) | ||
|
||
def exception_to_message(self, exception: EOFException) -> str: | ||
"""Takes an EOFException and returns a formatted string.""" | ||
message = self.exception_to_message_map.get( | ||
exception, | ||
f"No message defined for {exception}; please add it to {self.__class__.__name__}", | ||
) | ||
return message | ||
|
||
def message_to_exception(self, exception_string: str) -> EOFException: | ||
"""Takes a string and tries to find matching exception""" | ||
# TODO inform tester where to add the missing exception if get uses default | ||
exception = self.exception_to_message_map.inverse.get( | ||
exception_string, EOFException.UNDEFINED_EXCEPTION | ||
) | ||
return exception |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.