Skip to content

Commit db0b38b

Browse files
committed
refactor exception mapper
parse expected exception lists
1 parent e5b5571 commit db0b38b

File tree

14 files changed

+550
-342
lines changed

14 files changed

+550
-342
lines changed

src/ethereum_test_exceptions/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
"""
44

55
from .engine_api import EngineAPIError
6-
from .evmone_exceptions import EvmoneExceptionMapper
7-
from .exception_mapper import ExceptionMapper
6+
from .exception_mapper import ExceptionMapper, ExceptionMessage
87
from .exceptions import (
98
BlockException,
109
BlockExceptionInstanceOrList,
@@ -13,8 +12,8 @@
1312
ExceptionInstanceOrList,
1413
TransactionException,
1514
TransactionExceptionInstanceOrList,
15+
UndefinedException,
1616
)
17-
from .geth_exceptions import GethExceptionMapper
1817

1918
__all__ = [
2019
"BlockException",
@@ -23,9 +22,9 @@
2322
"EOFExceptionInstanceOrList",
2423
"EngineAPIError",
2524
"ExceptionMapper",
26-
"EvmoneExceptionMapper",
27-
"GethExceptionMapper",
25+
"ExceptionMessage",
2826
"ExceptionInstanceOrList",
2927
"TransactionException",
28+
"UndefinedException",
3029
"TransactionExceptionInstanceOrList",
3130
]

src/ethereum_test_exceptions/evmone_exceptions.py

Lines changed: 0 additions & 99 deletions
This file was deleted.

src/ethereum_test_exceptions/exception_mapper.py

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
"""
22
EEST Exception mapper
33
"""
4+
45
from abc import ABC, abstractmethod
56
from dataclasses import dataclass
67

78
from bidict import frozenbidict
89

9-
from .exceptions import ExceptionBase, TransactionException, UndefinedException
10+
from .exceptions import ExceptionBase, UndefinedException
1011

1112

1213
@dataclass
@@ -54,37 +55,3 @@ def message_to_exception(self, exception_string: str) -> ExceptionBase:
5455
exception_string, UndefinedException.UNDEFINED_EXCEPTION
5556
)
5657
return exception
57-
58-
def check_transaction(self, tx_error_message: str | None, tx, tx_pos: int):
59-
"""Verify transaction exception"""
60-
exception_info = f"TransactionException (pos={tx_pos}, nonce={tx.nonce})\n"
61-
62-
if tx.error and not tx_error_message:
63-
raise Exception(f"{exception_info} Error: tx expected to fail succeeded")
64-
elif not tx.error and tx_error_message:
65-
raise Exception(f"{exception_info} Error: tx unexpectedly failed: {tx_error_message}")
66-
# TODO check exception list case
67-
elif isinstance(tx.error, TransactionException) and tx_error_message:
68-
expected_error_message = self.exception_to_message(tx.error)
69-
error_exception = self.message_to_exception(tx_error_message)
70-
71-
define_message_hint = (
72-
f"No message defined for {tx.error}, please add it to {self.__class__.__name__}"
73-
if expected_error_message == "Undefined"
74-
else ""
75-
)
76-
define_exception_hint = (
77-
f"No exception defined for error message got, "
78-
f"please add it to {self.__class__.__name__}"
79-
if error_exception == UndefinedException.UNDEFINED_EXCEPTION
80-
else ""
81-
)
82-
83-
if expected_error_message not in tx_error_message:
84-
raise Exception(
85-
f"{exception_info}"
86-
f"Error: exception mismatch:\n want = '{expected_error_message}' ({tx.error}),"
87-
f"\n got = '{tx_error_message}' ({error_exception})"
88-
f"\n {define_message_hint}"
89-
f"\n {define_exception_hint}"
90-
)

src/ethereum_test_exceptions/exceptions.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,11 @@ class TransactionException(ExceptionBase):
372372
"""
373373
TYPE_4_INVALID_AUTHORITY_SIGNATURE = auto()
374374
"""
375-
Transaction is type 4, but has an empty authorization list.
375+
Transaction authority signature is invalid
376+
"""
377+
TYPE_4_INVALID_AUTHORITY_SIGNATURE_S_TOO_HIGH = auto()
378+
"""
379+
Transaction authority signature is invalid
376380
"""
377381
TYPE_4_TX_CONTRACT_CREATION = auto()
378382
"""

src/ethereum_test_exceptions/geth_exceptions.py

Lines changed: 0 additions & 140 deletions
This file was deleted.

src/ethereum_test_specs/base.py

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,15 @@
77
from itertools import count
88
from os import path
99
from pathlib import Path
10-
from typing import Callable, ClassVar, Dict, Generator, Iterator, List, Optional
10+
from typing import Callable, ClassVar, Generator, Iterator, List, Optional
1111

1212
import pytest
1313
from pydantic import BaseModel, Field
1414

1515
from ethereum_test_base_types import to_hex
16-
from ethereum_test_exceptions import ExceptionMapper, TransactionException
1716
from ethereum_test_fixtures import BaseFixture, FixtureFormat
1817
from ethereum_test_forks import Fork
19-
from ethereum_test_types import Environment, Transaction, Withdrawal
18+
from ethereum_test_types import Environment, Withdrawal
2019
from evm_transition_tool import Result, TransitionTool
2120

2221

@@ -33,24 +32,6 @@ def __str__(self): # noqa: D105
3332
return f"{self.message}: Expected {self.expected_hash}, got {self.actual_hash}"
3433

3534

36-
def verify_transactions(
37-
exception_mapper: ExceptionMapper, txs: List[Transaction], result: Result
38-
) -> List[int]:
39-
"""
40-
Verify rejected transactions (if any) against the expected outcome.
41-
Raises exception on unexpected rejections or unexpected successful txs.
42-
"""
43-
rejected_txs: Dict[int, str] = {
44-
rejected_tx.index: rejected_tx.error for rejected_tx in result.rejected_transactions
45-
}
46-
47-
for i, tx in enumerate(txs):
48-
error_message = rejected_txs[i] if i in rejected_txs else None
49-
exception_mapper.check_transaction(error_message, tx, i)
50-
51-
return list(rejected_txs.keys())
52-
53-
5435
def verify_result(result: Result, env: Environment):
5536
"""
5637
Verify that values in the t8n result match the expected values.

0 commit comments

Comments
 (0)