Skip to content

Commit 2b5604f

Browse files
committed
Change RevertTransaction to ContractLogicError
1 parent 4ba54a5 commit 2b5604f

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

newsfragments/1814.bugfix.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Added a new ``RevertTransaction`` error for when the ``REVERT`` opcode is called.
2-
``RevertTransaction`` will replace ``SolidityError``, in v6.
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-
RevertTransaction,
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(RevertTransaction, 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(RevertTransaction, match='not allowed to monitor'):
107+
with pytest.raises(ContractLogicError, match='not allowed to monitor'):
108108
formatters(REVERT_WITH_MSG)
109-
with pytest.raises(RevertTransaction):
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-
RevertTransaction,
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 RevertTransaction(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 RevertTransaction('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 RevertTransaction(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 RevertTransaction(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 RevertTransaction('execution reverted')
525+
raise ContractLogicError('execution reverted')
526526

527527
return response
528528

web3/_utils/module_testing/eth_module.py

Lines changed: 5 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-
RevertTransaction,
4141
TransactionNotFound,
4242
)
4343
from web3.types import ( # noqa: F401
@@ -760,7 +760,7 @@ def test_eth_call_revert_with_msg(
760760
revert_contract: "Contract",
761761
unlocked_account: ChecksumAddress,
762762
) -> None:
763-
with pytest.raises(RevertTransaction,
763+
with pytest.raises(ContractLogicError,
764764
match='execution reverted: Function has been reverted'):
765765
txn_params = revert_contract._prepare_transaction(
766766
fn_name="revertWithMessage",
@@ -777,7 +777,7 @@ def test_eth_call_revert_without_msg(
777777
revert_contract: "Contract",
778778
unlocked_account: ChecksumAddress,
779779
) -> None:
780-
with pytest.raises(RevertTransaction, match="execution reverted"):
780+
with pytest.raises(ContractLogicError, match="execution reverted"):
781781
txn_params = revert_contract._prepare_transaction(
782782
fn_name="revertWithoutMessage",
783783
transaction={
@@ -793,7 +793,7 @@ def test_eth_estimateGas_revert_with_msg(
793793
revert_contract: "Contract",
794794
unlocked_account: ChecksumAddress,
795795
) -> None:
796-
with pytest.raises(RevertTransaction,
796+
with pytest.raises(ContractLogicError,
797797
match='execution reverted: Function has been reverted'):
798798
txn_params = revert_contract._prepare_transaction(
799799
fn_name="revertWithMessage",
@@ -810,7 +810,7 @@ def test_eth_estimateGas_revert_without_msg(
810810
revert_contract: "Contract",
811811
unlocked_account: ChecksumAddress,
812812
) -> None:
813-
with pytest.raises(RevertTransaction, match="execution reverted"):
813+
with pytest.raises(ContractLogicError, match="execution reverted"):
814814
txn_params = revert_contract._prepare_transaction(
815815
fn_name="revertWithoutMessage",
816816
transaction={

web3/exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ class SolidityError(ValueError):
202202
pass
203203

204204

205-
class RevertTransaction(SolidityError, ValueError):
205+
class ContractLogicError(SolidityError, ValueError):
206206
# Inherits from ValueError for backwards compatibility
207207
# TODO: Remove SolidityError inheritance in v6
208208
"""

0 commit comments

Comments
 (0)