Fee reserve for lightning backends (#557)
* preparing fees * fee_limit_msat * await resp result * clightning * fix tests * fix test * add fee to test * mypy * invoice_status * checking id fix * fee reserve error message * only for external payments
This commit is contained in:
parent
911fe92e03
commit
0f97f8f18b
15 changed files with 129 additions and 84 deletions
|
|
@ -3,7 +3,10 @@ import secrets
|
|||
from lnbits.core.crud import get_wallet
|
||||
from lnbits.settings import HOST, PORT
|
||||
from lnbits.extensions.bleskomat.crud import get_bleskomat_lnurl
|
||||
from lnbits.extensions.bleskomat.helpers import generate_bleskomat_lnurl_signature, query_to_signing_payload
|
||||
from lnbits.extensions.bleskomat.helpers import (
|
||||
generate_bleskomat_lnurl_signature,
|
||||
query_to_signing_payload,
|
||||
)
|
||||
from tests.conftest import client
|
||||
from tests.helpers import credit_wallet
|
||||
from tests.extensions.bleskomat.conftest import bleskomat, lnurl
|
||||
|
|
@ -73,7 +76,9 @@ async def test_bleskomat_lnurl_api_valid_signature(client, bleskomat):
|
|||
}
|
||||
payload = query_to_signing_payload(query)
|
||||
signature = generate_bleskomat_lnurl_signature(
|
||||
payload=payload, api_key_secret=bleskomat.api_key_secret, api_key_encoding=bleskomat.api_key_encoding
|
||||
payload=payload,
|
||||
api_key_secret=bleskomat.api_key_secret,
|
||||
api_key_encoding=bleskomat.api_key_encoding,
|
||||
)
|
||||
response = await client.get(f"/bleskomat/u?{payload}&signature={signature}")
|
||||
assert response.status_code == 200
|
||||
|
|
@ -97,7 +102,9 @@ async def test_bleskomat_lnurl_api_action_insufficient_balance(client, lnurl):
|
|||
response = await client.get(f"/bleskomat/u?k1={secret}&pr={pr}")
|
||||
assert response.status_code == 200
|
||||
assert response.json()["status"] == "ERROR"
|
||||
assert ("Insufficient balance" in response.json()["reason"]) or ("fee" in response.json()["reason"])
|
||||
assert ("Insufficient balance" in response.json()["reason"]) or (
|
||||
"fee" in response.json()["reason"]
|
||||
)
|
||||
wallet = await get_wallet(bleskomat.wallet)
|
||||
assert wallet.balance_msat == 0
|
||||
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
||||
|
|
@ -123,4 +130,4 @@ async def test_bleskomat_lnurl_api_action_success(client, lnurl):
|
|||
assert wallet.balance_msat == 50000
|
||||
bleskomat_lnurl = await get_bleskomat_lnurl(secret)
|
||||
assert bleskomat_lnurl.has_uses_remaining() == False
|
||||
WALLET.pay_invoice.assert_called_once_with(pr)
|
||||
WALLET.pay_invoice.assert_called_once_with(pr, 2000)
|
||||
|
|
|
|||
|
|
@ -9,28 +9,42 @@ from lnbits.wallets.base import (
|
|||
)
|
||||
from lnbits.settings import WALLET
|
||||
|
||||
WALLET.status = AsyncMock(return_value=StatusResponse(
|
||||
"",# no error
|
||||
1000000,# msats
|
||||
))
|
||||
WALLET.create_invoice = AsyncMock(return_value=InvoiceResponse(
|
||||
True,# ok
|
||||
"6621aafbdd7709ca6eea6203f362d64bd7cb2911baa91311a176b3ecaf2274bd",# checking_id (i.e. payment_hash)
|
||||
"lntb1u1psezhgspp5vcs6477awuyu5mh2vgplxckkf0tuk2g3h253xydpw6e7etezwj7sdqqcqzpgxqyz5vqsp5dxpw8zs77hw5pla4wz4mfujllyxtlpu443auur2uxqdrs8q2h56q9qyyssq65zk30ylmygvv5y4tuwalnf3ttnqjn57ef6rmcqg0s53akem560jh8ptemjcmytn3lrlatw4hv9smg88exv3v4f4lqnp96s0psdrhxsp6pp75q",# payment_request
|
||||
"",# no error
|
||||
))
|
||||
def pay_invoice_side_effect(payment_request: str):
|
||||
WALLET.status = AsyncMock(
|
||||
return_value=StatusResponse(
|
||||
"", # no error
|
||||
1000000, # msats
|
||||
)
|
||||
)
|
||||
WALLET.create_invoice = AsyncMock(
|
||||
return_value=InvoiceResponse(
|
||||
True, # ok
|
||||
"6621aafbdd7709ca6eea6203f362d64bd7cb2911baa91311a176b3ecaf2274bd", # checking_id (i.e. payment_hash)
|
||||
"lntb1u1psezhgspp5vcs6477awuyu5mh2vgplxckkf0tuk2g3h253xydpw6e7etezwj7sdqqcqzpgxqyz5vqsp5dxpw8zs77hw5pla4wz4mfujllyxtlpu443auur2uxqdrs8q2h56q9qyyssq65zk30ylmygvv5y4tuwalnf3ttnqjn57ef6rmcqg0s53akem560jh8ptemjcmytn3lrlatw4hv9smg88exv3v4f4lqnp96s0psdrhxsp6pp75q", # payment_request
|
||||
"", # no error
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def pay_invoice_side_effect(
|
||||
payment_request: str, fee_limit_msat: int
|
||||
) -> PaymentResponse:
|
||||
invoice = bolt11.decode(payment_request)
|
||||
return PaymentResponse(
|
||||
True,# ok
|
||||
invoice.payment_hash,# checking_id (i.e. payment_hash)
|
||||
0,# fee_msat
|
||||
"",# no error
|
||||
True, # ok
|
||||
invoice.payment_hash, # checking_id (i.e. payment_hash)
|
||||
0, # fee_msat
|
||||
"", # no error
|
||||
)
|
||||
|
||||
|
||||
WALLET.pay_invoice = AsyncMock(side_effect=pay_invoice_side_effect)
|
||||
WALLET.get_invoice_status = AsyncMock(return_value=PaymentStatus(
|
||||
True,# paid
|
||||
))
|
||||
WALLET.get_payment_status = AsyncMock(return_value=PaymentStatus(
|
||||
True,# paid
|
||||
))
|
||||
WALLET.get_invoice_status = AsyncMock(
|
||||
return_value=PaymentStatus(
|
||||
True, # paid
|
||||
)
|
||||
)
|
||||
WALLET.get_payment_status = AsyncMock(
|
||||
return_value=PaymentStatus(
|
||||
True, # paid
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue