Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add handler for Ganache revert message format #1794

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/core/utilities/test_method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@
"id": 1,
})

GANACHE_RESPONSE = RPCResponse({
'id': 24,
'jsonrpc': '2.0',
'error': {
'message': 'VM Exception while processing transaction: revert Custom revert message',
'code': -32000,
'data': {
'stack': 'o: VM Exception while processing transaction: revert Custom revert message\n',
'name': 'o'
}
}
})


@pytest.mark.parametrize(
"response,expected",
Expand All @@ -69,6 +82,14 @@ def test_get_revert_reason_other_error() -> None:
assert raise_solidity_error_on_revert(OTHER_ERROR) is OTHER_ERROR


def test_get_revert_reason_ganache() -> None:
with pytest.raises(
SolidityError,
match='VM Exception while processing transaction: revert Custom revert message'
):
raise_solidity_error_on_revert(GANACHE_RESPONSE)


def test_get_error_formatters() -> None:
formatters = get_error_formatters(RPC.eth_call)
with pytest.raises(SolidityError, match='not allowed to monitor'):
Expand Down
7 changes: 6 additions & 1 deletion web3/_utils/method_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,13 @@ def raise_solidity_error_on_revert(response: RPCResponse) -> RPCResponse:
if not isinstance(response['error'], dict):
raise ValueError('Error expected to be a dict')

# Parity/OpenEthereum case:
data = response['error'].get('data', '')

# Ganache case:
if isinstance(data, dict) and response['error'].get('message'):
wolovim marked this conversation as resolved.
Show resolved Hide resolved
raise SolidityError(response['error']['message'])
wolovim marked this conversation as resolved.
Show resolved Hide resolved

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