33import shutil
44from bisect import bisect_right
55from subprocess import PIPE , call
6- from typing import Literal , Optional , Union , cast
6+ from typing import TYPE_CHECKING , Literal , Optional , Union , cast
77
88from ape .api import (
99 BlockAPI ,
2323 VirtualMachineError ,
2424)
2525from ape .logging import logger
26- from ape .types import AddressType , BlockID , ContractCode , SnapshotID
2726from ape .utils import cached_property
2827from ape_ethereum .provider import Web3Provider
2928from ape_ethereum .trace import TraceApproach , TransactionTrace
5453except ImportError :
5554 Optimism = None # type: ignore
5655
56+ if TYPE_CHECKING :
57+ from ape .types import AddressType , BlockID , ContractCode , SnapshotID
58+
59+
5760EPHEMERAL_PORTS_START = 49152
5861EPHEMERAL_PORTS_END = 60999
5962DEFAULT_PORT = 8545
@@ -136,7 +139,7 @@ class FoundryProvider(SubprocessProvider, Web3Provider, TestProviderAPI):
136139 _did_warn_wrong_node = False
137140
138141 @property
139- def unlocked_accounts (self ) -> list [AddressType ]:
142+ def unlocked_accounts (self ) -> list [" AddressType" ]:
140143 return list (self .account_manager .test_accounts ._impersonated_accounts )
141144
142145 @property
@@ -485,7 +488,7 @@ def build_command(self) -> list[str]:
485488
486489 return cmd
487490
488- def set_balance (self , account : AddressType , amount : Union [int , float , str , bytes ]):
491+ def set_balance (self , account : " AddressType" , amount : Union [int , float , str , bytes ]):
489492 is_str = isinstance (amount , str )
490493 is_key_word = is_str and " " in amount # type: ignore
491494 _is_hex = is_str and not is_key_word and amount .startswith ("0x" ) # type: ignore
@@ -516,19 +519,19 @@ def mine(self, num_blocks: int = 1):
516519 def snapshot (self ) -> str :
517520 return self .make_request ("evm_snapshot" , [])
518521
519- def restore (self , snapshot_id : SnapshotID ) -> bool :
522+ def restore (self , snapshot_id : " SnapshotID" ) -> bool :
520523 snapshot_id = to_hex (snapshot_id ) if isinstance (snapshot_id , int ) else snapshot_id
521524 result = self .make_request ("evm_revert" , [snapshot_id ])
522525 return result is True
523526
524- def unlock_account (self , address : AddressType ) -> bool :
527+ def unlock_account (self , address : " AddressType" ) -> bool :
525528 self .make_request ("anvil_impersonateAccount" , [address ])
526529 return True
527530
528- def relock_account (self , address : AddressType ):
531+ def relock_account (self , address : " AddressType" ):
529532 self .make_request ("anvil_stopImpersonatingAccount" , [address ])
530533
531- def get_balance (self , address : AddressType , block_id : Optional [BlockID ] = None ) -> int :
534+ def get_balance (self , address : " AddressType" , block_id : Optional [" BlockID" ] = None ) -> int :
532535 if result := self .make_request ("eth_getBalance" , [address , block_id ]):
533536 return int (result , 16 ) if isinstance (result , str ) else result
534537
@@ -645,7 +648,7 @@ def _extract_custom_error(self, **kwargs) -> str:
645648 def set_block_gas_limit (self , gas_limit : int ) -> bool :
646649 return self .make_request ("evm_setBlockGasLimit" , [hex (gas_limit )]) is True
647650
648- def set_code (self , address : AddressType , code : ContractCode ) -> bool :
651+ def set_code (self , address : " AddressType" , code : " ContractCode" ) -> bool :
649652 if isinstance (code , bytes ):
650653 code = code .hex ()
651654
@@ -658,7 +661,7 @@ def set_code(self, address: AddressType, code: ContractCode) -> bool:
658661 self .make_request ("anvil_setCode" , [address , code ])
659662 return True
660663
661- def set_storage (self , address : AddressType , slot : int , value : HexBytes ):
664+ def set_storage (self , address : " AddressType" , slot : int , value : HexBytes ):
662665 self .make_request (
663666 "anvil_setStorageAt" ,
664667 [
@@ -712,7 +715,7 @@ def evm_version(self) -> Optional[str]:
712715
713716 return self .settings .evm_version
714717
715- def get_block (self , block_id : BlockID ) -> BlockAPI :
718+ def get_block (self , block_id : " BlockID" ) -> BlockAPI :
716719 if isinstance (block_id , str ) and block_id .isnumeric ():
717720 block_id = int (block_id )
718721
0 commit comments