diff --git a/ape_addressbook/addressbook.py b/ape_addressbook/addressbook.py index 9e5c5ef..c30adbe 100644 --- a/ape_addressbook/addressbook.py +++ b/ape_addressbook/addressbook.py @@ -26,12 +26,16 @@ def _validate_entries(entries: Dict) -> Dict: class AddressBookConfig(PluginConfig): - __root__: Dict[str, AddressType] = {} - @root_validator(pre=True) def validate_entries(cls, entries): return _validate_entries(entries) + def __len__(self) -> int: + return len(self.dict()) + + class Config: + extra = "allow" + class AddressBook(ManagerAccessMixin): """ @@ -67,7 +71,10 @@ def registry(self) -> Dict[str, AddressType]: and project addresses. """ - return self.config.dict() + data = self.config.dict() + + # Sorted for consistency's sake. + return {k: data[k] for k in sorted(data)} @property def aliases(self) -> Iterator[str]: @@ -75,6 +82,7 @@ def aliases(self) -> Iterator[str]: An iterator over all aliases in the registry. """ + # NOTE: self.registry is sorted. for alias in self.registry: yield alias diff --git a/setup.py b/setup.py index 57c75b8..0839db1 100644 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ include_package_data=True, install_requires=[ "eth-ape>=0.6.0,<0.7", - "pydantic<2", + "pydantic", # Use same version as eth-ape. ], python_requires=">=3.8,<4", extras_require=extras_require, diff --git a/tests/test_addressbook.py b/tests/test_addressbook.py index 21170e7..d112bf0 100644 --- a/tests/test_addressbook.py +++ b/tests/test_addressbook.py @@ -29,10 +29,9 @@ def test_aliases(project_alias_unchecksummed, project_alias_no_quotes): The aliases includes both project and global addresses. """ - assert list(addressbook.aliases) == [ - project_alias_unchecksummed, - project_alias_no_quotes, - ] + actual = list(addressbook.aliases) + expected = [project_alias_no_quotes, project_alias_unchecksummed] + assert actual == expected def test_contains(