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

feat: added warning suppression for if you don't care that a contract has no bytecode #313

Closed
Closed
Show file tree
Hide file tree
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
12 changes: 9 additions & 3 deletions boa/contracts/abi/abi_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,15 @@ 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)
self._abi = abi
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,
Expand Down Expand Up @@ -364,13 +365,18 @@ def functions(self):
def from_abi_dict(cls, abi, name="<anonymous contract>", 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)
Expand Down
13 changes: 13 additions & 0 deletions tests/unitary/contracts/abi/test_abi.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
import warnings

import pytest
import yaml
Expand Down Expand Up @@ -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
Expand Down
Loading