-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Solidity allows messages in `require` statements which can help a lot when debugging. This commit parses the revert reasons from failing `call`s and raises them as `SolidityError` exceptions. Closes #941.
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Raise `SolidityError` exceptions that contain the revert reason when a `call` fails. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from web3.manager import ( | ||
get_revert_reason, | ||
) | ||
from web3.types import ( | ||
RPCResponse, | ||
) | ||
|
||
|
||
def test_get_revert_reason() -> None: | ||
response = RPCResponse({ | ||
'jsonrpc': '2.0', | ||
'error': { | ||
'code': -32015, | ||
'message': 'VM execution error.', | ||
'data': ( | ||
'Reverted ' | ||
'0x08c379a' | ||
'00000000000000000000000000000000000000000000000000000000000000020' | ||
'0000000000000000000000000000000000000000000000000000000000000016' | ||
'6e6f7420616c6c6f77656420746f206d6f6e69746f7200000000000000000000' | ||
), | ||
}, | ||
'id': 2987 | ||
}) | ||
assert get_revert_reason(response) == 'not allowed to monitor' | ||
|
||
|
||
def test_get_revert_reason_without_reason() -> None: | ||
""" In this case, no reason string is given in the solidity code """ | ||
response = RPCResponse({ | ||
'jsonrpc': '2.0', | ||
'error': { | ||
'code': -32015, | ||
'message': 'VM execution error.', | ||
'data': 'Reverted 0x', | ||
}, | ||
'id': 2987 | ||
}) | ||
assert get_revert_reason(response) is None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters