diff --git a/boa/contracts/abi/abi_contract.py b/boa/contracts/abi/abi_contract.py index 47f8b382..ccb893a7 100644 --- a/boa/contracts/abi/abi_contract.py +++ b/boa/contracts/abi/abi_contract.py @@ -236,6 +236,7 @@ def __init__( functions: list[ABIFunction], address: Address, filename: Optional[str] = None, + suppress_warning: bool = False, env=None, ): super().__init__(name, env, filename=filename, address=address) @@ -243,7 +244,7 @@ def __init__( self._functions = functions self._bytecode = self.env.get_code(address) - if not self._bytecode: + if not self._bytecode and not suppress_warning: warn( f"Requested {self} but there is no bytecode at that address!", stacklevel=2, @@ -364,13 +365,18 @@ def functions(self): def from_abi_dict(cls, abi, name="", filename=None): return cls(name, abi, filename) - def at(self, address: Address | str) -> ABIContract: + def at(self, address: Address | str, suppress_warning: bool = False) -> ABIContract: """ Create an ABI contract object for a deployed contract at `address`. """ address = Address(address) contract = ABIContract( - self._name, self._abi, self.functions, address, self.filename + self._name, + self._abi, + self.functions, + address, + self.filename, + suppress_warning=suppress_warning, ) contract.env.register_contract(address, contract) diff --git a/tests/unitary/contracts/abi/test_abi.py b/tests/unitary/contracts/abi/test_abi.py index c8f90f39..285e81d0 100644 --- a/tests/unitary/contracts/abi/test_abi.py +++ b/tests/unitary/contracts/abi/test_abi.py @@ -1,4 +1,5 @@ import re +import warnings import pytest import yaml @@ -160,6 +161,18 @@ def test() -> uint256: assert "no bytecode at this address!" in str(e.value) +def test_bad_address_suppressed(): + code = """ +@external +def test() -> uint256: + return 0 +""" + abi_contract, _ = load_via_abi(code) + with warnings.catch_warnings(): + warnings.simplefilter("error") + abi_contract = abi_contract.deployer.at(ZERO_ADDRESS, suppress_warning=True) + + def test_abi_reverts(): code = """ @external