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

[ethPM] Update registry uri to support basic uris w/o package id #1389

Merged
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
6 changes: 4 additions & 2 deletions ethpm/backends/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ def parse_registry_uri(uri: str) -> RegistryURI:
validate_registry_uri(uri)
parsed_uri = parse.urlparse(uri)
address, chain_id = parsed_uri.netloc.split(":")
pkg_name = parsed_uri.path.strip("/")
pkg_version = parsed_uri.query.lstrip("version=").strip("/")
parsed_name = parsed_uri.path.strip("/")
parsed_version = parsed_uri.query.lstrip("version=").strip("/")
pkg_name = parsed_name if parsed_name else None
pkg_version = parsed_version if parsed_version else None
return RegistryURI(address, chain_id, pkg_name, pkg_version)
14 changes: 9 additions & 5 deletions ethpm/validation/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,21 @@ def validate_registry_uri(uri: str) -> None:
Raise an exception if the URI does not conform to the registry URI scheme.
"""
parsed = parse.urlparse(uri)
scheme, authority, pkg_name, query = (
scheme, authority, pkg_path, version = (
parsed.scheme,
parsed.netloc,
parsed.path,
parsed.query,
)
validate_registry_uri_scheme(scheme)
validate_registry_uri_authority(authority)
if query:
validate_registry_uri_version(query)
validate_package_name(pkg_name[1:])
pkg_name = pkg_path.lstrip("/")
if pkg_name:
validate_package_name(pkg_name)
if not pkg_name and version:
raise ValidationError("Registry URIs cannot provide a version without a package name.")
if version:
validate_registry_uri_version(version)


def validate_registry_uri_authority(auth: str) -> None:
Expand All @@ -75,7 +79,7 @@ def validate_registry_uri_authority(auth: str) -> None:

if is_ens_domain(address) is False and not is_checksum_address(address):
raise ValidationError(
f"{auth} is not a valid registry address. "
f"{address} is not a valid registry address. "
"Please try again with a valid registry URI."
)

Expand Down
15 changes: 12 additions & 3 deletions tests/ethpm/_utils/test_registry_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,14 @@
@pytest.mark.parametrize(
"uri",
(
("erc1319://zeppelinos.eth:1/erc20/"),
# no package id in uri
("erc1319://zeppelinos.eth:1"),
("erc1319://zeppelinos.eth:1/"),
("erc1319://packages.zeppelinos.eth:1"),
("erc1319://packages.zeppelinos.eth:1/"),
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1"),
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/"),
# with package id in uri
("erc1319://zeppelinos.eth:1/erc20/"),
("erc1319://zeppelinos.eth:1/erc20//"),
("erc1319://zeppelinos.eth:1/erc20?version=1.0.0"),
Expand All @@ -33,17 +40,19 @@ def test_is_registry_uri_validates(uri):
"uri",
(
# invalid authority
("erc1319://zeppelinos.eth"),
("erc1319://zeppelinos.eth/"),
("erc1319://zeppelinos.eth/erc20?version=1.0.0"),
("erc1319://zeppelinos.eth:333/erc20?version=1.0.0"),
("erc1319://packages.zeppelinos.com:1/erc20?version=1.0.0"),
("erc1319://package.manager.zeppelinos.eth:1/erc20?version=1.0.0"),
("erc1319://packageszeppelinoseth:1/erc20?version=1.0.0"),
("erc1319://0xd3cda913deb6f67967b99d67acdfa1712c293601:1/erc20?version=1.0.0"),
# invalid package name
("erc1319://packages.zeppelinos.eth:1/"),
("erc1319://packages.zeppelinos.eth:1///"),
("erc1319://packages.zeppelinos.eth:1/?version=1.0.0"),
("erc1319://packages.zeppelinos.eth:1/?version=1.0.0/"),
("erc1319://packages.zeppelinos.eth:1/!rc20?version=1.0.0"),
("erc1319://packages.zeppelinos.eth:1/!rc20?version=1.0.0/"),
# invalid version param
("erc1319://zeppelinos.eth:1/erc20?versions=1.0.0"),
("erc1319://zeppelinos.eth:1/erc20?version1.0.0"),
Expand Down
8 changes: 8 additions & 0 deletions tests/ethpm/test_uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ def test_create_github_uri():
@pytest.mark.parametrize(
"uri,expected",
(
(
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1",
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", None, None],
),
(
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/owned",
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", None],
),
(
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/owned?version=1.0.0",
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", "1.0.0"],
Expand Down