Skip to content

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

souradeep-das
Copy link
Contributor

What was wrong?

Related to Issue #1021

How was it fixed?

  • While loading state tests - replaced InvalidTransaction on pytest.raises with specific exception type
  • Added specific exception (InsufficientTransactionGasError, NonceTooHighError and InitCodeTooLargeError) for transaction validation, extending InvalidTransaction

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

from ethereum.utils.hexadecimal import hex_to_bytes
from ethereum_spec_tools.evm_tools.loaders.fixture_loader import Load

FORK_SPECIFIC_EXCEPTIONS = {
Copy link
Contributor Author

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?

@souradeep-das souradeep-das marked this pull request as ready for review June 24, 2025 21:17

class NonceTooHighError(InvalidTransaction):
"""
Thrown when a transaction's nonce is higher than 64 bits.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Contributor

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.

Copy link
Contributor

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):
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants