diff --git a/cashu/lightning/fake.py b/cashu/lightning/fake.py index 59073fd1..1d3cbab1 100644 --- a/cashu/lightning/fake.py +++ b/cashu/lightning/fake.py @@ -30,6 +30,7 @@ class FakeWallet(LightningBackend): + unit: Unit fake_btc_price = 1e8 / 1337 paid_invoices_queue: asyncio.Queue[Bolt11] = asyncio.Queue(0) payment_secrets: Dict[str, str] = dict() @@ -46,7 +47,6 @@ class FakeWallet(LightningBackend): ).hex() supported_units = {Unit.sat, Unit.msat, Unit.usd, Unit.eur} - unit = Unit.sat supports_incoming_payment_stream: bool = True supports_description: bool = True diff --git a/tests/conftest.py b/tests/conftest.py index 024f02b7..4ccebc61 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,6 +33,7 @@ settings.tor = False settings.wallet_unit = "sat" settings.mint_backend_bolt11_sat = settings.mint_backend_bolt11_sat or "FakeWallet" +settings.mint_backend_bolt11_usd = settings.mint_backend_bolt11_usd or "FakeWallet" settings.fakewallet_brr = True settings.fakewallet_delay_outgoing_payment = 0 settings.fakewallet_delay_incoming_payment = 1 @@ -42,7 +43,7 @@ ), "Test database is the same as the main database" settings.mint_database = settings.mint_test_database settings.mint_derivation_path = "m/0'/0'/0'" -settings.mint_derivation_path_list = [] +settings.mint_derivation_path_list = ["m/0'/2'/0'"] # USD settings.mint_private_key = "TEST_PRIVATE_KEY" settings.mint_seed_decryption_key = "" settings.mint_max_balance = 0 @@ -85,13 +86,6 @@ def run(self, *args, **kwargs): async def ledger(): async def start_mint_init(ledger: Ledger) -> Ledger: await migrate_databases(ledger.db, migrations_mint) - ledger = Ledger( - db=Database("mint", settings.mint_database), - seed=settings.mint_private_key, - derivation_path=settings.mint_derivation_path, - backends=backends, - crud=LedgerCrudSqlite(), - ) await ledger.startup_ledger() return ledger @@ -110,9 +104,17 @@ async def start_mint_init(ledger: Ledger) -> Ledger: await db.engine.dispose() wallets_module = importlib.import_module("cashu.lightning") - lightning_backend = getattr(wallets_module, settings.mint_backend_bolt11_sat)() + lightning_backend_sat = getattr(wallets_module, settings.mint_backend_bolt11_sat)( + unit=Unit.sat + ) + lightning_backend_usd = getattr(wallets_module, settings.mint_backend_bolt11_usd)( + unit=Unit.usd + ) backends = { - Method.bolt11: {Unit.sat: lightning_backend}, + Method.bolt11: { + Unit.sat: lightning_backend_sat, + Unit.usd: lightning_backend_usd, + }, } ledger = Ledger( db=Database("mint", settings.mint_database), diff --git a/tests/test_mint_api.py b/tests/test_mint_api.py index aa5b402f..fe38bc70 100644 --- a/tests/test_mint_api.py +++ b/tests/test_mint_api.py @@ -94,6 +94,12 @@ async def test_api_keysets(ledger: Ledger): "active": True, "input_fee_ppk": 0, }, + { + "id": "00c074b96c7e2b0e", + "unit": "usd", + "active": True, + "input_fee_ppk": 0, + }, ] } assert response.json() == expected diff --git a/tests/test_mint_init.py b/tests/test_mint_init.py index 71aa7021..60817fe3 100644 --- a/tests/test_mint_init.py +++ b/tests/test_mint_init.py @@ -60,7 +60,7 @@ async def wallet(ledger: Ledger): async def test_init_keysets(ledger: Ledger): ledger.keysets = {} await ledger.init_keysets() - assert len(ledger.keysets) == 1 + assert len(ledger.keysets) == 2 @pytest.mark.asyncio diff --git a/tests/test_mint_melt.py b/tests/test_mint_melt.py index 22bc0b50..c135992f 100644 --- a/tests/test_mint_melt.py +++ b/tests/test_mint_melt.py @@ -343,35 +343,28 @@ async def test_mint_melt_different_units(ledger: Ledger, wallet: Wallet): amount = 32 - # create a mint quote that is unpaid + # mint quote in sat sat_mint_quote = await ledger.mint_quote( quote_request=PostMintQuoteRequest(amount=amount, unit="sat") ) sat_invoice = sat_mint_quote.request assert sat_mint_quote.paid is False - # create a melt quote with above invoice in different unit + # melt quote in usd usd_melt_quote = await ledger.melt_quote( PostMeltQuoteRequest(unit="usd", request=sat_invoice) ) assert usd_melt_quote.paid is False - melt_resp = await ledger.melt(proofs=wallet.proofs, quote=usd_melt_quote.quote) - - assert_err( - melt_resp.state == MeltQuoteState.unpaid.value, - f"Expected state to be paid, got {melt_resp.state}", - ) + # pay melt quote with usd + await ledger.melt(proofs=wallet.proofs, quote=usd_melt_quote.quote) output_amounts = [32] secrets, rs, derivation_paths = await wallet.generate_n_secrets(len(output_amounts)) outputs, rs = wallet._construct_outputs(output_amounts, secrets, rs) - mint_resp = await ledger.mint(outputs=outputs, quote_id=invoice.id) - assert_err(len(mint_resp) > 0, f"Expected promises, got {len(mint_resp)} promises") + # mint in sat + mint_resp = await ledger.mint(outputs=outputs, quote_id=sat_mint_quote.quote) - await assert_err( - ledger.mint(outputs=outputs, quote_id=invoice.id), - "outputs have already been signed before.", - ) + assert len(mint_resp) == len(outputs)