mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 19:14:19 +01:00
* `PaymentResult` * ledger: rely on PaymentResult instead of paid flag. Double check for payments marked pending. * `None` is `PENDING` * make format * reflected changes API tests where `PaymentStatus` is used + reflected changes in lnbits * reflect changes in blink backend and tests * fix lnbits get_payment_status * remove paid flag * fix mypy * remove more paid flags * fix strike mypy * green * shorten all state checks * fix * fix some tests * gimme ✅ * fix............ * fix lnbits * fix error * lightning refactor * add more regtest tests * add tests for pending state and failure * shorten checks * use match case for startup check - and remember modified checking_id from pay_invoice * fix strike pending return * new tests? * refactor startup routine into get_melt_quote * test with purge * refactor blink * cleanup responses * blink: return checking_id on failure * fix lndgrpc try except * add more testing for melt branches * speed things up a bit * remove comments * remove comments * block pending melt quotes * remove comments --------- Co-authored-by: lollerfirst <lollerfirst@gmail.com>
107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
import asyncio
|
|
|
|
import bolt11
|
|
import pytest
|
|
import pytest_asyncio
|
|
|
|
from cashu.mint.ledger import Ledger
|
|
from cashu.wallet.wallet import Wallet
|
|
from tests.conftest import SERVER_ENDPOINT
|
|
from tests.helpers import (
|
|
SLEEP_TIME,
|
|
cancel_invoice,
|
|
get_hold_invoice,
|
|
is_fake,
|
|
pay_if_regtest,
|
|
settle_invoice,
|
|
)
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="function")
|
|
async def wallet():
|
|
wallet = await Wallet.with_db(
|
|
url=SERVER_ENDPOINT,
|
|
db="test_data/wallet",
|
|
name="wallet",
|
|
)
|
|
await wallet.load_mint()
|
|
yield wallet
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skipif(is_fake, reason="only regtest")
|
|
async def test_regtest_pending_quote(wallet: Wallet, ledger: Ledger):
|
|
# fill wallet
|
|
invoice = await wallet.request_mint(64)
|
|
await pay_if_regtest(invoice.bolt11)
|
|
await wallet.mint(64, id=invoice.id)
|
|
assert wallet.balance == 64
|
|
|
|
# create hodl invoice
|
|
preimage, invoice_dict = get_hold_invoice(16)
|
|
invoice_payment_request = str(invoice_dict["payment_request"])
|
|
|
|
# wallet pays the invoice
|
|
quote = await wallet.melt_quote(invoice_payment_request)
|
|
total_amount = quote.amount + quote.fee_reserve
|
|
_, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount)
|
|
asyncio.create_task(
|
|
wallet.melt(
|
|
proofs=send_proofs,
|
|
invoice=invoice_payment_request,
|
|
fee_reserve_sat=quote.fee_reserve,
|
|
quote_id=quote.quote,
|
|
)
|
|
)
|
|
await asyncio.sleep(SLEEP_TIME)
|
|
|
|
states = await wallet.check_proof_state(send_proofs)
|
|
assert all([s.pending for s in states.states])
|
|
|
|
settle_invoice(preimage=preimage)
|
|
|
|
await asyncio.sleep(SLEEP_TIME)
|
|
|
|
states = await wallet.check_proof_state(send_proofs)
|
|
assert all([s.spent for s in states.states])
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skipif(is_fake, reason="only regtest")
|
|
async def test_regtest_failed_quote(wallet: Wallet, ledger: Ledger):
|
|
# fill wallet
|
|
invoice = await wallet.request_mint(64)
|
|
await pay_if_regtest(invoice.bolt11)
|
|
await wallet.mint(64, id=invoice.id)
|
|
assert wallet.balance == 64
|
|
|
|
# create hodl invoice
|
|
preimage, invoice_dict = get_hold_invoice(16)
|
|
invoice_payment_request = str(invoice_dict["payment_request"])
|
|
invoice_obj = bolt11.decode(invoice_payment_request)
|
|
preimage_hash = invoice_obj.payment_hash
|
|
|
|
# wallet pays the invoice
|
|
quote = await wallet.melt_quote(invoice_payment_request)
|
|
total_amount = quote.amount + quote.fee_reserve
|
|
_, send_proofs = await wallet.swap_to_send(wallet.proofs, total_amount)
|
|
asyncio.create_task(
|
|
wallet.melt(
|
|
proofs=send_proofs,
|
|
invoice=invoice_payment_request,
|
|
fee_reserve_sat=quote.fee_reserve,
|
|
quote_id=quote.quote,
|
|
)
|
|
)
|
|
await asyncio.sleep(SLEEP_TIME)
|
|
|
|
states = await wallet.check_proof_state(send_proofs)
|
|
assert all([s.pending for s in states.states])
|
|
|
|
cancel_invoice(preimage_hash=preimage_hash)
|
|
|
|
await asyncio.sleep(SLEEP_TIME)
|
|
|
|
states = await wallet.check_proof_state(send_proofs)
|
|
assert all([s.unspent for s in states.states])
|