Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 17, 2023
1 parent a2ff6db commit 3f98d4b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions cashu/mint/ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ async def melt(
# TODO: needs logic to look up the lightning invoice from the quote ID
melt_quote = await self.crud.get_melt_quote(quote_id=quote, db=self.db)
assert melt_quote, "quote not found"
assert not melt_quote.paid, "quote already paid"
assert not melt_quote.paid, "melt quote already paid"
bolt11_request = melt_quote.request

logger.trace("melt called")
Expand Down Expand Up @@ -440,8 +440,8 @@ async def melt(
assert mint_quote.amount == invoice_amount, "amounts do not match"
assert mint_quote.unit == melt_quote.unit, "units do not match"
assert mint_quote.method == melt_quote.method, "methods do not match"
assert not mint_quote.paid, "quote already paid"
assert not mint_quote.issued, "quote already issued"
assert not mint_quote.paid, "mint quote already paid"
assert not mint_quote.issued, "mint quote already issued"
# we can handle this transaction internally
await self.crud.update_mint_quote_paid(
quote_id=mint_quote.quote, paid=True, db=self.db
Expand Down
4 changes: 2 additions & 2 deletions cashu/mint/router_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ async def melt_deprecated(
quote = await ledger.melt_quote(
PostMeltQuoteRequest(request=payload.pr, unit="sat", method="bolt11")
)
ok, preimage, change_promises = await ledger.melt(
preimage, change_promises = await ledger.melt(
proofs=payload.proofs, quote=quote.quote, outputs=payload.outputs
)
resp = PostMeltResponse_deprecated(
paid=ok, preimage=preimage, change=change_promises
paid=True, preimage=preimage, change=change_promises
)
logger.trace(f"< POST /melt: {resp}")
return resp
Expand Down
8 changes: 4 additions & 4 deletions tests/test_mint.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ async def test_generate_change_promises(ledger: Ledger):
invoice_amount = 100_000
fee_reserve = 2_000
total_provided = invoice_amount + fee_reserve
actual_fee_msat = 100_000
actual_fee = 100

expected_returned_promises = 7 # Amounts = [4, 8, 32, 64, 256, 512, 1024]
expected_returned_fees = 1900
Expand All @@ -178,7 +178,7 @@ async def test_generate_change_promises(ledger: Ledger):
]

promises = await ledger._generate_change_promises(
total_provided, invoice_amount, actual_fee_msat, outputs
total_provided, invoice_amount, actual_fee, outputs
)

assert len(promises) == expected_returned_promises
Expand All @@ -192,7 +192,7 @@ async def test_generate_change_promises_legacy_wallet(ledger: Ledger):
invoice_amount = 100_000
fee_reserve = 2_000
total_provided = invoice_amount + fee_reserve
actual_fee_msat = 100_000
actual_fee = 100

expected_returned_promises = 4 # Amounts = [64, 256, 512, 1024]
expected_returned_fees = 1856
Expand All @@ -204,7 +204,7 @@ async def test_generate_change_promises_legacy_wallet(ledger: Ledger):
]

promises = await ledger._generate_change_promises(
total_provided, invoice_amount, actual_fee_msat, outputs
total_provided, invoice_amount, actual_fee, outputs
)

assert len(promises) == expected_returned_promises
Expand Down
7 changes: 4 additions & 3 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ async def test_mint(ledger: Ledger, wallet: Wallet):
invoice = await wallet.request_mint(64)
pay_if_regtest(invoice.bolt11)
quote_id = invoice.id
secrets, rs, derivation_paths = await wallet.generate_n_secrets(2, skip_bump=True)
secrets, rs, derivation_paths = await wallet.generate_secrets_from_to(10000, 10001)
outputs, rs = wallet._construct_outputs([32, 32], secrets, rs)
outputs_payload = [o.dict() for o in outputs]
response = httpx.post(
f"{BASE_URL}/v1/mint",
json={"quote": quote_id, "outputs": outputs_payload},
timeout=None,
)
assert response.status_code == 200, f"{response.url} {response.status_code}"
result = response.json()
Expand Down Expand Up @@ -192,8 +193,8 @@ async def test_melt_quote(ledger: Ledger, wallet: Wallet):
assert result["quote"]
assert result["unit"] == "sat"
assert result["amount"] == 64
# internal invoice, fee should be 0
assert result["fee_reserve"] == 0
# TODO: internal invoice, fee should be 0
assert result["fee_reserve"] == 2


@pytest.mark.asyncio
Expand Down
10 changes: 4 additions & 6 deletions tests/test_wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,12 @@ async def test_split_more_than_balance(wallet1: Wallet):
@pytest.mark.asyncio
async def test_melt(wallet1: Wallet):
# mint twice so we have enough to pay the second invoice back
invoice = await wallet1.request_mint(64)
pay_if_regtest(invoice.bolt11)
await wallet1.mint(64, id=invoice.id)
invoice = await wallet1.request_mint(64)
pay_if_regtest(invoice.bolt11)
await wallet1.mint(64, id=invoice.id)
topup_invoice = await wallet1.request_mint(128)
pay_if_regtest(topup_invoice.bolt11)
await wallet1.mint(128, id=topup_invoice.id)
assert wallet1.balance == 128

invoice = await wallet1.request_mint(64)
invoice_payment_hash = str(invoice.payment_hash)
invoice_payment_request = invoice.bolt11
if is_regtest:
Expand Down

0 comments on commit 3f98d4b

Please sign in to comment.