-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
refactor!: move contract instance and container helper utilities to chain.contracts #898
Conversation
d9a50bb
to
8e13858
Compare
src/ape/api/accounts.py
Outdated
) | ||
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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)
?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 aContractInstance
. I don't remember why we made it returnAddress
when it does not find the contract
I don't either. Let's change that? Or have it return Optional[ContractInstance]
maybe
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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