|
26 | 26 | from ape.utils import cached_property |
27 | 27 | from ape_ethereum.provider import Web3Provider |
28 | 28 | from ape_test import ApeTestConfig |
29 | | -from eth_pydantic_types import HashBytes32, HexBytes |
| 29 | +from eth_pydantic_types import HexBytes, HexBytes32 |
30 | 30 | from eth_typing import HexStr |
31 | 31 | from eth_utils import add_0x_prefix, is_0x_prefixed, is_hex, to_hex |
32 | 32 | from pydantic import field_validator, model_validator |
|
41 | 41 | from web3.middleware import ExtraDataToPOAMiddleware # type: ignore |
42 | 42 | except ImportError: |
43 | 43 | from web3.middleware import geth_poa_middleware as ExtraDataToPOAMiddleware # type: ignore |
| 44 | + |
44 | 45 | from web3.middleware.validation import MAX_EXTRADATA_LENGTH |
45 | 46 | from yarl import URL |
46 | 47 |
|
@@ -141,6 +142,7 @@ class FoundryProvider(SubprocessProvider, Web3Provider, TestProviderAPI): |
141 | 142 | attempted_ports: list[int] = [] |
142 | 143 | cached_chain_id: Optional[int] = None |
143 | 144 | _did_warn_wrong_node = False |
| 145 | + _disconnected: Optional[bool] = None |
144 | 146 |
|
145 | 147 | @property |
146 | 148 | def unlocked_accounts(self) -> list["AddressType"]: |
@@ -258,7 +260,7 @@ def ws_uri(self) -> str: |
258 | 260 |
|
259 | 261 | @property |
260 | 262 | def is_connected(self) -> bool: |
261 | | - if self._host in ("auto", None): |
| 263 | + if self._disconnected is True or self._host in ("auto", None): |
262 | 264 | # Hasn't tried yet. |
263 | 265 | return False |
264 | 266 |
|
@@ -299,7 +301,7 @@ def connect(self): |
299 | 301 | Start the foundry process and verify it's up and accepting connections. |
300 | 302 | **NOTE**: Must set port before calling 'super().connect()'. |
301 | 303 | """ |
302 | | - |
| 304 | + self._disconnected = False |
303 | 305 | if "APE_FOUNDRY_HOST" in os.environ: |
304 | 306 | self._host = os.environ["APE_FOUNDRY_HOST"] |
305 | 307 |
|
@@ -452,6 +454,7 @@ def disconnect(self): |
452 | 454 | self._web3 = None |
453 | 455 | self._host = None |
454 | 456 | super().disconnect() |
| 457 | + self._disconnected = True |
455 | 458 |
|
456 | 459 | def build_command(self) -> list[str]: |
457 | 460 | cmd = [ |
@@ -665,8 +668,8 @@ def set_storage(self, address: "AddressType", slot: int, value: HexBytes): |
665 | 668 | "anvil_setStorageAt", |
666 | 669 | [ |
667 | 670 | address, |
668 | | - to_hex(HashBytes32.__eth_pydantic_validate__(slot)), |
669 | | - to_hex(HashBytes32.__eth_pydantic_validate__(value)), |
| 671 | + to_hex(HexBytes32.__eth_pydantic_validate__(slot)), |
| 672 | + to_hex(HexBytes32.__eth_pydantic_validate__(value)), |
670 | 673 | ], |
671 | 674 | ) |
672 | 675 |
|
|
0 commit comments