diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d65e090..8d1f728 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -62,7 +62,7 @@ jobs: # TODO: Replace with macos-latest when works again. # https://github.com/actions/setup-python/issues/808 os: [ubuntu-latest, macos-12] # eventually add `windows-latest` - python-version: [3.8, 3.9, "3.10", "3.11", "3.12"] + python-version: [3.9, "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v4 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3919289..a35de4c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,7 +30,7 @@ repos: rev: 0.7.17 hooks: - id: mdformat - additional_dependencies: [mdformat-gfm, mdformat-frontmatter] + additional_dependencies: [mdformat-gfm, mdformat-frontmatter, mdformat-pyproject] default_language_version: python: python3 diff --git a/README.md b/README.md index 0e58cc8..c58d67b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Ape plugin that allows tracking addresses and contracts in projects and globally ## Dependencies -- [python3](https://www.python.org/downloads) version 3.8 up to 3.12. +- [python3](https://www.python.org/downloads) version 3.9 up to 3.12. ## Installation diff --git a/ape_addressbook/addressbook.py b/ape_addressbook/addressbook.py index 461d653..8cef27b 100644 --- a/ape_addressbook/addressbook.py +++ b/ape_addressbook/addressbook.py @@ -1,4 +1,5 @@ -from typing import Dict, Iterator, cast +from collections.abc import Iterator +from typing import cast from ape.api import PluginConfig from ape.logging import logger @@ -9,8 +10,8 @@ from pydantic_settings import SettingsConfigDict -def _validate_entries(entries: Dict) -> Dict: - validated: Dict[str, AddressType] = {} +def _validate_entries(entries: dict) -> dict: + validated: dict[str, AddressType] = {} for k, v in entries.items(): # Attempt to handle EVM-like addresses but if it fails, # let it be in case it is for a more unique ecosystem. @@ -66,7 +67,7 @@ def config(self) -> AddressBookConfig: return cast(AddressBookConfig, config_obj) @property - def registry(self) -> Dict[str, AddressType]: + def registry(self) -> dict[str, AddressType]: """ The complete registry of addresses, including both global and project addresses. diff --git a/pyproject.toml b/pyproject.toml index 9e11ac7..8013e27 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ write_to = "ape_addressbook/version.py" [tool.black] line-length = 100 -target-version = ['py38', 'py39', 'py310', 'py311', 'py312'] +target-version = ['py39', 'py310', 'py311', 'py312'] include = '\.pyi?$' [tool.pytest.ini_options] diff --git a/setup.py b/setup.py index a279739..77bd034 100644 --- a/setup.py +++ b/setup.py @@ -60,11 +60,11 @@ url="https://github.com/ApeWorX/ape-addressbook", include_package_data=True, install_requires=[ - "eth-ape>=0.7.0,<0.8", + "eth-ape>=0.8.1,<0.9", "pydantic", # Use same version as eth-ape. "pydantic-settings", # Use same version as eth-ape. ], - python_requires=">=3.8,<4", + python_requires=">=3.9,<4", extras_require=extras_require, py_modules=["ape_addressbook"], license="Apache-2.0", @@ -80,7 +80,6 @@ "Operating System :: MacOS", "Operating System :: POSIX", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", diff --git a/tests/conftest.py b/tests/conftest.py index e58c38f..54ddd2f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,46 +1,22 @@ -import tempfile -from pathlib import Path - import ape import pytest -from ape.managers.config import CONFIG_FILE_NAME from eth_utils import to_checksum_address PROJECT_ALIAS_UNCHECKSUMMED = "project_entry_quotes" -PROJECT_ALIAS_NO_QUOTES = "project_entry_no_quotes" +PROJECT_ALIAS_INT = "project_entry_no_quotes" PROJECT_ADDRESS_NON_CHECKSUMMED = "0xbc8563cb0eedbd1b95ccafd0c156e2daf5e18c29" PROJECT_ADDRESS = to_checksum_address(PROJECT_ADDRESS_NON_CHECKSUMMED) - -APE_CONFIG = rf""" -addressbook: +CONFIG_ADDRESSBOOK = { # This address purposely is not checksummed. - {PROJECT_ALIAS_UNCHECKSUMMED}: '{PROJECT_ADDRESS_NON_CHECKSUMMED}' - - # This address is read-in as an int since it has no quotes. - {PROJECT_ALIAS_NO_QUOTES}: {PROJECT_ADDRESS} -""" + PROJECT_ALIAS_UNCHECKSUMMED: PROJECT_ADDRESS_NON_CHECKSUMMED, + PROJECT_ALIAS_INT: int(PROJECT_ADDRESS, 16), +} @pytest.fixture(autouse=True, scope="session") -def madeup_project(): - """ - Prevents actually affecting global addressbook - and sets a temporary project. - """ - - with tempfile.TemporaryDirectory() as temp_dir: - # Create the config file with address entries. - path = Path(temp_dir) - config_file = path / CONFIG_FILE_NAME - config_file.touch() - config_file.write_text(APE_CONFIG) - - with ape.config.using_project(path): - yield - - # Clean up. - if config_file.is_file(): - config_file.unlink() +def project(): + with ape.project.temp_config(addressbook=CONFIG_ADDRESSBOOK): + yield ape.project @pytest.fixture @@ -49,8 +25,8 @@ def project_alias_unchecksummed(): @pytest.fixture -def project_alias_no_quotes(): - return PROJECT_ALIAS_NO_QUOTES +def project_alias_int(): + return PROJECT_ALIAS_INT @pytest.fixture diff --git a/tests/test_addressbook.py b/tests/test_addressbook.py index d112bf0..43a1295 100644 --- a/tests/test_addressbook.py +++ b/tests/test_addressbook.py @@ -1,7 +1,7 @@ from ape_addressbook import addressbook -def test_config(project_alias_unchecksummed, project_alias_no_quotes, project_address): +def test_config(project_alias_unchecksummed, project_alias_int, project_address): """ This test shows that we are able to read values from a project's config as well as handle checksumming them if needbe. @@ -10,42 +10,31 @@ def test_config(project_alias_unchecksummed, project_alias_no_quotes, project_ad actual = addressbook.config assert len(actual) == 2 assert actual[project_alias_unchecksummed] == project_address - assert actual[project_alias_no_quotes] == project_address + assert actual[project_alias_int] == project_address -def test_registry( - project_alias_unchecksummed, - project_alias_no_quotes, - project_address, -): +def test_registry(project_alias_unchecksummed, project_alias_int, project_address): actual = addressbook.registry assert len(actual) == 2 assert actual[project_alias_unchecksummed] == project_address - assert actual[project_alias_no_quotes] == project_address + assert actual[project_alias_int] == project_address -def test_aliases(project_alias_unchecksummed, project_alias_no_quotes): +def test_aliases(project_alias_unchecksummed, project_alias_int): """ The aliases includes both project and global addresses. """ actual = list(addressbook.aliases) - expected = [project_alias_no_quotes, project_alias_unchecksummed] + expected = [project_alias_int, project_alias_unchecksummed] assert actual == expected -def test_contains( - project_alias_unchecksummed, - project_alias_no_quotes, -): +def test_contains(project_alias_unchecksummed, project_alias_int): assert project_alias_unchecksummed in addressbook - assert project_alias_no_quotes in addressbook + assert project_alias_int in addressbook -def test_get_item( - project_alias_unchecksummed, - project_address, - project_alias_no_quotes, -): +def test_get_item(project_alias_unchecksummed, project_address, project_alias_int): assert addressbook[project_alias_unchecksummed] == project_address - assert addressbook[project_alias_no_quotes] == project_address + assert addressbook[project_alias_int] == project_address