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

better Panic message for contract call #1275

Merged
merged 1 commit into from
Oct 11, 2021
Merged
Changes from all 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
13 changes: 11 additions & 2 deletions brownie/network/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
VirtualMachineError,
)
from brownie.project import compiler, ethpm
from brownie.project.compiler.solidity import SOLIDITY_ERROR_CODES
from brownie.typing import AccountsType, TransactionReceiptType
from brownie.utils import color
from brownie.utils.toposort import toposort_flatten
Expand Down Expand Up @@ -1532,12 +1533,20 @@ def call(self, *args: Tuple, block_identifier: Union[int, str, bytes] = None) ->
except ValueError as e:
raise VirtualMachineError(e) from None

if HexBytes(data)[:4].hex() == "0x08c379a0":
selector = HexBytes(data)[:4].hex()

if selector == "0x08c379a0":
revert_str = eth_abi.decode_abi(["string"], HexBytes(data)[4:])[0]
raise ValueError(f"Call reverted: {revert_str}")
elif selector == "0x4e487b71":
error_code = int(HexBytes(data)[4:].hex(), 16)
if error_code in SOLIDITY_ERROR_CODES:
revert_str = SOLIDITY_ERROR_CODES[error_code]
else:
revert_str = f"Panic (error code: {error_code})"
raise ValueError(f"Call reverted: {revert_str}")
if self.abi["outputs"] and not data:
raise ValueError("No data was returned - the call likely reverted")

return self.decode_output(data)

def transact(self, *args: Tuple) -> TransactionReceiptType:
Expand Down