Skip to content

Commit

Permalink
fix: accidental override
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Dec 12, 2024
1 parent 149c654 commit f21a636
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/ape/api/networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ class ProxyInfoAPI(BaseModel):
target: AddressType
"""The address of the implementation contract."""

@property
def abi(self) -> Optional["MethodABI"]:
"""
Some proxies have special ABIs which may not exist in their
contract-types by default, such as Safe's ``masterCopy()``.
"""
return None


class EcosystemAPI(ExtraAttributesMixin, BaseInterfaceModel):
"""
Expand Down
11 changes: 7 additions & 4 deletions src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,21 +809,24 @@ def cache_deployment(self, contract_instance: ContractInstance):
self.cache_proxy_info(address, proxy_info)
if implementation_contract := self.get(proxy_info.target):
# Include proxy ABIs but ignore fallback/ctor etc.
abis = list(implementation_contract.abi)
proxy_abis = [
abi for abi in contract_type.abi if abi.type in ("error", "event", "function")
]
implementation_contract.abi.extend(proxy_abis)
abis.extend(proxy_abis)

# Include "hidden" ABIs, such as Safe's `masterCopy()`.
if proxy_info.abi and proxy_info.abi.signature not in [
abi.signature for abi in contract_type.abi
]:
implementation_contract.abi.append(proxy_info.abi)
abis.append(proxy_info.abi)

self._cache_contract_type(address, implementation_contract)
updated_proxy_contract = implementation_contract.model_copy()
updated_proxy_contract.abi = abis
self._cache_contract_type(address, updated_proxy_contract)

# Use this contract type in the user's contract instance.
contract_instance.contract_type = implementation_contract
contract_instance.contract_type = updated_proxy_contract

else:
# No implementation yet. Just cache proxy.
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/geth/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_gnosis_safe(get_contract_type, geth_contract, owner, ethereum, chain):
# Ensure we can call the proxy-method.
assert proxy_instance.masterCopy()

# Ensure we can target methods.
# Ensure we can call target methods.
assert isinstance(proxy_instance.myNumber(), int)

# Ensure this works with new instances.
Expand Down

0 comments on commit f21a636

Please sign in to comment.