diff --git a/brownie/network/contract.py b/brownie/network/contract.py index 44ce7cab3..f8de57a88 100644 --- a/brownie/network/contract.py +++ b/brownie/network/contract.py @@ -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 @@ -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: