Skip to content

Commit

Permalink
fix: issue where local contract creation not cleared (ApeWorX#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Aug 30, 2024
1 parent ebe446c commit d9d6f56
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ape/managers/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 29 additions & 0 deletions tests/functional/test_contracts_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {}

0 comments on commit d9d6f56

Please sign in to comment.