-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ability to get conversion classes by name (#2497)
- Loading branch information
Showing
4 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import pytest | ||
|
||
from ape.managers.converters import ( | ||
AddressAPIConverter, | ||
BytesAddressConverter, | ||
HexConverter, | ||
HexIntConverter, | ||
IntAddressConverter, | ||
StringDecimalConverter, | ||
StringIntConverter, | ||
) | ||
from ape.types.address import AddressType | ||
from ape.utils.basemodel import ManagerAccessMixin | ||
from ape_ethereum._converters import WeiConversions | ||
|
||
NAME_TO_CONVERTER = { | ||
"AddressAPI": AddressAPIConverter, | ||
"BytesAddress": BytesAddressConverter, | ||
"hex": HexConverter, | ||
"HexInt": HexIntConverter, | ||
"IntAddress": IntAddressConverter, | ||
"StringDecimal": StringDecimalConverter, | ||
"StringInt": StringIntConverter, | ||
"wei": WeiConversions, | ||
} | ||
|
||
|
||
@pytest.fixture | ||
def conversion_manager(): | ||
return ManagerAccessMixin.conversion_manager | ||
|
||
|
||
@pytest.mark.parametrize("name", NAME_TO_CONVERTER) | ||
def test_get_converter(name, conversion_manager): | ||
actual = conversion_manager.get_converter(name) | ||
expected = NAME_TO_CONVERTER[name] | ||
assert isinstance(actual, expected) | ||
|
||
|
||
def test_get_converters_by_type(conversion_manager): | ||
converters = conversion_manager.get_converters_by_type(AddressType) | ||
for expected in (AddressAPIConverter, IntAddressConverter, BytesAddressConverter): | ||
assert any(isinstance(c, expected) for c in converters) |