mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 11:24:19 +01:00
Mint: blink fix fee estimation (#439)
* blink: fix fee esimation * fix line length * fix line length * fix line length * remove noqa
This commit is contained in:
@@ -327,7 +327,7 @@ class BlinkWallet(LightningBackend):
|
||||
fees_response_msat = int(resp["data"]["lnInvoiceFeeProbe"]["amount"]) * 1000
|
||||
# we either take fee_msat_response or the BLINK_MAX_FEE_PERCENT, whichever is higher
|
||||
fees_msat = max(
|
||||
fees_response_msat, math.ceil(amount_msat * BLINK_MAX_FEE_PERCENT)
|
||||
fees_response_msat, math.ceil(amount_msat / 100 * BLINK_MAX_FEE_PERCENT)
|
||||
)
|
||||
|
||||
fees = Amount(unit=Unit.msat, amount=fees_msat)
|
||||
|
||||
@@ -380,6 +380,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
method = Method[quote.method]
|
||||
|
||||
if not quote.paid:
|
||||
assert quote.checking_id, "quote has no checking id"
|
||||
logger.trace(f"Lightning: checking invoice {quote.checking_id}")
|
||||
status: PaymentStatus = await self.backends[method][
|
||||
unit
|
||||
@@ -482,6 +483,7 @@ class Ledger(LedgerVerification, LedgerSpendingConditions):
|
||||
assert mint_quote.method == method.name, "methods do not match"
|
||||
assert not mint_quote.paid, "mint quote already paid"
|
||||
assert not mint_quote.issued, "mint quote already issued"
|
||||
assert mint_quote.checking_id, "mint quote has no checking id"
|
||||
payment_quote = PaymentQuoteResponse(
|
||||
checking_id=mint_quote.checking_id,
|
||||
amount=Amount(unit, mint_quote.amount),
|
||||
|
||||
@@ -49,7 +49,6 @@ async def test_blink_create_invoice():
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
|
||||
invoice = await blink.create_invoice(Amount(Unit.sat, 1000))
|
||||
assert invoice.checking_id == invoice.payment_request
|
||||
@@ -129,9 +128,18 @@ async def test_blink_get_payment_status():
|
||||
@respx.mock
|
||||
@pytest.mark.asyncio
|
||||
async def test_blink_get_payment_quote():
|
||||
# response says 1 sat fees but invoice * 0.5% is 5 sat so we expect 5 sat
|
||||
mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 1}}}
|
||||
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
|
||||
quote = await blink.get_payment_quote(payment_request)
|
||||
assert quote.checking_id == payment_request
|
||||
assert quote.amount == Amount(Unit.msat, 1000000) # msat
|
||||
assert quote.fee == Amount(Unit.msat, 5000) # msat
|
||||
|
||||
# response says 10 sat fees but invoice * 0.5% is 5 sat so we expect 10 sat
|
||||
mock_response = {"data": {"lnInvoiceFeeProbe": {"amount": 10}}}
|
||||
respx.post(blink.endpoint).mock(return_value=Response(200, json=mock_response))
|
||||
quote = await blink.get_payment_quote(payment_request)
|
||||
assert quote.checking_id == payment_request
|
||||
assert quote.amount == Amount(Unit.msat, 1000000) # msat
|
||||
assert quote.fee == Amount(Unit.msat, 500000) # msat
|
||||
assert quote.fee == Amount(Unit.msat, 10000) # msat
|
||||
|
||||
Reference in New Issue
Block a user