mirror of
https://github.com/lnbits/lnbits.git
synced 2025-06-06 21:23:05 +02:00
fix bleskomat tests
This commit is contained in:
parent
9e8376b3fb
commit
09b86605dd
@ -9,18 +9,21 @@ from tests.helpers import credit_wallet
|
|||||||
from tests.extensions.bleskomat.conftest import bleskomat, lnurl
|
from tests.extensions.bleskomat.conftest import bleskomat, lnurl
|
||||||
from tests.mocks import WALLET
|
from tests.mocks import WALLET
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_missing_secret(client):
|
async def test_bleskomat_lnurl_api_missing_secret(client):
|
||||||
response = await client.get("/bleskomat/u")
|
response = await client.get("/bleskomat/u")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "ERROR", "reason": "Missing secret"}
|
assert response.json() == {"status": "ERROR", "reason": "Missing secret"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_invalid_secret(client):
|
async def test_bleskomat_lnurl_api_invalid_secret(client):
|
||||||
response = await client.get("/bleskomat/u?k1=invalid-secret")
|
response = await client.get("/bleskomat/u?k1=invalid-secret")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "ERROR", "reason": "Invalid secret"}
|
assert response.json() == {"status": "ERROR", "reason": "Invalid secret"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_unknown_api_key(client):
|
async def test_bleskomat_lnurl_api_unknown_api_key(client):
|
||||||
query = {
|
query = {
|
||||||
@ -33,11 +36,12 @@ async def test_bleskomat_lnurl_api_unknown_api_key(client):
|
|||||||
"f": "EUR",
|
"f": "EUR",
|
||||||
}
|
}
|
||||||
payload = query_to_signing_payload(query)
|
payload = query_to_signing_payload(query)
|
||||||
signature = "xxx"# not checked, so doesn't matter
|
signature = "xxx" # not checked, so doesn't matter
|
||||||
response = await client.get(f'/bleskomat/u?{payload}&signature={signature}')
|
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "ERROR", "reason": "Unknown API key"}
|
assert response.json() == {"status": "ERROR", "reason": "Unknown API key"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_invalid_signature(client, bleskomat):
|
async def test_bleskomat_lnurl_api_invalid_signature(client, bleskomat):
|
||||||
query = {
|
query = {
|
||||||
@ -51,10 +55,11 @@ async def test_bleskomat_lnurl_api_invalid_signature(client, bleskomat):
|
|||||||
}
|
}
|
||||||
payload = query_to_signing_payload(query)
|
payload = query_to_signing_payload(query)
|
||||||
signature = "invalid"
|
signature = "invalid"
|
||||||
response = await client.get(f'/bleskomat/u?{payload}&signature={signature}')
|
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "ERROR", "reason": "Invalid API key signature"}
|
assert response.json() == {"status": "ERROR", "reason": "Invalid API key signature"}
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_valid_signature(client, bleskomat):
|
async def test_bleskomat_lnurl_api_valid_signature(client, bleskomat):
|
||||||
query = {
|
query = {
|
||||||
@ -64,41 +69,42 @@ async def test_bleskomat_lnurl_api_valid_signature(client, bleskomat):
|
|||||||
"minWithdrawable": "1",
|
"minWithdrawable": "1",
|
||||||
"maxWithdrawable": "1",
|
"maxWithdrawable": "1",
|
||||||
"defaultDescription": "test valid sig",
|
"defaultDescription": "test valid sig",
|
||||||
"f": "EUR",# tests use the dummy exchange rate provider
|
"f": "EUR", # tests use the dummy exchange rate provider
|
||||||
}
|
}
|
||||||
payload = query_to_signing_payload(query)
|
payload = query_to_signing_payload(query)
|
||||||
signature = generate_bleskomat_lnurl_signature(
|
signature = generate_bleskomat_lnurl_signature(
|
||||||
payload=payload,
|
payload=payload, api_key_secret=bleskomat.api_key_secret, api_key_encoding=bleskomat.api_key_encoding
|
||||||
api_key_secret=bleskomat.api_key_secret,
|
|
||||||
api_key_encoding=bleskomat.api_key_encoding
|
|
||||||
)
|
)
|
||||||
response = await client.get(f'/bleskomat/u?{payload}&signature={signature}')
|
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
data = response.json()
|
data = response.json()
|
||||||
assert data["tag"] == "withdrawRequest"
|
assert data["tag"] == "withdrawRequest"
|
||||||
assert data["minWithdrawable"] == 1000
|
assert data["minWithdrawable"] == 1000
|
||||||
assert data["maxWithdrawable"] == 1000
|
assert data["maxWithdrawable"] == 1000
|
||||||
assert data["defaultDescription"] == "test valid sig"
|
assert data["defaultDescription"] == "test valid sig"
|
||||||
assert data["callback"] == f'http://{HOST}:{PORT}/bleskomat/u'
|
assert data["callback"] == f"http://{HOST}:{PORT}/bleskomat/u"
|
||||||
k1 = data["k1"]
|
k1 = data["k1"]
|
||||||
lnurl = await get_bleskomat_lnurl(secret=k1)
|
lnurl = await get_bleskomat_lnurl(secret=k1)
|
||||||
assert lnurl
|
assert lnurl
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_action_insufficient_balance(client, lnurl):
|
async def test_bleskomat_lnurl_api_action_insufficient_balance(client, lnurl):
|
||||||
bleskomat = lnurl["bleskomat"]
|
bleskomat = lnurl["bleskomat"]
|
||||||
secret = lnurl["secret"]
|
secret = lnurl["secret"]
|
||||||
pr = "lntb500n1pseq44upp5xqd38rgad72lnlh4gl339njlrsl3ykep82j6gj4g02dkule7k54qdqqcqzpgxqyz5vqsp5h0zgewuxdxcl2rnlumh6g520t4fr05rgudakpxm789xgjekha75s9qyyssq5vhwsy9knhfeqg0wn6hcnppwmum8fs3g3jxkgw45havgfl6evchjsz3s8e8kr6eyacz02szdhs7v5lg0m7wehd5rpf6yg8480cddjlqpae52xu"
|
pr = "lntb500n1pseq44upp5xqd38rgad72lnlh4gl339njlrsl3ykep82j6gj4g02dkule7k54qdqqcqzpgxqyz5vqsp5h0zgewuxdxcl2rnlumh6g520t4fr05rgudakpxm789xgjekha75s9qyyssq5vhwsy9knhfeqg0wn6hcnppwmum8fs3g3jxkgw45havgfl6evchjsz3s8e8kr6eyacz02szdhs7v5lg0m7wehd5rpf6yg8480cddjlqpae52xu"
|
||||||
WALLET.pay_invoice.reset_mock()
|
WALLET.pay_invoice.reset_mock()
|
||||||
response = await client.get(f'/bleskomat/u?k1={secret}&pr={pr}')
|
response = await client.get(f"/bleskomat/u?k1={secret}&pr={pr}")
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.json() == {"status": "ERROR", "reason": "Failed to pay invoice: Insufficient balance."}
|
assert response.json()["status"] == "ERROR"
|
||||||
|
assert "Insufficient balance" in response.json()["reason"]
|
||||||
wallet = await get_wallet(bleskomat.wallet)
|
wallet = await get_wallet(bleskomat.wallet)
|
||||||
assert wallet.balance_msat == 0
|
assert wallet.balance_msat == 0
|
||||||
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
||||||
assert bleskomat_lnurl.has_uses_remaining() == True
|
assert bleskomat_lnurl.has_uses_remaining() == True
|
||||||
WALLET.pay_invoice.assert_not_called()
|
WALLET.pay_invoice.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
async def test_bleskomat_lnurl_api_action_success(client, lnurl):
|
async def test_bleskomat_lnurl_api_action_success(client, lnurl):
|
||||||
bleskomat = lnurl["bleskomat"]
|
bleskomat = lnurl["bleskomat"]
|
||||||
@ -111,7 +117,7 @@ async def test_bleskomat_lnurl_api_action_success(client, lnurl):
|
|||||||
wallet = await get_wallet(bleskomat.wallet)
|
wallet = await get_wallet(bleskomat.wallet)
|
||||||
assert wallet.balance_msat == 100000
|
assert wallet.balance_msat == 100000
|
||||||
WALLET.pay_invoice.reset_mock()
|
WALLET.pay_invoice.reset_mock()
|
||||||
response = await client.get(f'/bleskomat/u?k1={secret}&pr={pr}')
|
response = await client.get(f"/bleskomat/u?k1={secret}&pr={pr}")
|
||||||
assert response.json() == {"status": "OK"}
|
assert response.json() == {"status": "OK"}
|
||||||
wallet = await get_wallet(bleskomat.wallet)
|
wallet = await get_wallet(bleskomat.wallet)
|
||||||
assert wallet.balance_msat == 50000
|
assert wallet.balance_msat == 50000
|
||||||
|
Loading…
x
Reference in New Issue
Block a user