diff --git a/src/ape/managers/chain.py b/src/ape/managers/chain.py index 1358f59640..022eeac8a5 100644 --- a/src/ape/managers/chain.py +++ b/src/ape/managers/chain.py @@ -1313,7 +1313,7 @@ def clear_local_caches(self): self._local_proxies = {} self._local_blueprints = {} self._local_deployments_mapping = {} - self._local_creation_metadata = {} + self._local_contract_creation = {} def _get_contract_type_from_disk(self, address: AddressType) -> Optional[ContractType]: address_file = self._contract_types_cache / f"{address}.json" diff --git a/tests/functional/test_contracts_cache.py b/tests/functional/test_contracts_cache.py index 919d828b5e..9e586a944d 100644 --- a/tests/functional/test_contracts_cache.py +++ b/tests/functional/test_contracts_cache.py @@ -472,3 +472,32 @@ def test_delete_proxy(vyper_contract_instance, chain, ethereum, owner): # Ensure we can't access the target either. with pytest.raises(KeyError): _ = chain.contracts[proxy_info.target] + + +def test_clear_local_caches(chain, vyper_contract_instance, proxy_contract_container, owner): + # Ensure contract type exists. + address = vyper_contract_instance.address + # Ensure blueprint exists. + chain.contracts._local_blueprints[address] = vyper_contract_instance.contract_type + # Ensure proxy exists. + proxy = proxy_contract_container.deploy(address, sender=owner) + # Ensure creation exists. + _ = chain.contracts.get_creation_metadata(address) + + # Test setup verification. + assert ( + address in chain.contracts._local_contract_types + ), "Setup failed - no contract type(s) cached" + assert proxy.address in chain.contracts._local_proxies, "Setup failed - no proxy cached" + assert ( + address in chain.contracts._local_contract_creation + ), "Setup failed - no creation(s) cached" + + # This is the method we are testing. + chain.contracts.clear_local_caches() + + # Assertions - everything should be empty. + assert chain.contracts._local_proxies == {} + assert chain.contracts._local_blueprints == {} + assert chain.contracts._local_deployments_mapping == {} + assert chain.contracts._local_contract_creation == {}