Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Ape 0.8 target #18

Merged
merged 5 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 5 additions & 4 deletions ape_addressbook/addressbook.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
44 changes: 10 additions & 34 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
31 changes: 10 additions & 21 deletions tests/test_addressbook.py
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
Loading