diff --git a/src/ape/api/address.py b/src/ape/api/address.py index a5e399f4d6..7835c8f832 100644 --- a/src/ape/api/address.py +++ b/src/ape/api/address.py @@ -251,7 +251,7 @@ def prepare_transaction(self, txn: "TransactionAPI", **kwargs) -> "TransactionAP ): raise AccountsError( f"Transfer value meets or exceeds account balance " - f"for account '{self.address}' on chain '{self.provider.chain_id}' " + f"for account '{self.address}' on chain '{self.chain_manager.chain_id}' " f"using provider '{self.provider.name}'.\n" "Are you using the correct account / chain / provider combination?\n" f"(transfer_value={txn.total_transfer_value}, balance={self.balance})." diff --git a/src/ape/api/networks.py b/src/ape/api/networks.py index 490ad44aa8..d997ead271 100644 --- a/src/ape/api/networks.py +++ b/src/ape/api/networks.py @@ -1042,7 +1042,9 @@ def explorer(self) -> Optional["ExplorerAPI"]: Returns: :class:`ape.api.explorers.ExplorerAPI`, optional """ - chain_id = None if self.network_manager.active_provider is None else self.provider.chain_id + chain_id = ( + None if self.network_manager.active_provider is None else self.chain_manager.chain_id + ) for plugin_name, plugin_tuple in self._plugin_explorers: ecosystem_name, network_name, explorer_class = plugin_tuple diff --git a/src/ape/managers/_contractscache.py b/src/ape/managers/_contractscache.py index 69e526e77f..be719b7eca 100644 --- a/src/ape/managers/_contractscache.py +++ b/src/ape/managers/_contractscache.py @@ -421,7 +421,7 @@ def _get_errors( self, address: AddressType, chain_id: Optional[int] = None ) -> set[type[CustomError]]: if chain_id is None and self.network_manager.active_provider is not None: - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id elif chain_id is None: return set() @@ -438,7 +438,7 @@ def _cache_error( self, address: AddressType, error: type[CustomError], chain_id: Optional[int] = None ): if chain_id is None and self.network_manager.active_provider is not None: - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id elif chain_id is None: return diff --git a/src/ape/managers/chain.py b/src/ape/managers/chain.py index 3d72787f85..81c0231eb8 100644 --- a/src/ape/managers/chain.py +++ b/src/ape/managers/chain.py @@ -605,7 +605,6 @@ def revert_to_block(self, block_number: int): Args: block_number (int): The block number to revert to. """ - self._hash_to_receipt_map = { h: r for h, r in self._hash_to_receipt_map.items() if r.block_number <= block_number } @@ -821,7 +820,7 @@ def snapshot(self) -> "SnapshotID": Returns: :class:`~ape.types.SnapshotID`: The snapshot ID. """ - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id snapshot_id = self.provider.snapshot() if snapshot_id not in self._snapshots[chain_id]: self._snapshots[chain_id].append(snapshot_id) @@ -843,7 +842,7 @@ def restore(self, snapshot_id: Optional["SnapshotID"] = None): snapshot_id (Optional[:class:`~ape.types.SnapshotID`]): The snapshot ID. Defaults to the most recent snapshot ID. """ - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id if snapshot_id is None and not self._snapshots[chain_id]: raise ChainError("There are no snapshots to revert to.") elif snapshot_id is None: diff --git a/src/ape/pytest/fixtures.py b/src/ape/pytest/fixtures.py index e8ef000e63..704803a8fb 100644 --- a/src/ape/pytest/fixtures.py +++ b/src/ape/pytest/fixtures.py @@ -648,7 +648,7 @@ def restore_snapshot(self, scope: Scope): if snapshot_id is None: return - elif snapshot_id not in self.chain_snapshots[self.provider.chain_id]: + elif snapshot_id not in self.chain_snapshots[self.chain_manager.chain_id]: # Still clear out. self.snapshots.clear_snapshot_id(scope) return diff --git a/src/ape_accounts/accounts.py b/src/ape_accounts/accounts.py index a6547be8ab..698123c15c 100644 --- a/src/ape_accounts/accounts.py +++ b/src/ape_accounts/accounts.py @@ -174,7 +174,7 @@ def sign_authorization( nonce: Optional[int] = None, ) -> Optional[MessageSignature]: if chain_id is None: - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id display_msg = f"Allow **full root access** to '{address}' on {chain_id or 'any chain'}?" if not click.confirm(click.style(f"{display_msg}\n\nAcknowledge: ", fg="yellow")): @@ -294,7 +294,7 @@ def set_delegate(self, contract: Union[BaseAddress, AddressType, str], **txn_kwa sig = self.sign_authorization(contract_address, nonce=self.nonce + 1) auth = Authorization.from_signature( address=contract_address, - chain_id=self.provider.chain_id, + chain_id=self.chain_manager.chain_id, # NOTE: `tx` uses `self.nonce` nonce=self.nonce + 1, signature=sig, @@ -312,7 +312,7 @@ def set_delegate(self, contract: Union[BaseAddress, AddressType, str], **txn_kwa def remove_delegate(self, **txn_kwargs): sig = self.sign_authorization(ZERO_ADDRESS, nonce=self.nonce + 1) auth = Authorization.from_signature( - chain_id=self.provider.chain_id, + chain_id=self.chain_manager.chain_id, address=ZERO_ADDRESS, # NOTE: `tx` uses `self.nonce` nonce=self.nonce + 1, diff --git a/src/ape_ethereum/ecosystem.py b/src/ape_ethereum/ecosystem.py index 6c64dbe7c5..219eba62b5 100644 --- a/src/ape_ethereum/ecosystem.py +++ b/src/ape_ethereum/ecosystem.py @@ -963,7 +963,7 @@ def create_transaction(self, **kwargs) -> "TransactionAPI": tx_data["chainId"] = int(chain_id, 16) elif chain_id is None and self.network_manager.active_provider is not None: - tx_data["chainId"] = self.provider.chain_id + tx_data["chainId"] = self.chain_manager.chain_id if "input" in tx_data: tx_data["data"] = tx_data.pop("input") diff --git a/src/ape_ethereum/multicall/handlers.py b/src/ape_ethereum/multicall/handlers.py index b0b5602af2..9b882f682f 100644 --- a/src/ape_ethereum/multicall/handlers.py +++ b/src/ape_ethereum/multicall/handlers.py @@ -66,8 +66,8 @@ def use_multicall(): provider = cls.network_manager.provider provider.set_code(MULTICALL3_ADDRESS, MULTICALL3_CODE) - if provider.chain_id not in SUPPORTED_CHAINS: - SUPPORTED_CHAINS.append(provider.chain_id) + if cls.chain_manager.chain_id not in SUPPORTED_CHAINS: + SUPPORTED_CHAINS.append(cls.chain_manager.chain_id) return multicall @@ -85,7 +85,10 @@ def contract(self) -> ContractInstance: contract_type=ContractType.model_validate(MULTICALL3_CONTRACT_TYPE), ) - if self.provider.chain_id not in self.supported_chains and contract.code != MULTICALL3_CODE: + if ( + self.chain_manager.chain_id not in self.supported_chains + and contract.code != MULTICALL3_CODE + ): # NOTE: 2nd condition allows for use in local test deployments and fork networks raise UnsupportedChainError() diff --git a/src/ape_test/accounts.py b/src/ape_test/accounts.py index ecc618ed4d..219e4cb822 100644 --- a/src/ape_test/accounts.py +++ b/src/ape_test/accounts.py @@ -134,7 +134,7 @@ def sign_authorization( nonce: Optional[int] = None, ) -> Optional[MessageSignature]: if chain_id is None: - chain_id = self.provider.chain_id + chain_id = self.chain_manager.chain_id try: signed_authorization = EthAccount.sign_authorization( @@ -222,7 +222,7 @@ def set_delegate(self, contract: Union[BaseAddress, AddressType, str], **txn_kwa sig = self.sign_authorization(contract_address, nonce=self.nonce + 1) auth = Authorization.from_signature( address=contract_address, - chain_id=self.provider.chain_id, + chain_id=self.chain_manager.chain_id, # NOTE: `tx` uses `self.nonce` nonce=self.nonce + 1, signature=sig, @@ -240,7 +240,7 @@ def set_delegate(self, contract: Union[BaseAddress, AddressType, str], **txn_kwa def remove_delegate(self, **txn_kwargs): sig = self.sign_authorization(ZERO_ADDRESS, nonce=self.nonce + 1) auth = Authorization.from_signature( - chain_id=self.provider.chain_id, + chain_id=self.chain_manager.chain_id, address=ZERO_ADDRESS, # NOTE: `tx` uses `self.nonce` nonce=self.nonce + 1, diff --git a/tests/functional/test_trace.py b/tests/functional/test_trace.py index 5a46119fbf..44c440a591 100644 --- a/tests/functional/test_trace.py +++ b/tests/functional/test_trace.py @@ -246,6 +246,8 @@ def test_transaction_trace_provider_does_not_implement_client_version( mock_weird_node = mocker.MagicMock() mock_weird_node.client_version.side_effect = AttributeError mock_weird_node.network = ethereum.local + mock_weird_node.chain_id = chain.chain_id + mock_weird_node.get_block.side_effect = chain.provider.get_block class HackyTransactionTrace(TransactionTrace): def _discover_calltrace_approach(self) -> CallTreeNode: