Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 1ba2081

Browse files
Merge pull request #1 from beemeeupnow/touchups
Miscellaneous touchups
2 parents bd40893 + 6c7dc97 commit 1ba2081

File tree

7 files changed

+40
-39
lines changed

7 files changed

+40
-39
lines changed

alchemy_sdk_py/alchemy.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import requests
2+
import time
13
from datetime import datetime
2-
from typing import Optional, Tuple, Union
4+
from typing import List, Optional, Tuple, Union
35
from .errors import NO_API_KEY_ERROR
4-
from .networks import Network
5-
from .utils import HexIntStringNumber, ETH_NULL_VALUE, is_hash, is_hex_int
66
from .evm_node import POSSIBLE_BLOCK_TAGS, EVM_Node, HEADERS
7-
import requests
8-
import time
7+
from .networks import Network
8+
from .utils import HexIntStringNumber, ETH_NULL_VALUE, is_hash
99

1010
NFT_FILTERS = ["SPAM", "AIRDROPS"]
1111

@@ -156,7 +156,7 @@ def _get_all_asset_transfers(
156156
from_block: Union[int, str, None] = 0,
157157
to_block: Union[int, str, None] = None,
158158
contract_addresses: Optional[list] = None,
159-
category: Optional[list[str]] = [
159+
category: Optional[List[str]] = [
160160
"external",
161161
"internal",
162162
"erc20",
@@ -202,7 +202,7 @@ def get_asset_transfers(
202202
max_count: Union[int, str, None] = 1000,
203203
page_key: Optional[str] = None,
204204
contract_addresses: Optional[list] = None,
205-
category: Optional[list[str]] = [
205+
category: Optional[List[str]] = [
206206
"external",
207207
"internal",
208208
"erc20",
@@ -433,7 +433,7 @@ def base_fee_per_gas(self) -> int:
433433
def get_token_balances(
434434
self,
435435
address: str,
436-
token_addresses_or_type: Union[list[str], str, None] = None,
436+
token_addresses_or_type: Union[List[str], str, None] = None,
437437
options_or_page_key: Union[dict, str, None] = None,
438438
) -> dict:
439439
"""
@@ -520,10 +520,10 @@ def get_nfts_for_owner(
520520
owner: str,
521521
page_key: Optional[str] = None,
522522
page_size: Optional[int] = 100,
523-
contract_addresses: Optional[list[str]] = None,
523+
contract_addresses: Optional[List[str]] = None,
524524
omit_metadata: Optional[bool] = False,
525525
token_uri_timeout_in_ms: Union[int, None] = None,
526-
filters: Optional[list[str]] = None,
526+
filters: Optional[List[str]] = None,
527527
) -> dict:
528528
"""Gets all NFTs currently owned by a given address.
529529
@@ -553,11 +553,11 @@ def get_nfts(
553553
owner: str,
554554
page_key: Optional[str] = None,
555555
page_size: Optional[int] = 100,
556-
contract_addresses: Optional[list[str]] = None,
556+
contract_addresses: Optional[List[str]] = None,
557557
with_metadata: Optional[bool] = False,
558558
token_uri_timeout_in_ms: Union[int, None] = None,
559-
exclude_filters: Optional[list[str]] = None,
560-
include_filters: Optional[list[str]] = None,
559+
exclude_filters: Optional[List[str]] = None,
560+
include_filters: Optional[List[str]] = None,
561561
order_by: Optional[str] = None,
562562
) -> dict:
563563
"""Gets all NFTs currently owned by a given address.
@@ -691,8 +691,8 @@ def get_contracts_for_owner(
691691
owner: str,
692692
page_key: Optional[str] = None,
693693
page_size: Optional[int] = 100,
694-
include_filters: Optional[list[str]] = None,
695-
exclude_filters: Optional[list[str]] = None,
694+
include_filters: Optional[List[str]] = None,
695+
exclude_filters: Optional[List[str]] = None,
696696
order_by: Optional[str] = None,
697697
) -> dict:
698698
"""Gets all contracts for a given owner.
@@ -701,8 +701,8 @@ def get_contracts_for_owner(
701701
owner (str): Owner address to check
702702
page_key (Optional[str], optional): Page key to get the next page of results. Defaults to None.
703703
page_size (Optional[int], optional): Page size to get the next page of results. Defaults to 100.
704-
include_filters (Optional[list[str]], optional): Optional list of strings from "SPAM" and "AIRDROPS". Defaults to None.
705-
exclude_filters (Optional[list[str]], optional): Optional list of strings from "SPAM" and "AIRDROPS". Defaults to None.
704+
include_filters (Optional[List[str]], optional): Optional list of strings from "SPAM" and "AIRDROPS". Defaults to None.
705+
exclude_filters (Optional[List[str]], optional): Optional list of strings from "SPAM" and "AIRDROPS". Defaults to None.
706706
order_by (Optional[str], optional): Optional string to order by "transferTime" or None. Defaults to None.
707707
708708
Returns:
@@ -956,7 +956,7 @@ def compute_rarity(self, contract_address: str, token_id: Union[str, int]) -> di
956956
return json_response
957957

958958
def verify_nft_ownership(
959-
self, wallet_address: str, contract_addresses: Union[str, list[str]]
959+
self, wallet_address: str, contract_addresses: Union[str, List[str]]
960960
) -> dict:
961961
"""Verifies if a wallet owns a given NFT.
962962

alchemy_sdk_py/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
def NETWORK_INITIALIZATION_ERROR(network_id_map):
1414
str = (
15-
"Network has been given a poor name or chain ID."
15+
"Network has been given a poor name or chain ID. "
1616
f"Please use one of the following options: {network_id_map.keys()}"
1717
)
1818
return str

alchemy_sdk_py/evm_node.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
2-
from typing import Optional, Union
3-
from alchemy_sdk_py.utils import HexIntStringNumber, is_hash
4-
from .errors import NO_API_KEY_ERROR
5-
from .networks import Network
62
import requests
73
from dotenv import load_dotenv
4+
from typing import List, Optional, Union
5+
from .utils import HexIntStringNumber
6+
from .errors import NO_API_KEY_ERROR
7+
from .networks import Network
88

99
load_dotenv()
1010

@@ -711,7 +711,7 @@ def get_gas_price(self) -> int:
711711
return self.gas_price()
712712

713713
# Unsupported by Alchemy
714-
# def get_compilers(self) -> list[str]:
714+
# def get_compilers(self) -> List[str]:
715715
# """
716716
# params:
717717
# None
@@ -729,7 +729,7 @@ def get_gas_price(self) -> int:
729729
# return result
730730

731731
# Unsupported by Alchemy
732-
# def get_work(self) -> list[str]:
732+
# def get_work(self) -> List[str]:
733733
# """
734734
# params:
735735
# None
@@ -749,7 +749,7 @@ def get_gas_price(self) -> int:
749749
def get_logs(
750750
self,
751751
contract_address: str,
752-
topics: Union[list[str], str],
752+
topics: Union[List[str], str],
753753
from_block: Union[str, int, None] = 0,
754754
to_block: Union[str, int, None] = "latest",
755755
) -> list:
@@ -758,7 +758,7 @@ def get_logs(
758758
def get_events(
759759
self,
760760
contract_address: str,
761-
topics: Union[list[str], str],
761+
topics: Union[List[str], str],
762762
from_block: Union[str, int, None] = 0,
763763
to_block: Union[str, int, None] = "latest",
764764
) -> list:

alchemy_sdk_py/networks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from .errors import NETWORK_INITIALIZATION_ERROR
21
from typing import Union
2+
from .errors import NETWORK_INITIALIZATION_ERROR
33

44
network_id_map = {
55
"eth_mainnet": "1",

requirements.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
certifi==2022.12.7
2-
charset-normalizer==2.1.1
3-
idna==3.4
4-
requests==2.28.1
5-
urllib3==1.26.13
6-
python-dotenv==0.21.0
1+
certifi>=2022.12.7
2+
charset-normalizer~=2.1.1
3+
idna~=3.4
4+
requests~=2.28.1
5+
urllib3~=1.26.13
6+
python-dotenv~=0.21.0

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def alchemy_with_key() -> Alchemy:
2121

2222
@pytest.fixture
2323
def mock_env_missing(monkeypatch: MonkeyPatch):
24-
"""A plugin from pytest to help saftely mock and delete environment variables.
24+
"""A plugin from pytest to help safely mock and delete environment variables.
2525
2626
Args:
2727
monkeypatch (_pytest.monkeypatch.MonkeyPatch): _description_

tests/integration/test_alchemy_setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from alchemy_sdk_py import Alchemy
2-
import pytest
31
import os
2+
import pytest
3+
from alchemy_sdk_py import Alchemy
4+
from _pytest.monkeypatch import MonkeyPatch
45

56

67
def test_initialize_empty_network(dummy_api_key, mock_env_missing):
@@ -38,8 +39,8 @@ def test_api_key_property(dummy_api_key):
3839
assert alchemy.key == dummy_api_key
3940

4041

41-
def test_key_with_environment_variable():
42+
def test_key_with_environment_variable(monkeypatch: MonkeyPatch):
4243
test_key = "test_key"
43-
os.environ["ALCHEMY_API_KEY"] = test_key
44+
monkeypatch.setenv("ALCHEMY_API_KEY", test_key)
4445
alchemy = Alchemy()
4546
assert alchemy.key == test_key

0 commit comments

Comments
 (0)