-
-
Notifications
You must be signed in to change notification settings - Fork 147
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
perf: break early on proxy detection when realize can't get storage #2514
Merged
antazoey
merged 4 commits into
ApeWorX:main
from
antazoey:perf/avoid-checking-many-proxies-on-not-impl-error
Feb 19, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
73edc97
perf: break early when detect cant get storage
antazoey 5648920
Merge branch 'main' into perf/avoid-checking-many-proxies-on-not-impl…
antazoey 964635d
Merge branch 'main' into perf/avoid-checking-many-proxies-on-not-impl…
antazoey 4f81948
Merge branch 'main' into perf/avoid-checking-many-proxies-on-not-impl…
antazoey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
from typing import TYPE_CHECKING, Optional | ||
|
||
from eth_pydantic_types import HexBytes | ||
|
||
from ape.contracts.base import ContractContainer | ||
from ape_ethereum.proxies import ProxyType | ||
from ape_test.provider import LocalProvider | ||
|
||
if TYPE_CHECKING: | ||
from ape.types import AddressType, BlockID | ||
|
||
""" | ||
NOTE: Most proxy tests are in `geth/test_proxy.py`. | ||
|
@@ -24,3 +33,49 @@ def test_minimal_proxy(ethereum, minimal_proxy_container, chain, owner): | |
if isinstance(abi, list): | ||
assert abi == [] | ||
# else: is messed up from other test (xdist). | ||
|
||
|
||
def test_provider_not_supports_get_storage( | ||
get_contract_type, owner, vyper_contract_instance, ethereum, chain, networks | ||
): | ||
""" | ||
The get storage slot RPC is required to detect this proxy, so it won't work | ||
on EthTester provider. However, we can make sure that it doesn't try to | ||
call `get_storage()` more than once. | ||
""" | ||
|
||
class MyProvider(LocalProvider): | ||
times_get_storage_was_called: int = 0 | ||
|
||
def get_storage( # type: ignore[empty-body] | ||
self, address: "AddressType", slot: int, block_id: Optional["BlockID"] = None | ||
) -> "HexBytes": | ||
self.times_get_storage_was_called += 1 | ||
raise NotImplementedError() | ||
|
||
my_provider = MyProvider(name="test", network=ethereum.local) | ||
my_provider._web3 = chain.provider._web3 | ||
|
||
_type = get_contract_type("beacon") | ||
beacon_contract = ContractContainer(_type) | ||
target = vyper_contract_instance.address | ||
beacon_instance = owner.deploy(beacon_contract, target) | ||
beacon = beacon_instance.address | ||
|
||
_type = get_contract_type("BeaconProxy") | ||
contract = ContractContainer(_type) | ||
contract_instance = owner.deploy(contract, beacon, HexBytes("")) | ||
|
||
# Ensure not already cached. | ||
if contract_instance.address in chain.contracts.proxy_infos: | ||
del chain.contracts.proxy_infos[contract_instance.address] | ||
|
||
init_provider = networks.active_provider | ||
networks.active_provider = my_provider | ||
try: | ||
actual = ethereum.get_proxy_info(contract_instance.address) | ||
finally: | ||
networks.active_provider = init_provider | ||
|
||
assert actual is None # Because of provider. | ||
assert my_provider.times_get_storage_was_called == 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I had to make a new provider because EthTester supports getting storage now, which is a good thing