Skip to content

Commit e3fc230

Browse files
committed
Update registry uri to support basic uris w/o package id
1 parent 36224cf commit e3fc230

File tree

4 files changed

+33
-10
lines changed

4 files changed

+33
-10
lines changed

ethpm/backends/registry.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ def parse_registry_uri(uri: str) -> RegistryURI:
8181
validate_registry_uri(uri)
8282
parsed_uri = parse.urlparse(uri)
8383
address, chain_id = parsed_uri.netloc.split(":")
84-
pkg_name = parsed_uri.path.strip("/")
85-
pkg_version = parsed_uri.query.lstrip("version=").strip("/")
84+
parsed_name = parsed_uri.path.strip("/")
85+
parsed_version = parsed_uri.query.lstrip("version=").strip("/")
86+
pkg_name = parsed_name if parsed_name else None
87+
pkg_version = parsed_version if parsed_version else None
8688
return RegistryURI(address, chain_id, pkg_name, pkg_version)

ethpm/validation/uri.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,21 @@ def validate_registry_uri(uri: str) -> None:
4747
Raise an exception if the URI does not conform to the registry URI scheme.
4848
"""
4949
parsed = parse.urlparse(uri)
50-
scheme, authority, pkg_name, query = (
50+
scheme, authority, pkg_path, version = (
5151
parsed.scheme,
5252
parsed.netloc,
5353
parsed.path,
5454
parsed.query,
5555
)
5656
validate_registry_uri_scheme(scheme)
5757
validate_registry_uri_authority(authority)
58-
if query:
59-
validate_registry_uri_version(query)
60-
validate_package_name(pkg_name[1:])
58+
pkg_name = pkg_path.lstrip("/")
59+
if pkg_name:
60+
validate_package_name(pkg_name)
61+
if not pkg_name and version:
62+
raise ValidationError("Registry URIs cannot provide a version without a package name.")
63+
if version:
64+
validate_registry_uri_version(version)
6165

6266

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

7680
if is_ens_domain(address) is False and not is_checksum_address(address):
7781
raise ValidationError(
78-
f"{auth} is not a valid registry address. "
82+
f"{address} is not a valid registry address. "
7983
"Please try again with a valid registry URI."
8084
)
8185

tests/ethpm/_utils/test_registry_utils.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111
@pytest.mark.parametrize(
1212
"uri",
1313
(
14-
("erc1319://zeppelinos.eth:1/erc20/"),
14+
# no package id in uri
15+
("erc1319://zeppelinos.eth:1"),
16+
("erc1319://zeppelinos.eth:1/"),
17+
("erc1319://packages.zeppelinos.eth:1"),
18+
("erc1319://packages.zeppelinos.eth:1/"),
19+
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1"),
20+
("erc1319://0xd3CdA913deB6f67967B99D67aCDFa1712C293601:1/"),
21+
# with package id in uri
1522
("erc1319://zeppelinos.eth:1/erc20/"),
1623
("erc1319://zeppelinos.eth:1/erc20//"),
1724
("erc1319://zeppelinos.eth:1/erc20?version=1.0.0"),
@@ -33,17 +40,19 @@ def test_is_registry_uri_validates(uri):
3340
"uri",
3441
(
3542
# invalid authority
43+
("erc1319://zeppelinos.eth"),
44+
("erc1319://zeppelinos.eth/"),
3645
("erc1319://zeppelinos.eth/erc20?version=1.0.0"),
3746
("erc1319://zeppelinos.eth:333/erc20?version=1.0.0"),
3847
("erc1319://packages.zeppelinos.com:1/erc20?version=1.0.0"),
3948
("erc1319://package.manager.zeppelinos.eth:1/erc20?version=1.0.0"),
4049
("erc1319://packageszeppelinoseth:1/erc20?version=1.0.0"),
4150
("erc1319://0xd3cda913deb6f67967b99d67acdfa1712c293601:1/erc20?version=1.0.0"),
4251
# invalid package name
43-
("erc1319://packages.zeppelinos.eth:1/"),
44-
("erc1319://packages.zeppelinos.eth:1///"),
4552
("erc1319://packages.zeppelinos.eth:1/?version=1.0.0"),
53+
("erc1319://packages.zeppelinos.eth:1/?version=1.0.0/"),
4654
("erc1319://packages.zeppelinos.eth:1/!rc20?version=1.0.0"),
55+
("erc1319://packages.zeppelinos.eth:1/!rc20?version=1.0.0/"),
4756
# invalid version param
4857
("erc1319://zeppelinos.eth:1/erc20?versions=1.0.0"),
4958
("erc1319://zeppelinos.eth:1/erc20?version1.0.0"),

tests/ethpm/test_uri.py

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ def test_create_github_uri():
7070
@pytest.mark.parametrize(
7171
"uri,expected",
7272
(
73+
(
74+
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1",
75+
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", None, None],
76+
),
77+
(
78+
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/owned",
79+
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", None],
80+
),
7381
(
7482
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/owned?version=1.0.0",
7583
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "owned", "1.0.0"],

0 commit comments

Comments
 (0)