-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathtest_wallet_utils.py
63 lines (48 loc) · 2.06 KB
/
test_wallet_utils.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
from typing import List, Union
from cashu.core.errors import CashuError
from cashu.wallet.utils import sanitize_url
async def assert_err(f, msg: Union[str, CashuError]):
"""Compute f() and expect an error message 'msg'."""
try:
await f
except Exception as exc:
error_message: str = str(exc.args[0])
if isinstance(msg, CashuError):
if msg.detail not in error_message:
raise Exception(
f"CashuError. Expected error: {msg.detail}, got: {error_message}"
)
return
if msg not in error_message:
raise Exception(f"Expected error: {msg}, got: {error_message}")
return
raise Exception(f"Expected error: {msg}, got no error")
async def assert_err_multiple(f, msgs: List[str]):
"""Compute f() and expect an error message 'msg'."""
try:
await f
except Exception as exc:
for msg in msgs:
if msg in str(exc.args[0]):
return
raise Exception(f"Expected error: {msgs}, got: {exc.args[0]}")
raise Exception(f"Expected error: {msgs}, got no error")
def test_sanitize_url():
url = "https://localhost:3338"
assert sanitize_url(url) == "https://localhost:3338"
url = "https://mint.com:3338"
assert sanitize_url(url) == "https://mint.com:3338"
url = "https://Mint.com:3338"
assert sanitize_url(url) == "https://mint.com:3338"
url = "https://mint.com:3338/"
assert sanitize_url(url) == "https://mint.com:3338"
url = "https://mint.com:3338/abc"
assert sanitize_url(url) == "https://mint.com:3338/abc"
url = "https://mint.com:3338/Abc"
assert sanitize_url(url) == "https://mint.com:3338/Abc"
url = "https://mint.com:3338/abc/"
assert sanitize_url(url) == "https://mint.com:3338/abc"
url = "https://mint.com:3338/Abc/"
assert sanitize_url(url) == "https://mint.com:3338/Abc"
url = "https://Mint.com:3338/Abc/def"
assert sanitize_url(url) == "https://mint.com:3338/Abc/def"