From c88e6b0e62e76a50cd1d4332c0c4239500744218 Mon Sep 17 00:00:00 2001 From: calle <93376500+callebtc@users.noreply.github.com> Date: Mon, 1 Aug 2022 16:12:25 +0200 Subject: [PATCH] Mega-merge 1: Test invoice creation with description hash (WIP) (#812) * check for description hash * remove unnecessary asserts for clarity * assume that description_hash is a hash already * no lock * restore bolt11.py * /api/v1/payments with hex of description * comment --- tests/conftest.py | 6 +----- tests/core/views/test_api.py | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index adb1fa36..e3e2443f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -122,12 +122,8 @@ async def adminkey_headers_to(to_wallet): @pytest_asyncio.fixture(scope="session") async def invoice(to_wallet): - wallet = to_wallet data = await get_random_invoice_data() invoiceData = CreateInvoiceData(**data) - stuff_lock = asyncio.Lock() - async with stuff_lock: - invoice = await api_payments_create_invoice(invoiceData, wallet) - await asyncio.sleep(1) + invoice = await api_payments_create_invoice(invoiceData, to_wallet) yield invoice del invoice diff --git a/tests/core/views/test_api.py b/tests/core/views/test_api.py index dfd2b32a..6bf26e26 100644 --- a/tests/core/views/test_api.py +++ b/tests/core/views/test_api.py @@ -1,8 +1,15 @@ import pytest import pytest_asyncio + +import hashlib +from binascii import hexlify + +from lnbits import bolt11 from lnbits.core.crud import get_wallet from lnbits.core.views.api import api_payment +from lnbits.core.views.api import api_payments_create_invoice, CreateInvoiceData + from ...helpers import get_random_invoice_data # check if the client is working @@ -179,3 +186,21 @@ async def test_api_payment_with_key(invoice, inkey_headers_from): assert type(response) == dict assert response["paid"] == True assert "details" in response + + +# check POST /api/v1/payments: invoice creation with a description hash +@pytest.mark.asyncio +async def test_create_invoice_with_description_hash(client, inkey_headers_to): + data = await get_random_invoice_data() + descr_hash = hashlib.sha256("asdasdasd".encode("utf-8")).hexdigest() + data["description_hash"] = "asdasdasd".encode("utf-8").hex() + + response = await client.post( + "/api/v1/payments", json=data, headers=inkey_headers_to + ) + invoice = response.json() + + invoice_bolt11 = bolt11.decode(invoice["payment_request"]) + assert invoice_bolt11.description_hash == descr_hash + assert invoice_bolt11.description is None + return invoice