diff --git a/src/ape/api/accounts.py b/src/ape/api/accounts.py index 482ba084f9..cb89480ff6 100644 --- a/src/ape/api/accounts.py +++ b/src/ape/api/accounts.py @@ -281,6 +281,7 @@ def deploy( self.project_manager.track_deployment(instance) self.provider.network.publish_contract(address) + instance.base_path = contract.base_path or self.project_manager.contracts_folder return instance def declare(self, contract: "ContractContainer", *args, **kwargs) -> ReceiptAPI: diff --git a/src/ape/contracts/base.py b/src/ape/contracts/base.py index beaa91db8c..85617aa392 100644 --- a/src/ape/contracts/base.py +++ b/src/ape/contracts/base.py @@ -730,6 +730,7 @@ def poll_logs( class ContractTypeWrapper(ManagerAccessMixin): contract_type: ContractType + base_path: Optional[Path] = None @property def selector_identifiers(self) -> Dict[str, str]: @@ -747,7 +748,7 @@ def identifier_lookup(self) -> Dict[str, ABI_W_SELECTOR_T]: """ return self.contract_type.identifier_lookup - @cached_property + @property def source_path(self) -> Optional[Path]: """ Returns the path to the local contract if determined that this container @@ -757,23 +758,12 @@ def source_path(self) -> Optional[Path]: source ID as one in the current project. That does not necessarily mean they are the same contract, however. """ - contract_name = self.contract_type.name - source_id = self.contract_type.source_id - if not (contract_name and source_id): + if not (source_id := self.contract_type.source_id): return None - contract_container = self.project_manager._get_contract(contract_name) - if not ( - contract_container - and contract_container.contract_type.source_id - and self.contract_type.source_id - ): - return None - - if source_id == contract_container.contract_type.source_id: - return self.project_manager.contracts_folder / source_id - else: - return None + base = self.base_path or self.project_manager.contracts_folder + path = base / source_id + return path if path.is_file() else None def decode_input(self, calldata: bytes) -> Tuple[str, Dict[str, Any]]: """ @@ -1420,6 +1410,7 @@ def deploy(self, *args, publish: bool = False, **kwargs) -> ContractInstance: self.project_manager.track_deployment(instance) self.provider.network.publish_contract(address) + instance.base_path = self.base_path or self.project_manager.contracts_folder return instance def _cache_wrap(self, function: Callable) -> ReceiptAPI: diff --git a/tests/functional/test_contract_container.py b/tests/functional/test_contract_container.py index c49e8d0825..d415591689 100644 --- a/tests/functional/test_contract_container.py +++ b/tests/functional/test_contract_container.py @@ -125,7 +125,7 @@ def test_source_path_in_project(project_with_contract): contract = project_with_contract.contracts["Contract"] contract_container = project_with_contract.get_contract("Contract") expected = contracts_folder / contract.source_id - + assert contract_container.source_path is not None assert contract_container.source_path.is_file() assert contract_container.source_path == expected