Skip to content

Commit

Permalink
fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dni committed Apr 24, 2024
1 parent e5948d4 commit e2eddbb
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
20 changes: 19 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ types-requests = "^2.31.0.2"
mypy = "^1.5.1"
ruff = "^0.0.284"
pre-commit = "^3.3.3"
pytest-asyncio = "^0.23.6"

[build-system]
requires = ["poetry-core"]
Expand Down
21 changes: 13 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
import httpx
import pytest

from lnurl.core import decode, encode, execute_login, execute_pay_request, get, handle
from lnurl.exceptions import InvalidLnurl, InvalidUrl, LnurlResponseException
Expand Down Expand Up @@ -74,26 +74,29 @@ def test_encode_nohttps(self, url):
class TestHandle:
"""Responses from the LNURL: https://legend.lnbits.com/"""

@pytest.mark.asyncio
@pytest.mark.parametrize(
"bech32",
[
"LNURL1DP68GURN8GHJ7MR9VAJKUEPWD3HXY6T5WVHXXMMD9AMKJARGV3EXZAE0V9CXJTMKXYH"
"KCMN4WFKZ7MJT2C6X2NRK0PDRYJNGWVU9WDN2G4V8XK2VSZA2RC"
],
)
def test_handle_withdraw(self, bech32):
res = handle(bech32)
async def test_handle_withdraw(self, bech32):
res = await handle(bech32)
assert isinstance(res, LnurlWithdrawResponse)
assert res.tag == "withdrawRequest"
assert res.callback.host == "legend.lnbits.com"
assert res.default_description == "sample withdraw"
assert res.max_withdrawable >= res.min_withdrawable

@pytest.mark.asyncio
@pytest.mark.parametrize("bech32", ["BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4"])
async def test_handle_nolnurl(self, bech32):
with pytest.raises(InvalidLnurl):
await handle(bech32)

@pytest.mark.asyncio
@pytest.mark.parametrize("url", ["https://lnurl.thisshouldfail.io/"])
async def test_get_requests_error(self, url):
with pytest.raises(LnurlResponseException):
Expand All @@ -103,6 +106,7 @@ async def test_get_requests_error(self, url):
class TestPayFlow:
"""Full LNURL-pay flow interacting with https://legend.lnbits.com/"""

@pytest.mark.asyncio
@pytest.mark.parametrize(
"bech32, amount",
[
Expand All @@ -113,22 +117,23 @@ class TestPayFlow:
("[email protected]", "100000"),
],
)
def test_pay_flow(self, bech32: str, amount: str):
res = handle(bech32)
async def test_pay_flow(self, bech32: str, amount: str):
res = await handle(bech32)
assert isinstance(res, LnurlPayResponse)
assert res.tag == "payRequest"
assert res.callback.host == "legend.lnbits.com"
assert len(res.metadata.list()) >= 1
assert res.metadata.text != ""

res2 = execute_pay_request(res, amount)
res2 = await execute_pay_request(res, amount)
assert isinstance(res2, LnurlPayActionResponse)
assert res2.success_action is None or isinstance(res2.success_action, LnurlPaySuccessAction)


class TestLoginFlow:
"""Full LNURL-login flow interacting with https://lnmarkets.com/"""

@pytest.mark.asyncio
@pytest.mark.xfail(reason="need online lnurl auth server to test this flow")
@pytest.mark.parametrize(
"url",
Expand All @@ -142,10 +147,10 @@ async def test_login_flow(self, url: str):
init.raise_for_status()
bech32 = init.json()["result"]["data"]["json"]["lnurl"]

res = handle(bech32)
res = await handle(bech32)
assert isinstance(res, LnurlAuthResponse)
assert res.tag == "login"
assert res.callback.host == "api.lnmarkets.com"

res2 = execute_login(res, "my-secret")
res2 = await execute_login(res, "my-secret")
assert isinstance(res2, LnurlSuccessResponse)

0 comments on commit e2eddbb

Please sign in to comment.