[feat]: invoice amount settings (#2990)

This commit is contained in:
Vlad Stan 2025-02-24 14:45:17 +02:00 committed by GitHub
parent 10682cf736
commit 30cf6913af
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 128 additions and 46 deletions

View file

@ -310,3 +310,5 @@ def _settings_cleanup(settings: Settings):
settings.lnbits_wallet_limit_daily_max_withdraw = 0
settings.lnbits_admin_extensions = []
settings.lnbits_admin_users = []
settings.lnbits_max_outgoing_payment_amount_sats = 10_000_000_100
settings.lnbits_max_incoming_payment_amount_sats = 10_000_000_200

View file

@ -11,7 +11,7 @@ from pytest_mock.plugin import MockerFixture
from lnbits.core.crud import get_standalone_payment, get_wallet
from lnbits.core.models import Payment, PaymentState, Wallet
from lnbits.core.services import create_invoice, pay_invoice
from lnbits.exceptions import PaymentError
from lnbits.exceptions import InvoiceError, PaymentError
from lnbits.settings import Settings
from lnbits.tasks import (
create_permanent_task,
@ -61,9 +61,12 @@ async def test_bad_wallet_id(to_wallet: Wallet):
@pytest.mark.anyio
async def test_payment_limit(to_wallet: Wallet):
async def test_payment_explicit_limit(to_wallet: Wallet):
payment = await create_invoice(wallet_id=to_wallet.id, amount=101, memo="")
with pytest.raises(PaymentError, match="Amount in invoice is too high."):
with pytest.raises(
PaymentError,
match="Invoice amount 101 sats is too high. Max allowed: 100 sats.",
):
await pay_invoice(
wallet_id=to_wallet.id,
max_sat=100,
@ -71,6 +74,31 @@ async def test_payment_limit(to_wallet: Wallet):
)
@pytest.mark.anyio
async def test_payment_system_limit(to_wallet: Wallet, settings: Settings):
settings.lnbits_max_outgoing_payment_amount_sats = 100
payment = await create_invoice(wallet_id=to_wallet.id, amount=200, memo="")
with pytest.raises(
PaymentError,
match="Invoice amount 200 sats is too high. Max allowed: 100 sats.",
):
await pay_invoice(
wallet_id=to_wallet.id,
payment_request=payment.bolt11,
)
@pytest.mark.anyio
async def test_create_payment_system_limit(to_wallet: Wallet, settings: Settings):
settings.lnbits_max_incoming_payment_amount_sats = 101
with pytest.raises(
InvoiceError,
match="Invoice amount 202 sats is too high. Max allowed: 101 sats.",
):
await create_invoice(wallet_id=to_wallet.id, amount=202, memo="")
@pytest.mark.anyio
async def test_pay_twice(to_wallet: Wallet):
payment = await create_invoice(wallet_id=to_wallet.id, amount=3, memo="Twice")