Skip to content

Commit

Permalink
refactor: pydantic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
NotPeopling2day committed Dec 19, 2023
1 parent a6d6e6e commit ee32872
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
13 changes: 7 additions & 6 deletions ape_alchemy/provider.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
from typing import Any, Dict, Optional
from typing import Any, Dict, List, Optional

from ape.api import ReceiptAPI, TransactionAPI, UpstreamProvider, Web3Provider
from ape.api import ReceiptAPI, TransactionAPI, UpstreamProvider
from ape.exceptions import (
APINotImplementedError,
ContractLogicError,
Expand All @@ -10,8 +10,9 @@
)
from ape.logging import logger
from ape.types import CallTreeNode
from ape_ethereum.provider import Web3Provider
from eth_pydantic_types import HexBytes
from eth_typing import HexStr
from ethpm_types import HexBytes
from evm_trace import (
ParityTraceList,
get_calltree_from_geth_call_trace,
Expand Down Expand Up @@ -132,7 +133,7 @@ def get_call_tree(self, txn_hash: str) -> CallTreeNode:

def _get_calltree_using_parity_style(self, txn_hash: str) -> CallTreeNode:
raw_trace_list = self._make_request("trace_transaction", [txn_hash])
trace_list = ParityTraceList.parse_obj(raw_trace_list)
trace_list = ParityTraceList.model_validate(raw_trace_list)
evm_call = get_calltree_from_parity_trace(trace_list)
return self._create_call_tree_node(evm_call)

Expand Down Expand Up @@ -178,11 +179,11 @@ def get_virtual_machine_error(self, exception: Exception, **kwargs) -> VirtualMa

return VirtualMachineError(message=message, txn=txn)

def _make_request(self, endpoint: str, parameters: list) -> Any:
def _make_request(self, endpoint: str, parameters: Optional[List] = None) -> Any:
try:
return super()._make_request(endpoint, parameters)
except HTTPError as err:
response_data = err.response.json()
response_data = err.response.json() if err.response else {}
if "error" not in response_data:
raise AlchemyProviderError(str(err)) from err

Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,14 @@ def networks():


@pytest.fixture
def missing_token(mocker):
def missing_token(alchemy_provider, mocker):
env = os.environ.copy()
mock = mocker.patch("os.environ.get")

def side_effect(key, *args, **kwargs):
return None if "WEB3" in key else env.get(key, *args, **kwargs)

alchemy_provider.network_uris = {}
mock.side_effect = side_effect
return mock

Expand Down

0 comments on commit ee32872

Please sign in to comment.