feat: parse nested pydantic models fetchone and fetchall + add shortcuts for insert_query and update_query into Database (#2714)
* feat: add shortcuts for insert_query and update_query into `Database`
example: await db.insert("table_name", base_model)
* remove where from argument
* chore: code clean-up
* extension manager
* lnbits-qrcode components
* parse date from dict
* refactor: make `settings` a fixture
* chore: remove verbose key names
* fix: time column
* fix: cast balance to `int`
* extension toggle vue3
* vue3 @input migration
* fix: payment extra and payment hash
* fix dynamic fields and ext db migration
* remove shadow on cards in dark theme
* screwed up and made more css pushes to this branch
* attempt to make chip component in settings dynamic fields
* dynamic chips
* qrscanner
* clean init admin settings
* make get_user better
* add dbversion model
* remove update_payment_status/extra/details
* traces for value and assertion errors
* refactor services
* add PaymentFiatAmount
* return Payment on api endpoints
* rename to get_user_from_account
* refactor: just refactor (#2740)
* rc5
* Fix db cache (#2741)
* [refactor] split services.py (#2742)
* refactor: spit `core.py` (#2743)
* refactor: make QR more customizable
* fix: print.html
* fix: qrcode options
* fix: white shadow on dark theme
* fix: datetime wasnt parsed in dict_to_model
* add timezone for conversion
* only parse timestamp for sqlite, postgres does it
* log internal payment success
* fix: export wallet to phone QR
* Adding a customisable border theme, like gradient (#2746)
* fixed mobile scan btn
* fix test websocket
* fix get_payments tests
* dict_to_model skip none values
* preimage none instead of defaulting to 0000...
* fixup test real invoice tests
* fixed pheonixd for wss
* fix nodemanager test settings
* fix lnbits funding
* only insert extension when they dont exist
---------
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
Co-authored-by: Tiago Vasconcelos <talvasconcelos@gmail.com>
Co-authored-by: Arc <ben@arc.wales>
Co-authored-by: Arc <33088785+arcbtc@users.noreply.github.com>
This commit is contained in:
parent
ae4eda04ba
commit
2940cf97c5
84 changed files with 4220 additions and 3776 deletions
|
|
@ -39,9 +39,11 @@ docker_lightning_unconnected_cli = [
|
|||
|
||||
|
||||
def run_cmd(cmd: list) -> str:
|
||||
timeout = 20
|
||||
timeout = 10
|
||||
process = Popen(cmd, stdout=PIPE, stderr=PIPE)
|
||||
|
||||
logger.debug(f"running command: {cmd}")
|
||||
|
||||
def process_communication(comm):
|
||||
stdout, stderr = comm
|
||||
output = stdout.decode("utf-8").strip()
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import hashlib
|
|||
import pytest
|
||||
|
||||
from lnbits import bolt11
|
||||
from lnbits.core.crud import get_standalone_payment, update_payment_details
|
||||
from lnbits.core.crud import get_standalone_payment, update_payment
|
||||
from lnbits.core.models import CreateInvoice, Payment, PaymentState
|
||||
from lnbits.core.services import fee_reserve_total, get_balance_delta
|
||||
from lnbits.tasks import create_task, wait_for_paid_invoices
|
||||
|
|
@ -99,7 +99,7 @@ async def test_create_real_invoice(client, adminkey_headers_from, inkey_headers_
|
|||
raise FakeError()
|
||||
|
||||
task = create_task(wait_for_paid_invoices("test_create_invoice", on_paid)())
|
||||
pay_real_invoice(invoice["payment_request"])
|
||||
pay_real_invoice(invoice["bolt11"])
|
||||
|
||||
# wait for the task to exit
|
||||
with pytest.raises(FakeError):
|
||||
|
|
@ -143,7 +143,6 @@ async def test_pay_real_invoice_set_pending_and_check_state(
|
|||
payment = await get_standalone_payment(invoice["payment_hash"])
|
||||
assert payment
|
||||
assert payment.success
|
||||
assert payment.pending is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -160,28 +159,19 @@ async def test_pay_hold_invoice_check_pending(
|
|||
)
|
||||
)
|
||||
await asyncio.sleep(1)
|
||||
|
||||
# get payment hash from the invoice
|
||||
invoice_obj = bolt11.decode(invoice["payment_request"])
|
||||
|
||||
payment_db = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
|
||||
assert payment_db
|
||||
assert payment_db.pending is True
|
||||
|
||||
settle_invoice(preimage)
|
||||
|
||||
payment_db = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
assert payment_db
|
||||
response = await task
|
||||
assert response.status_code < 300
|
||||
|
||||
# check if paid
|
||||
|
||||
await asyncio.sleep(1)
|
||||
|
||||
payment_db_after_settlement = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
|
||||
assert payment_db_after_settlement
|
||||
assert payment_db_after_settlement.pending is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
@ -202,11 +192,6 @@ async def test_pay_hold_invoice_check_pending_and_fail(
|
|||
# get payment hash from the invoice
|
||||
invoice_obj = bolt11.decode(invoice["payment_request"])
|
||||
|
||||
payment_db = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
|
||||
assert payment_db
|
||||
assert payment_db.pending is True
|
||||
|
||||
preimage_hash = hashlib.sha256(bytes.fromhex(preimage)).hexdigest()
|
||||
|
||||
# cancel the hodl invoice
|
||||
|
|
@ -221,7 +206,6 @@ async def test_pay_hold_invoice_check_pending_and_fail(
|
|||
# payment should be in database as failed
|
||||
payment_db_after_settlement = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
assert payment_db_after_settlement
|
||||
assert payment_db_after_settlement.pending is False
|
||||
assert payment_db_after_settlement.failed is True
|
||||
|
||||
|
||||
|
|
@ -243,11 +227,6 @@ async def test_pay_hold_invoice_check_pending_and_fail_cancel_payment_task_in_me
|
|||
# get payment hash from the invoice
|
||||
invoice_obj = bolt11.decode(invoice["payment_request"])
|
||||
|
||||
payment_db = await get_standalone_payment(invoice_obj.payment_hash)
|
||||
|
||||
assert payment_db
|
||||
assert payment_db.pending is True
|
||||
|
||||
# cancel payment task, this simulates the client dropping the connection
|
||||
task.cancel()
|
||||
|
||||
|
|
@ -264,7 +243,7 @@ async def test_pay_hold_invoice_check_pending_and_fail_cancel_payment_task_in_me
|
|||
assert payment_db_after_settlement is not None
|
||||
|
||||
# payment is failed
|
||||
status = await payment_db.check_status()
|
||||
status = await payment_db_after_settlement.check_status()
|
||||
assert not status.paid
|
||||
assert status.failed
|
||||
|
||||
|
|
@ -307,16 +286,15 @@ async def test_receive_real_invoice_set_pending_and_check_state(
|
|||
assert payment_status["paid"]
|
||||
|
||||
assert payment
|
||||
assert payment.pending is False
|
||||
|
||||
# set the incoming invoice to pending
|
||||
await update_payment_details(payment.checking_id, status=PaymentState.PENDING)
|
||||
payment.status = PaymentState.PENDING
|
||||
await update_payment(payment)
|
||||
|
||||
payment_pending = await get_standalone_payment(
|
||||
invoice["payment_hash"], incoming=True
|
||||
)
|
||||
assert payment_pending
|
||||
assert payment_pending.pending is True
|
||||
assert payment_pending.success is False
|
||||
assert payment_pending.failed is False
|
||||
|
||||
|
|
@ -324,7 +302,7 @@ async def test_receive_real_invoice_set_pending_and_check_state(
|
|||
raise FakeError()
|
||||
|
||||
task = create_task(wait_for_paid_invoices("test_create_invoice", on_paid)())
|
||||
pay_real_invoice(invoice["payment_request"])
|
||||
pay_real_invoice(invoice["bolt11"])
|
||||
|
||||
with pytest.raises(FakeError):
|
||||
await task
|
||||
|
|
@ -349,7 +327,7 @@ async def test_check_fee_reserve(client, adminkey_headers_from):
|
|||
)
|
||||
assert response.status_code < 300
|
||||
invoice = response.json()
|
||||
payment_request = invoice["payment_request"]
|
||||
payment_request = invoice["bolt11"]
|
||||
|
||||
response = await client.get(
|
||||
f"/api/v1/payments/fee-reserve?invoice={payment_request}",
|
||||
|
|
|
|||
|
|
@ -2,45 +2,45 @@ import pytest
|
|||
from bolt11 import decode
|
||||
|
||||
from lnbits.core.services import (
|
||||
PaymentStatus,
|
||||
create_invoice,
|
||||
)
|
||||
from lnbits.wallets import get_funding_source
|
||||
from lnbits.wallets.base import PaymentStatus
|
||||
|
||||
description = "test create invoice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_invoice(from_wallet):
|
||||
payment_hash, pr = await create_invoice(
|
||||
payment = await create_invoice(
|
||||
wallet_id=from_wallet.id,
|
||||
amount=1000,
|
||||
memo=description,
|
||||
)
|
||||
invoice = decode(pr)
|
||||
assert invoice.payment_hash == payment_hash
|
||||
invoice = decode(payment.bolt11)
|
||||
assert invoice.payment_hash == payment.payment_hash
|
||||
assert invoice.amount_msat == 1000000
|
||||
assert invoice.description == description
|
||||
|
||||
funding_source = get_funding_source()
|
||||
status = await funding_source.get_invoice_status(payment_hash)
|
||||
status = await funding_source.get_invoice_status(payment.payment_hash)
|
||||
assert isinstance(status, PaymentStatus)
|
||||
assert status.pending
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_internal_invoice(from_wallet):
|
||||
payment_hash, pr = await create_invoice(
|
||||
payment = await create_invoice(
|
||||
wallet_id=from_wallet.id, amount=1000, memo=description, internal=True
|
||||
)
|
||||
invoice = decode(pr)
|
||||
assert invoice.payment_hash == payment_hash
|
||||
invoice = decode(payment.bolt11)
|
||||
assert invoice.payment_hash == payment.payment_hash
|
||||
assert invoice.amount_msat == 1000000
|
||||
assert invoice.description == description
|
||||
|
||||
# Internal invoices are not on fundingsource. so we should get some kind of error
|
||||
# that the invoice is not found, but we get status pending
|
||||
funding_source = get_funding_source()
|
||||
status = await funding_source.get_invoice_status(payment_hash)
|
||||
status = await funding_source.get_invoice_status(payment.payment_hash)
|
||||
assert isinstance(status, PaymentStatus)
|
||||
assert status.pending
|
||||
|
|
|
|||
|
|
@ -1,27 +1,23 @@
|
|||
import pytest
|
||||
|
||||
from lnbits.core.crud import (
|
||||
get_standalone_payment,
|
||||
)
|
||||
from lnbits.core.models import PaymentState
|
||||
from lnbits.core.services import (
|
||||
PaymentError,
|
||||
pay_invoice,
|
||||
)
|
||||
from lnbits.exceptions import PaymentError
|
||||
|
||||
description = "test pay invoice"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_services_pay_invoice(to_wallet, real_invoice):
|
||||
payment_hash = await pay_invoice(
|
||||
payment = await pay_invoice(
|
||||
wallet_id=to_wallet.id,
|
||||
payment_request=real_invoice.get("bolt11"),
|
||||
description=description,
|
||||
)
|
||||
assert payment_hash
|
||||
payment = await get_standalone_payment(payment_hash)
|
||||
assert payment
|
||||
assert not payment.pending
|
||||
assert payment.status == PaymentState.SUCCESS
|
||||
assert payment.memo == description
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from pydantic import parse_obj_as
|
|||
|
||||
from lnbits import bolt11
|
||||
from lnbits.nodes.base import ChannelPoint, ChannelState, NodeChannel
|
||||
from tests.conftest import pytest_asyncio, settings
|
||||
from tests.conftest import pytest_asyncio
|
||||
|
||||
from ..helpers import (
|
||||
funding_source,
|
||||
|
|
@ -25,7 +25,7 @@ pytestmark = pytest.mark.skipif(
|
|||
|
||||
|
||||
@pytest_asyncio.fixture()
|
||||
async def node_client(client, from_super_user):
|
||||
async def node_client(client, from_super_user, settings):
|
||||
settings.lnbits_node_ui = True
|
||||
settings.lnbits_public_node_ui = False
|
||||
settings.lnbits_node_ui_transactions = True
|
||||
|
|
@ -37,14 +37,14 @@ async def node_client(client, from_super_user):
|
|||
|
||||
|
||||
@pytest_asyncio.fixture()
|
||||
async def public_node_client(node_client):
|
||||
async def public_node_client(node_client, settings):
|
||||
settings.lnbits_public_node_ui = True
|
||||
yield node_client
|
||||
settings.lnbits_public_node_ui = False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_node_info_not_found(client, from_super_user):
|
||||
async def test_node_info_not_found(client, from_super_user, settings):
|
||||
settings.lnbits_node_ui = False
|
||||
response = await client.get("/node/api/v1/info", params={"usr": from_super_user.id})
|
||||
assert response.status_code == HTTPStatus.SERVICE_UNAVAILABLE
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue