-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
33 additions
and
9 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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): | ||
|
@@ -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", | ||
[ | ||
|
@@ -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", | ||
|
@@ -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) |