From 29d124cd1cdc6b9068298d5e16862dedc91d526d Mon Sep 17 00:00:00 2001 From: Danno Ferrin Date: Thu, 22 Aug 2024 08:49:28 -0600 Subject: [PATCH] feat(tests) Add "multiple exceptions" eof exception 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 --- src/ethereum_test_exceptions/exceptions.py | 7 ++++--- src/ethereum_test_specs/eof.py | 9 ++++++++- .../eip3540_eof_v1/test_example_valid_invalid.py | 8 ++++---- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ethereum_test_exceptions/exceptions.py b/src/ethereum_test_exceptions/exceptions.py index a4195b7783..4984c0fe55 100644 --- a/src/ethereum_test_exceptions/exceptions.py +++ b/src/ethereum_test_exceptions/exceptions.py @@ -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. diff --git a/src/ethereum_test_specs/eof.py b/src/ethereum_test_specs/eof.py index 835cb02053..4753ff674f 100644 --- a/src/ethereum_test_specs/eof.py +++ b/src/ethereum_test_specs/eof.py @@ -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})", diff --git a/tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py b/tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py index e90e386ef2..5ebe46f579 100644 --- a/tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py +++ b/tests/prague/eip7692_eof_v1/eip3540_eof_v1/test_example_valid_invalid.py @@ -272,7 +272,7 @@ 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 @@ -280,7 +280,7 @@ 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 "ef000101000802000100030400040000800001000000003050003050000bad60A7", - EOFException.INVALID_TYPE_SECTION_SIZE, + EOFException.MULTIPLE_EXCEPTIONS, ), ( False, # second section is mentioned in code header array (0003) @@ -288,7 +288,7 @@ 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 "ef0001010008020002000300030400040000800001000000003050000bad60A7", - EOFException.UNREACHABLE_CODE_SECTIONS, + EOFException.MULTIPLE_EXCEPTIONS, ), ( False, # second section is mentioned in code header array (0003) @@ -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