Skip to content

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I found that the block_exceptions from legacy tests/blockchain test fixtures are very different from the state transition exceptions. (and the state_transition method from the fork is used to raise the error caught here).

This specific function also seems to work with blockchaintests fixtures so couldn't account for the expected exception from state_tests. If i'm thinking wrong about this - do lmk!

@souradeep-das souradeep-das requested a review from SamWilsn July 1, 2025 10:10
eeemmmmmm and others added 3 commits July 8, 2025 16:55
update exceptions for other forks

fix tests

use fork module

rename to NonceOverFlowError

revert load test catching specific exc

style: indent comment line
@SamWilsn SamWilsn force-pushed the souradeep/exc_tests branch from 7cf1a56 to 3385821 Compare July 8, 2025 21:06
@SamWilsn SamWilsn changed the base branch from master to forks/osaka July 8, 2025 21:07
@SamWilsn SamWilsn closed this Jul 8, 2025
@SamWilsn SamWilsn reopened this Jul 8, 2025
@SamWilsn SamWilsn merged commit 7b1694e into ethereum:forks/osaka Jul 9, 2025
3 of 7 checks passed
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.

4 participants