mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
* add websockets for quote updates * add test (not working) * wip: emit events to everyone * wip: emit events to everyone * wip, lots of things broken but invoice callback works * wip * add wip files * tests almost passing * add task * refactor nut constants * startup fix * works with old mints * wip cli * fix mypy * remove automatic invoice test now with websockets * remove comment * better logging * send back response * add rate limiter to websocket * add rate limiter to subscriptions * refactor websocket ratelimit * websocket tests * subscription kinds * doesnt start * remove circular import * update * fix mypy * move test file in test because it fails if it runs later... dunno why * adjust websocket NUT-06 settings * local import and small fix * disable websockets in CLI if "no_check" is selected * move subscription test to where it was * check proof state with callback, add tests * tests: run mint fixture per module instead of per session * subscription command name fix * test per session again * update test race conditions * fix tests * clean up * tmp * fix db issues and remove cached secrets * fix tests * blindly try pipeline * remove comments * comments
86 lines
2.6 KiB
Python
86 lines
2.6 KiB
Python
import pytest
|
|
import pytest_asyncio
|
|
|
|
from cashu.core.models import PostMeltQuoteRequest
|
|
from cashu.mint.ledger import Ledger
|
|
from cashu.wallet.wallet import Wallet
|
|
from cashu.wallet.wallet import Wallet as Wallet1
|
|
from tests.conftest import SERVER_ENDPOINT
|
|
from tests.helpers import is_postgres
|
|
|
|
|
|
async def assert_err(f, msg):
|
|
"""Compute f() and expect an error message 'msg'."""
|
|
try:
|
|
await f
|
|
except Exception as exc:
|
|
if msg not in str(exc.args[0]):
|
|
raise Exception(f"Expected error: {msg}, got: {exc.args[0]}")
|
|
return
|
|
raise Exception(f"Expected error: {msg}, got no error")
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="function")
|
|
async def wallet1(ledger: Ledger):
|
|
wallet1 = await Wallet1.with_db(
|
|
url=SERVER_ENDPOINT,
|
|
db="test_data/wallet1",
|
|
name="wallet1",
|
|
)
|
|
await wallet1.load_mint()
|
|
yield wallet1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_mint_quote(wallet1: Wallet, ledger: Ledger):
|
|
invoice = await wallet1.request_mint(128)
|
|
assert invoice is not None
|
|
quote = await ledger.crud.get_mint_quote(quote_id=invoice.id, db=ledger.db)
|
|
assert quote is not None
|
|
assert quote.quote == invoice.id
|
|
assert quote.amount == 128
|
|
assert quote.unit == "sat"
|
|
assert not quote.paid
|
|
assert quote.checking_id == invoice.payment_hash
|
|
assert quote.paid_time is None
|
|
assert quote.created_time
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_mint_quote_by_request(wallet1: Wallet, ledger: Ledger):
|
|
invoice = await wallet1.request_mint(128)
|
|
assert invoice is not None
|
|
quote = await ledger.crud.get_mint_quote(request=invoice.bolt11, db=ledger.db)
|
|
assert quote is not None
|
|
assert quote.quote == invoice.id
|
|
assert quote.amount == 128
|
|
assert quote.unit == "sat"
|
|
assert not quote.paid
|
|
assert quote.paid_time is None
|
|
assert quote.created_time
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_melt_quote(wallet1: Wallet, ledger: Ledger):
|
|
invoice = await wallet1.request_mint(128)
|
|
assert invoice is not None
|
|
melt_quote = await ledger.melt_quote(
|
|
PostMeltQuoteRequest(request=invoice.bolt11, unit="sat")
|
|
)
|
|
quote = await ledger.crud.get_melt_quote(quote_id=melt_quote.quote, db=ledger.db)
|
|
assert quote is not None
|
|
assert quote.quote == melt_quote.quote
|
|
assert quote.amount == 128
|
|
assert quote.unit == "sat"
|
|
assert not quote.paid
|
|
assert quote.checking_id == invoice.payment_hash
|
|
assert quote.paid_time is None
|
|
assert quote.created_time
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
@pytest.mark.skipif(not is_postgres, reason="only works with Postgres")
|
|
async def test_postgres_working():
|
|
assert is_postgres
|
|
assert True
|