Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 21, 2023
1 parent e1a9104 commit 48c15a7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
13 changes: 10 additions & 3 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cashu.core.base import CheckSpendableRequest, CheckSpendableResponse, Proof
from cashu.mint.ledger import Ledger
from cashu.wallet.wallet import Wallet
from tests.helpers import pay_if_regtest
from tests.helpers import get_real_invoice, is_regtest, pay_if_regtest

BASE_URL = "http://localhost:3337"

Expand Down Expand Up @@ -201,9 +201,16 @@ async def test_melt(ledger: Ledger, wallet: Wallet):
assert wallet.balance == 64

# create invoice to melt to
# we melt 2 satoshis less because of the fee reserve
# use 2 sat less because we need to pay the fee
invoice = await wallet.request_mint(62)
quote = await wallet.melt_quote(invoice.bolt11)

invoice_payment_request = invoice.bolt11
if is_regtest:
invoice_dict = get_real_invoice(62)
invoice_payment_request = invoice_dict["payment_request"]
str(invoice_dict["r_hash"])

quote = await wallet.melt_quote(invoice_payment_request)
inputs_payload = [p.to_dict() for p in wallet.proofs]

# outputs for change
Expand Down
14 changes: 9 additions & 5 deletions tests/test_mint_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from cashu.wallet.wallet import Wallet
from cashu.wallet.wallet import Wallet as Wallet1
from tests.conftest import SERVER_ENDPOINT
from tests.helpers import pay_if_regtest
from tests.helpers import get_real_invoice, is_regtest, pay_if_regtest


@pytest_asyncio.fixture(scope="function")
Expand All @@ -29,14 +29,18 @@ async def test_melt(wallet1: Wallet, ledger: Ledger):
invoice = await wallet1.request_mint(64)
pay_if_regtest(invoice.bolt11)
await wallet1.mint(64, id=invoice.id)
invoice_payment_request = invoice.bolt11
if is_regtest:
invoice_dict = get_real_invoice(64)
invoice_payment_request = invoice_dict["payment_request"]
str(invoice_dict["r_hash"])

assert wallet1.balance == 128
mint_quote = await wallet1.get_pay_amount_with_fees(invoice.bolt11)
# mint_fees = await ledger._get_lightning_fees(invoice.bolt11)
# assert mint_fees == mint_quote.fee_reserve
mint_quote = await wallet1.get_pay_amount_with_fees(invoice_payment_request)
total_amount = mint_quote.amount + mint_quote.fee_reserve
keep_proofs, send_proofs = await wallet1.split_to_send(wallet1.proofs, total_amount)
melt_quote = await ledger.melt_quote(
PostMeltQuoteRequest(request=invoice.bolt11, unit="sat")
PostMeltQuoteRequest(request=invoice_payment_request, unit="sat")
)
await ledger.melt(proofs=send_proofs, quote=melt_quote.quote)

Expand Down

0 comments on commit 48c15a7

Please sign in to comment.