-
Notifications
You must be signed in to change notification settings - Fork 310
tests: add specific exceptions on tests #1286
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
base: master
Are you sure you want to change the base?
Conversation
from ethereum.utils.hexadecimal import hex_to_bytes | ||
from ethereum_spec_tools.evm_tools.loaders.fixture_loader import Load | ||
|
||
FORK_SPECIFIC_EXCEPTIONS = { |
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.
is there a better/preferred way to do this instead?
|
||
class NonceTooHighError(InvalidTransaction): | ||
""" | ||
Thrown when a transaction's nonce is higher than 64 bits. |
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.
Thrown when a transaction's nonce is higher than 64 bits. | |
Thrown when a transaction's nonce is greater than `2**64 - 2`. |
I believe this is more correct?
""" | ||
|
||
|
||
class NonceTooHighError(InvalidTransaction): |
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.
class NonceTooHighError(InvalidTransaction): | |
class NonceOverflowError(InvalidTransaction): |
if the transaction is invalid. | ||
validation. It throws an `InsufficientTransactionGasError` exception if | ||
the transaction does not provide enough gas to cover the intrinsic cost, | ||
and a `NonceTooHighError` exception if the nonce is higher than 64 bits. |
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.
Hm, is this technically correct? We use a >=
in the condition, so I think the docstring is off by one.
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.
We try really hard to avoid fork-specific code where we can. Instead we rely on the Hardfork
class to do the heavy lifting.
You could maybe use module('exceptions')
to load the fork-specific module, then iterate through the classes defined in it?
) | ||
all_exceptions = common_exceptions + fork_specific_exceptions | ||
|
||
with pytest.raises(all_exceptions): |
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 believe the JSON fixture contains a string representing the expected exception. Is it possible to map that to exactly one exception type?
What was wrong?
Related to Issue #1021
How was it fixed?
InvalidTransaction
on pytest.raises with specific exception typeInsufficientTransactionGasError
,NonceTooHighError
andInitCodeTooLargeError
) for transaction validation, extendingInvalidTransaction
Cute Animal Picture