Skip to content

Commit

Permalink
Change RevertTransaction to ContractLogicError
Browse files Browse the repository at this point in the history
  • Loading branch information
kclowes committed Jan 11, 2021
1 parent 4ba54a5 commit 2b5604f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions newsfragments/1814.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Added a new ``RevertTransaction`` error for when the ``REVERT`` opcode is called.
``RevertTransaction`` will replace ``SolidityError``, in v6.
Added a new ``ContractLogicError`` for when a contract reverts a transaction.
``ContractLogicError`` will replace ``SolidityError``, in v6.
8 changes: 4 additions & 4 deletions tests/core/utilities/test_method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
RPC,
)
from web3.exceptions import (
RevertTransaction,
ContractLogicError,
)
from web3.types import (
RPCResponse,
Expand Down Expand Up @@ -94,7 +94,7 @@
'test_get-ganache-revert-reason',
])
def test_get_revert_reason(response, expected) -> None:
with pytest.raises(RevertTransaction, match=expected):
with pytest.raises(ContractLogicError, match=expected):
raise_solidity_error_on_revert(response)


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

def test_get_error_formatters() -> None:
formatters = get_error_formatters(RPC.eth_call)
with pytest.raises(RevertTransaction, match='not allowed to monitor'):
with pytest.raises(ContractLogicError, match='not allowed to monitor'):
formatters(REVERT_WITH_MSG)
with pytest.raises(RevertTransaction):
with pytest.raises(ContractLogicError):
formatters(REVERT_WITHOUT_MSG)
assert formatters(OTHER_ERROR) == OTHER_ERROR
12 changes: 6 additions & 6 deletions web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
)
from web3.exceptions import (
BlockNotFound,
RevertTransaction,
ContractLogicError,
TransactionNotFound,
)
from web3.types import (
Expand Down Expand Up @@ -503,26 +503,26 @@ def raise_solidity_error_on_revert(response: RPCResponse) -> RPCResponse:

# Ganache case:
if isinstance(data, dict) and response['error'].get('message'):
raise RevertTransaction(f'execution reverted: {response["error"]["message"]}')
raise ContractLogicError(f'execution reverted: {response["error"]["message"]}')

# Parity/OpenEthereum case:
if data.startswith('Reverted '):
# "Reverted", function selector and offset are always the same for revert errors
prefix = 'Reverted 0x08c379a00000000000000000000000000000000000000000000000000000000000000020' # noqa: 501
if not data.startswith(prefix):
raise RevertTransaction('execution reverted')
raise ContractLogicError('execution reverted')

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

# Geth case:
if 'message' in response['error'] and response['error'].get('code', '') == 3:
raise RevertTransaction(response['error']['message'])
raise ContractLogicError(response['error']['message'])

# Geth Revert without error message case:
if 'execution reverted' in response['error'].get('message'):
raise RevertTransaction('execution reverted')
raise ContractLogicError('execution reverted')

return response

Expand Down
10 changes: 5 additions & 5 deletions web3/_utils/module_testing/eth_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
)
from web3.exceptions import (
BlockNotFound,
ContractLogicError,
InvalidAddress,
NameNotFound,
RevertTransaction,
TransactionNotFound,
)
from web3.types import ( # noqa: F401
Expand Down Expand Up @@ -760,7 +760,7 @@ def test_eth_call_revert_with_msg(
revert_contract: "Contract",
unlocked_account: ChecksumAddress,
) -> None:
with pytest.raises(RevertTransaction,
with pytest.raises(ContractLogicError,
match='execution reverted: Function has been reverted'):
txn_params = revert_contract._prepare_transaction(
fn_name="revertWithMessage",
Expand All @@ -777,7 +777,7 @@ def test_eth_call_revert_without_msg(
revert_contract: "Contract",
unlocked_account: ChecksumAddress,
) -> None:
with pytest.raises(RevertTransaction, match="execution reverted"):
with pytest.raises(ContractLogicError, match="execution reverted"):
txn_params = revert_contract._prepare_transaction(
fn_name="revertWithoutMessage",
transaction={
Expand All @@ -793,7 +793,7 @@ def test_eth_estimateGas_revert_with_msg(
revert_contract: "Contract",
unlocked_account: ChecksumAddress,
) -> None:
with pytest.raises(RevertTransaction,
with pytest.raises(ContractLogicError,
match='execution reverted: Function has been reverted'):
txn_params = revert_contract._prepare_transaction(
fn_name="revertWithMessage",
Expand All @@ -810,7 +810,7 @@ def test_eth_estimateGas_revert_without_msg(
revert_contract: "Contract",
unlocked_account: ChecksumAddress,
) -> None:
with pytest.raises(RevertTransaction, match="execution reverted"):
with pytest.raises(ContractLogicError, match="execution reverted"):
txn_params = revert_contract._prepare_transaction(
fn_name="revertWithoutMessage",
transaction={
Expand Down
2 changes: 1 addition & 1 deletion web3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class SolidityError(ValueError):
pass


class RevertTransaction(SolidityError, ValueError):
class ContractLogicError(SolidityError, ValueError):
# Inherits from ValueError for backwards compatibility
# TODO: Remove SolidityError inheritance in v6
"""
Expand Down

0 comments on commit 2b5604f

Please sign in to comment.