forked from ethereum/web3.py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_uri.py
96 lines (87 loc) · 3.16 KB
/
test_uri.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import pytest
from ethpm.backends.http import (
is_valid_api_github_uri,
)
from ethpm.backends.registry import (
parse_registry_uri,
)
from ethpm.uri import (
create_content_addressed_github_uri,
is_valid_content_addressed_github_uri,
)
@pytest.mark.parametrize(
"uri,expected",
(
({}, False),
(123, False),
("xxx", False),
# invalid scheme
("api.github.com/repos/contents/path", False),
("http://api.github.com/repos/contents/path", False),
# invalid authority
("http://raw.githubusercontent.com/repos/contents/path", False),
("https://github.com/repos/contents/path", False),
# invalid path
("https://api.github.com", False),
("https://api.github.com/", False),
("https://api.github.com/contents/", False),
("https://api.github.com/repos/", False),
# valid github urls
("https://api.github.com/repos/contents/path", True),
(
"https://api.github.com/repos/ethpm/ethpm-spec/contents/examples/owned/contracts/Owned.sol", # noqa: E501
True,
),
),
)
def test_is_valid_github_uri(uri, expected):
actual = is_valid_api_github_uri(uri)
assert actual is expected
@pytest.mark.parametrize(
"uri,expected",
(
(
"https://api.github.com/repos/ethpm/ethpm-spec/contents/examples/owned/contracts/Owned.sol", # noqa: E501
False,
),
(
"https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03480", # noqa: E501
True,
),
),
)
def test_is_valid_content_addressed_github_uri(uri, expected):
actual = is_valid_content_addressed_github_uri(uri)
assert actual is expected
def test_create_github_uri():
api_uri = "https://api.github.com/repos/ethpm/py-ethpm/contents/ethpm/assets/owned/1.0.1.json"
expected_blob_uri = "https://api.github.com/repos/ethpm/py-ethpm/git/blobs/a7232a93f1e9e75d606f6c1da18aa16037e03480" # noqa: E501
actual_blob_uri = create_content_addressed_github_uri(api_uri)
assert actual_blob_uri == expected_blob_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"],
),
(
"erc1319://0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729:1/wallet?version=2.8.0/",
["0x6b5DA3cA4286Baa7fBaf64EEEE1834C7d430B729", "1", "wallet", "2.8.0"],
),
),
)
def test_parse_registry_uri(uri, expected):
address, chain_id, pkg_name, pkg_version = parse_registry_uri(uri)
assert address == expected[0]
assert chain_id == expected[1]
assert pkg_name == expected[2]
assert pkg_version == expected[3]