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

Conversation

PatrickAlphaC
Copy link
Contributor

@PatrickAlphaC PatrickAlphaC commented Sep 12, 2024

What I did

I added a suppress_warning: bool = False keyword argument to:

  1. ABIContract::__init__
  2. ABIContract::at

The rationale for this is as such:

  1. Using the from_etherscan command in boa without being on the same network as the uri will cause this warning to be thrown. So, we should have an option to suppress the warning if we choose a custom uri.
  2. There are scenarios where we may want to assign an ABI to an address with empty code, for example in the case of using CREATE2 to deploy a contract

It may make sense to set this flag to true when calling this function from from_etherscan

How I did it

- def at(self, address: Address | str) -> ABIContract:
+ def at(self, address: Address | str, suppress_warning: bool= False) -> ABIContract:

How to verify it

I added the following test:

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)

The code:

with warnings.catch_warnings():
        warnings.simplefilter("error

Will error if any warning is thrown, so this test passing means the warning is not being thrown.

pytest -k test_bad_address_suppressed

Description for the changelog

  • feat: enabled ABIContract objects created before bytecode assigned to ignore warnings flagged

Cute Animal Picture

image

@charles-cooper
Copy link
Member

closing per offline discussion, as the warning is usually indicative of a user bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants