Skip to content

refactor!: move contract instance and container helper utilities to chain.contracts #898

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

Merged
merged 10 commits into from
Jul 24, 2022

Conversation

antazoey
Copy link
Member

@antazoey antazoey commented Jul 20, 2022

What I did

fixes: #777
this was a breaking change we wanted to do since create_contract is a confusing name.

How I did it

removed method entirely and use methods in chain.contracts

How to verify it

name good or nah?

Checklist

  • All changes are completed
  • New test cases have been added
  • Documentation has been updated

@antazoey antazoey marked this pull request as draft July 20, 2022 22:26
@antazoey antazoey force-pushed the refactor/rename-contract-method branch from d9a50bb to 8e13858 Compare July 20, 2022 22:52
@antazoey antazoey changed the title refactor!: rename create_contract to get_contract_instance refactor!: move contract instance and container helper utilities to chain.contracts Jul 21, 2022
@antazoey antazoey marked this pull request as ready for review July 21, 2022 00:27
fubuloubu
fubuloubu previously approved these changes Jul 21, 2022
)
self.chain_manager.contracts[contract_instance.address] = contract_instance.contract_type
return contract_instance
# NOTE: Type ignore because we know it is a contract instance at this point
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could throw a assert contract_instance in here to satisfy mypy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mypy is mad because the type is BaseAddress and not ContractInstance

Normally I would check the type to satisfy mypy (or assert the type), but importing from the ape.contracts namespace is challenging (circular imports)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about assert not isinstance(contract_instance, AddressType)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be BaseAddress, but let me try

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh no that won't work because ContractInstance is a subclass of BaseAddress

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I kind of wish instance_at() always returned a ContractInstance. I don't remember why we made it return Address when it does not find the contract

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I kind of wish instance_at() always returned a ContractInstance. I don't remember why we made it return Address when it does not find the contract

I don't either. Let's change that? Or have it return Optional[ContractInstance] maybe

Copy link
Member

@fubuloubu fubuloubu Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe ape.Contract is more of the API to access the contract cache?

Copy link
Member Author

@antazoey antazoey Jul 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ape.Contract calls instance_at() at under-the-hood and manager-access mixin impls use chain_manager.instance_at directly since they can't really import from the top-level namespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See all the changes in the latest commit! Making this change makes things way easier and still fixes #777, as now things will fail loudly and cause alert.

fubuloubu
fubuloubu previously approved these changes Jul 21, 2022
fubuloubu
fubuloubu previously approved these changes Jul 21, 2022
@antazoey antazoey requested a review from fubuloubu July 22, 2022 14:08
fubuloubu
fubuloubu previously approved these changes Jul 22, 2022
@antazoey antazoey merged commit 4817927 into ApeWorX:main Jul 24, 2022
@antazoey antazoey deleted the refactor/rename-contract-method branch July 24, 2022 03:42
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.

Contract does not raise a warning if it can't find a contract type
2 participants