-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(exception mapper): class to verify exception strings #795
base: main
Are you sure you want to change the base?
Conversation
src/ethereum_test_specs/base.py
Outdated
@@ -46,6 +49,13 @@ def verify_transactions(txs: List[Transaction], result: Result) -> List[int]: | |||
raise Exception(f"tx expected to fail succeeded: pos={i}, nonce={tx.nonce}") | |||
elif not tx.error and error: | |||
raise Exception(f"tx unexpectedly failed: {error}") | |||
elif isinstance(tx.error, TransactionException) and error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps this whole part should be inside ExceptionMapper. since we compare x and y and have to cover cases each time the exception is verified
expected y, got x == y
expected y, got x != y
expected 0, got x
expected 0, got 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the ExceptionMapper
idea, I think it might be too t8n-focused but it could be used in many other places, e.g. exceptions from the Engine API when we run the tests in hive.
I think this PR can start with TransitionToolExceptionMapper
defined in src/evm_transition_tool
to make ExceptionMapper
a bit more generic to open the door to future PRs to implement other subclasses.
) | ||
return exception | ||
|
||
def check_transaction(self, tx_error_message: str | None, tx, tx_pos: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transaction
here would cause a cycle import, and I think that is because this method should not be defined here because not all tests depend on transaction exceptions (only state_test
).
Probably better to be in ethereum_test_specs/state.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After looking through all the changes, I think what we could do is have a subclass called TransitionToolExceptionMapper
that is specifically dedicated to map exceptions from the transition tool, and this can be used to subclass specific GethTransaitionToolExceptionMapper
and so on.
Another approach could be that we don't need the subclass GethTransaitionToolExceptionMapper
and only TransitionToolExceptionMapper
, and then in src/evm_transition_tool/geth.py
we create an instance of TransitionToolExceptionMapper
that contains the map, so we avoid creating too many classes and also avoid instantiating the same GethTransaitionToolExceptionMapper
every time we instantiate the t8n tool.
@@ -31,7 +32,9 @@ def __str__(self): # noqa: D105 | |||
return f"{self.message}: Expected {self.expected_hash}, got {self.actual_hash}" | |||
|
|||
|
|||
def verify_transactions(txs: List[Transaction], result: Result) -> List[int]: | |||
def verify_transactions( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should take the opportunity and move this somewhere else, maybe an src/ethereum_test_specs/helpers.py
file?
@@ -12,6 +12,7 @@ | |||
from pydantic import BaseModel, Field | |||
|
|||
from ethereum_test_base_types import to_hex | |||
from ethereum_test_exceptions import ExceptionMapper, TransactionException |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from ethereum_test_exceptions import ExceptionMapper, TransactionException | |
from ethereum_test_exceptions import ExceptionMapper |
Unused import.
from .exceptions import EOFException, TransactionException | ||
|
||
|
||
class GethExceptionMapper(ExceptionMapper): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are very directly related to the Geth T8N implementation, it might be a good idea to simply move it into src/evm_transition_tool/geth.py
.
Same for the evmone_exceptions.py
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. This can also be a base exception mapper.
Then geth t8n defines geth exception mapper for t8n.
And geth consume defines exception mapper for consume driver.
🗒️ Description
Extent exception mapper with base class so that any t8n can define exception string maps for any exception types
I put transaction exception validation into exception mapper for convinience atm.
Example exception message:
🔗 Related Issues
✅ Checklist
mkdocs serve
locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.