Skip to content

Commit 7b1694e

Browse files
souradeep-dasSamWilsn
authored andcommitted
add specific exceptions on tests
update exceptions for other forks fix tests use fork module rename to NonceOverFlowError revert load test catching specific exc style: indent comment line
1 parent e6108ed commit 7b1694e

File tree

32 files changed

+266
-101
lines changed

32 files changed

+266
-101
lines changed

src/ethereum/arrow_glacier/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1515
from ethereum.crypto.hash import Hash32, keccak256
16-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
16+
from ethereum.exceptions import (
17+
InsufficientTransactionGasError,
18+
InvalidSignatureError,
19+
NonceOverflowError,
20+
)
1721

1822
from .exceptions import TransactionTypeError
1923
from .fork_types import Address
@@ -337,15 +341,17 @@ def validate_transaction(tx: Transaction) -> Uint:
337341
338342
This function takes a transaction as a parameter and returns the intrinsic
339343
gas cost of the transaction after validation. It throws an
340-
`InvalidTransaction` exception if the transaction is invalid.
344+
`InsufficientTransactionGasError` exception if the transaction does not
345+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
346+
exception if the nonce is greater than `2**64 - 2`.
341347
342348
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
343349
"""
344350
intrinsic_gas = calculate_intrinsic_cost(tx)
345351
if intrinsic_gas > tx.gas:
346-
raise InvalidTransaction("Insufficient gas")
352+
raise InsufficientTransactionGasError("Insufficient gas")
347353
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
348-
raise InvalidTransaction("Nonce too high")
354+
raise NonceOverflowError("Nonce too high")
349355
return intrinsic_gas
350356

351357

src/ethereum/berlin/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1515
from ethereum.crypto.hash import Hash32, keccak256
16-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
16+
from ethereum.exceptions import (
17+
InsufficientTransactionGasError,
18+
InvalidSignatureError,
19+
NonceOverflowError,
20+
)
1721

1822
from .exceptions import TransactionTypeError
1923
from .fork_types import Address
@@ -254,15 +258,17 @@ def validate_transaction(tx: Transaction) -> Uint:
254258
255259
This function takes a transaction as a parameter and returns the intrinsic
256260
gas cost of the transaction after validation. It throws an
257-
`InvalidTransaction` exception if the transaction is invalid.
261+
`InsufficientTransactionGasError` exception if the transaction does not
262+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
263+
exception if the nonce is greater than `2**64 - 2`.
258264
259265
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
260266
"""
261267
intrinsic_gas = calculate_intrinsic_cost(tx)
262268
if intrinsic_gas > tx.gas:
263-
raise InvalidTransaction("Insufficient gas")
269+
raise InsufficientTransactionGasError("Insufficient gas")
264270
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
265-
raise InvalidTransaction("Nonce too high")
271+
raise NonceOverflowError("Nonce too high")
266272
return intrinsic_gas
267273

268274

src/ethereum/byzantium/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1414
from ethereum.crypto.hash import Hash32, keccak256
15-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
15+
from ethereum.exceptions import (
16+
InsufficientTransactionGasError,
17+
InvalidSignatureError,
18+
NonceOverflowError,
19+
)
1620

1721
from .fork_types import Address
1822

@@ -110,15 +114,17 @@ def validate_transaction(tx: Transaction) -> Uint:
110114
111115
This function takes a transaction as a parameter and returns the intrinsic
112116
gas cost of the transaction after validation. It throws an
113-
`InvalidTransaction` exception if the transaction is invalid.
117+
`InsufficientTransactionGasError` exception if the transaction does not
118+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
119+
exception if the nonce is greater than `2**64 - 2`.
114120
115121
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
116122
"""
117123
intrinsic_gas = calculate_intrinsic_cost(tx)
118124
if intrinsic_gas > tx.gas:
119-
raise InvalidTransaction("Insufficient gas")
125+
raise InsufficientTransactionGasError("Insufficient gas")
120126
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
121-
raise InvalidTransaction("Nonce too high")
127+
raise NonceOverflowError("Nonce too high")
122128
return intrinsic_gas
123129

124130

src/ethereum/cancun/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,9 @@ class PriorityFeeGreaterThanMaxFeeError(InvalidTransaction):
101101
"""
102102
The priority fee is greater than the maximum fee per gas.
103103
"""
104+
105+
106+
class InitCodeTooLargeError(InvalidTransaction):
107+
"""
108+
The init code of the transaction is too large.
109+
"""

src/ethereum/cancun/transactions.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313

1414
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1515
from ethereum.crypto.hash import Hash32, keccak256
16-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
16+
from ethereum.exceptions import (
17+
InsufficientTransactionGasError,
18+
InvalidSignatureError,
19+
NonceOverflowError,
20+
)
1721

18-
from .exceptions import TransactionTypeError
22+
from .exceptions import InitCodeTooLargeError, TransactionTypeError
1923
from .fork_types import Address, VersionedHash
2024

2125
TX_BASE_COST = Uint(21000)
@@ -439,19 +443,23 @@ def validate_transaction(tx: Transaction) -> Uint:
439443
440444
This function takes a transaction as a parameter and returns the intrinsic
441445
gas cost of the transaction after validation. It throws an
442-
`InvalidTransaction` exception if the transaction is invalid.
446+
`InsufficientTransactionGasError` exception if the transaction does not
447+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
448+
exception if the nonce is greater than `2**64 - 2`. It also raises an
449+
`InitCodeTooLargeError` if the code size of a contract creation transaction
450+
exceeds the maximum allowed size.
443451
444452
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
445453
"""
446454
from .vm.interpreter import MAX_INIT_CODE_SIZE
447455

448456
intrinsic_gas = calculate_intrinsic_cost(tx)
449457
if intrinsic_gas > tx.gas:
450-
raise InvalidTransaction("Insufficient gas")
458+
raise InsufficientTransactionGasError("Insufficient gas")
451459
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
452-
raise InvalidTransaction("Nonce too high")
460+
raise NonceOverflowError("Nonce too high")
453461
if tx.to == Bytes0(b"") and len(tx.data) > MAX_INIT_CODE_SIZE:
454-
raise InvalidTransaction("Code size too large")
462+
raise InitCodeTooLargeError("Code size too large")
455463

456464
return intrinsic_gas
457465

src/ethereum/constantinople/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1414
from ethereum.crypto.hash import Hash32, keccak256
15-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
15+
from ethereum.exceptions import (
16+
InsufficientTransactionGasError,
17+
InvalidSignatureError,
18+
NonceOverflowError,
19+
)
1620

1721
from .fork_types import Address
1822

@@ -110,15 +114,17 @@ def validate_transaction(tx: Transaction) -> Uint:
110114
111115
This function takes a transaction as a parameter and returns the intrinsic
112116
gas cost of the transaction after validation. It throws an
113-
`InvalidTransaction` exception if the transaction is invalid.
117+
`InsufficientTransactionGasError` exception if the transaction does not
118+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
119+
exception if the nonce is greater than `2**64 - 2`.
114120
115121
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
116122
"""
117123
intrinsic_gas = calculate_intrinsic_cost(tx)
118124
if intrinsic_gas > tx.gas:
119-
raise InvalidTransaction("Insufficient gas")
125+
raise InsufficientTransactionGasError("Insufficient gas")
120126
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
121-
raise InvalidTransaction("Nonce too high")
127+
raise NonceOverflowError("Nonce too high")
122128
return intrinsic_gas
123129

124130

src/ethereum/dao_fork/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1414
from ethereum.crypto.hash import Hash32, keccak256
15-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
15+
from ethereum.exceptions import (
16+
InsufficientTransactionGasError,
17+
InvalidSignatureError,
18+
NonceOverflowError,
19+
)
1620

1721
from .fork_types import Address
1822

@@ -110,15 +114,17 @@ def validate_transaction(tx: Transaction) -> Uint:
110114
111115
This function takes a transaction as a parameter and returns the intrinsic
112116
gas cost of the transaction after validation. It throws an
113-
`InvalidTransaction` exception if the transaction is invalid.
117+
`InsufficientTransactionGasError` exception if the transaction does not
118+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
119+
exception if the nonce is greater than `2**64 - 2`.
114120
115121
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
116122
"""
117123
intrinsic_gas = calculate_intrinsic_cost(tx)
118124
if intrinsic_gas > tx.gas:
119-
raise InvalidTransaction("Insufficient gas")
125+
raise InsufficientTransactionGasError("Insufficient gas")
120126
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
121-
raise InvalidTransaction("Nonce too high")
127+
raise NonceOverflowError("Nonce too high")
122128
return intrinsic_gas
123129

124130

src/ethereum/exceptions.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,16 @@ class GasUsedExceedsLimitError(InvalidTransaction):
6060
Thrown when a transaction's gas usage exceeds the gas available in the
6161
block.
6262
"""
63+
64+
65+
class InsufficientTransactionGasError(InvalidTransaction):
66+
"""
67+
Thrown when a transaction does not provide enough gas to cover its
68+
intrinsic cost.
69+
"""
70+
71+
72+
class NonceOverflowError(InvalidTransaction):
73+
"""
74+
Thrown when a transaction's nonce is greater than `2**64 - 2`.
75+
"""

src/ethereum/frontier/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212

1313
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1414
from ethereum.crypto.hash import Hash32, keccak256
15-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
15+
from ethereum.exceptions import (
16+
InsufficientTransactionGasError,
17+
InvalidSignatureError,
18+
NonceOverflowError,
19+
)
1620

1721
from .fork_types import Address
1822

@@ -105,15 +109,17 @@ def validate_transaction(tx: Transaction) -> Uint:
105109
106110
This function takes a transaction as a parameter and returns the intrinsic
107111
gas cost of the transaction after validation. It throws an
108-
`InvalidTransaction` exception if the transaction is invalid.
112+
`InsufficientTransactionGasError` exception if the transaction does not
113+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
114+
exception if the nonce is greater than `2**64 - 2`.
109115
110116
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
111117
"""
112118
intrinsic_gas = calculate_intrinsic_cost(tx)
113119
if intrinsic_gas > tx.gas:
114-
raise InvalidTransaction("Insufficient gas")
120+
raise InsufficientTransactionGasError("Insufficient gas")
115121
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
116-
raise InvalidTransaction("Nonce too high")
122+
raise NonceOverflowError("Nonce too high")
117123
return intrinsic_gas
118124

119125

src/ethereum/gray_glacier/transactions.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313

1414
from ethereum.crypto.elliptic_curve import SECP256K1N, secp256k1_recover
1515
from ethereum.crypto.hash import Hash32, keccak256
16-
from ethereum.exceptions import InvalidSignatureError, InvalidTransaction
16+
from ethereum.exceptions import (
17+
InsufficientTransactionGasError,
18+
InvalidSignatureError,
19+
NonceOverflowError,
20+
)
1721

1822
from .exceptions import TransactionTypeError
1923
from .fork_types import Address
@@ -337,15 +341,17 @@ def validate_transaction(tx: Transaction) -> Uint:
337341
338342
This function takes a transaction as a parameter and returns the intrinsic
339343
gas cost of the transaction after validation. It throws an
340-
`InvalidTransaction` exception if the transaction is invalid.
344+
`InsufficientTransactionGasError` exception if the transaction does not
345+
provide enough gas to cover the intrinsic cost, and a `NonceOverflowError`
346+
exception if the nonce is greater than `2**64 - 2`.
341347
342348
[EIP-2681]: https://eips.ethereum.org/EIPS/eip-2681
343349
"""
344350
intrinsic_gas = calculate_intrinsic_cost(tx)
345351
if intrinsic_gas > tx.gas:
346-
raise InvalidTransaction("Insufficient gas")
352+
raise InsufficientTransactionGasError("Insufficient gas")
347353
if U256(tx.nonce) >= U256(U64.MAX_VALUE):
348-
raise InvalidTransaction("Nonce too high")
354+
raise NonceOverflowError("Nonce too high")
349355
return intrinsic_gas
350356

351357

0 commit comments

Comments
 (0)