Skip to content

Commit e370d16

Browse files
committed
Move SolidityError -> ContractLogicError
1 parent 0096e96 commit e370d16

File tree

5 files changed

+29
-16
lines changed

5 files changed

+29
-16
lines changed

newsfragments/1814.bugfix.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Added a new ``ContractLogicError`` for when a contract reverts a transaction.
2+
``ContractLogicError`` will replace ``SolidityError``, in v6.

tests/core/utilities/test_method_formatters.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
RPC,
99
)
1010
from web3.exceptions import (
11-
SolidityError,
11+
ContractLogicError,
1212
)
1313
from web3.types import (
1414
RPCResponse,
@@ -94,7 +94,7 @@
9494
'test_get-ganache-revert-reason',
9595
])
9696
def test_get_revert_reason(response, expected) -> None:
97-
with pytest.raises(SolidityError, match=expected):
97+
with pytest.raises(ContractLogicError, match=expected):
9898
raise_solidity_error_on_revert(response)
9999

100100

@@ -104,8 +104,8 @@ def test_get_revert_reason_other_error() -> None:
104104

105105
def test_get_error_formatters() -> None:
106106
formatters = get_error_formatters(RPC.eth_call)
107-
with pytest.raises(SolidityError, match='not allowed to monitor'):
107+
with pytest.raises(ContractLogicError, match='not allowed to monitor'):
108108
formatters(REVERT_WITH_MSG)
109-
with pytest.raises(SolidityError):
109+
with pytest.raises(ContractLogicError):
110110
formatters(REVERT_WITHOUT_MSG)
111111
assert formatters(OTHER_ERROR) == OTHER_ERROR

web3/_utils/method_formatters.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
)
8282
from web3.exceptions import (
8383
BlockNotFound,
84-
SolidityError,
84+
ContractLogicError,
8585
TransactionNotFound,
8686
)
8787
from web3.types import (
@@ -503,26 +503,26 @@ def raise_solidity_error_on_revert(response: RPCResponse) -> RPCResponse:
503503

504504
# Ganache case:
505505
if isinstance(data, dict) and response['error'].get('message'):
506-
raise SolidityError(f'execution reverted: {response["error"]["message"]}')
506+
raise ContractLogicError(f'execution reverted: {response["error"]["message"]}')
507507

508508
# Parity/OpenEthereum case:
509509
if data.startswith('Reverted '):
510510
# "Reverted", function selector and offset are always the same for revert errors
511511
prefix = 'Reverted 0x08c379a00000000000000000000000000000000000000000000000000000000000000020' # noqa: 501
512512
if not data.startswith(prefix):
513-
raise SolidityError('execution reverted')
513+
raise ContractLogicError('execution reverted')
514514

515515
reason_length = int(data[len(prefix):len(prefix) + 64], 16)
516516
reason = data[len(prefix) + 64:len(prefix) + 64 + reason_length * 2]
517-
raise SolidityError(f'execution reverted: {bytes.fromhex(reason).decode("utf8")}')
517+
raise ContractLogicError(f'execution reverted: {bytes.fromhex(reason).decode("utf8")}')
518518

519519
# Geth case:
520520
if 'message' in response['error'] and response['error'].get('code', '') == 3:
521-
raise SolidityError(response['error']['message'])
521+
raise ContractLogicError(response['error']['message'])
522522

523523
# Geth Revert without error message case:
524524
if 'execution reverted' in response['error'].get('message'):
525-
raise SolidityError('execution reverted')
525+
raise ContractLogicError('execution reverted')
526526

527527
return response
528528

web3/_utils/module_testing/eth_module.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@
3535
)
3636
from web3.exceptions import (
3737
BlockNotFound,
38+
ContractLogicError,
3839
InvalidAddress,
3940
NameNotFound,
40-
SolidityError,
4141
TransactionNotFound,
4242
)
4343
from web3.types import ( # noqa: F401
@@ -767,7 +767,8 @@ def test_eth_call_revert_with_msg(
767767
revert_contract: "Contract",
768768
unlocked_account: ChecksumAddress,
769769
) -> None:
770-
with pytest.raises(SolidityError, match='execution reverted: Function has been reverted'):
770+
with pytest.raises(ContractLogicError,
771+
match='execution reverted: Function has been reverted'):
771772
txn_params = revert_contract._prepare_transaction(
772773
fn_name="revertWithMessage",
773774
transaction={
@@ -783,7 +784,7 @@ def test_eth_call_revert_without_msg(
783784
revert_contract: "Contract",
784785
unlocked_account: ChecksumAddress,
785786
) -> None:
786-
with pytest.raises(SolidityError, match="execution reverted"):
787+
with pytest.raises(ContractLogicError, match="execution reverted"):
787788
txn_params = revert_contract._prepare_transaction(
788789
fn_name="revertWithoutMessage",
789790
transaction={
@@ -799,7 +800,8 @@ def test_eth_estimateGas_revert_with_msg(
799800
revert_contract: "Contract",
800801
unlocked_account: ChecksumAddress,
801802
) -> None:
802-
with pytest.raises(SolidityError, match='execution reverted: Function has been reverted'):
803+
with pytest.raises(ContractLogicError,
804+
match='execution reverted: Function has been reverted'):
803805
txn_params = revert_contract._prepare_transaction(
804806
fn_name="revertWithMessage",
805807
transaction={
@@ -815,7 +817,7 @@ def test_eth_estimateGas_revert_without_msg(
815817
revert_contract: "Contract",
816818
unlocked_account: ChecksumAddress,
817819
) -> None:
818-
with pytest.raises(SolidityError, match="execution reverted"):
820+
with pytest.raises(ContractLogicError, match="execution reverted"):
819821
txn_params = revert_contract._prepare_transaction(
820822
fn_name="revertWithoutMessage",
821823
transaction={

web3/exceptions.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ class InvalidEventABI(ValueError):
197197
class SolidityError(ValueError):
198198
# Inherits from ValueError for backwards compatibility
199199
"""
200-
Raised on a solidity require/revert
200+
Raised on a contract revert error
201+
"""
202+
pass
203+
204+
205+
class ContractLogicError(SolidityError, ValueError):
206+
# Inherits from ValueError for backwards compatibility
207+
# TODO: Remove SolidityError inheritance in v6
208+
"""
209+
Raised on a contract revert error
201210
"""
202211
pass

0 commit comments

Comments
 (0)