mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-02-10 11:14:20 +01:00
Keysets per seed and postgres (#400)
* allow generation of keys per seed phrase * emit errors correctly * parse timestamps for melt and mint quotes correctly * error messages * adjust error message * postgres works * prepare postgres tests * timestamps refactor * add command to key activation * generate keys per seed * add keyset tests * keyest uniqueness constaint on (derivation_path, seed) * add tables ony if not exists * log leve
This commit is contained in:
63
tests/test_mint_db.py
Normal file
63
tests/test_mint_db.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from cashu.core.base 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
|
||||
|
||||
|
||||
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_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
|
||||
57
tests/test_mint_keysets.py
Normal file
57
tests/test_mint_keysets.py
Normal file
@@ -0,0 +1,57 @@
|
||||
import pytest
|
||||
|
||||
from cashu.core.base import MintKeyset
|
||||
from cashu.core.settings import settings
|
||||
|
||||
SEED = "TEST_PRIVATE_KEY"
|
||||
DERIVATION_PATH = "m/0'/0'/0'"
|
||||
|
||||
|
||||
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.mark.asyncio
|
||||
async def test_keyset_0_15_0():
|
||||
keyset = MintKeyset(seed=SEED, derivation_path=DERIVATION_PATH, version="0.15.0")
|
||||
assert len(keyset.public_keys_hex) == settings.max_order
|
||||
assert keyset.seed == "TEST_PRIVATE_KEY"
|
||||
assert keyset.derivation_path == "m/0'/0'/0'"
|
||||
assert (
|
||||
keyset.public_keys_hex[1]
|
||||
== "02194603ffa36356f4a56b7df9371fc3192472351453ec7398b8da8117e7c3e104"
|
||||
)
|
||||
assert keyset.id == "009a1f293253e41e"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_keyset_0_14_0():
|
||||
keyset = MintKeyset(seed=SEED, derivation_path=DERIVATION_PATH, version="0.14.0")
|
||||
assert len(keyset.public_keys_hex) == settings.max_order
|
||||
assert keyset.seed == "TEST_PRIVATE_KEY"
|
||||
assert keyset.derivation_path == "m/0'/0'/0'"
|
||||
assert (
|
||||
keyset.public_keys_hex[1]
|
||||
== "036d6f3adf897e88e16ece3bffb2ce57a0b635fa76f2e46dbe7c636a937cd3c2f2"
|
||||
)
|
||||
assert keyset.id == "xnI+Y0j7cT1/"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_keyset_0_11_0():
|
||||
keyset = MintKeyset(seed=SEED, derivation_path=DERIVATION_PATH, version="0.11.0")
|
||||
assert len(keyset.public_keys_hex) == settings.max_order
|
||||
assert keyset.seed == "TEST_PRIVATE_KEY"
|
||||
assert keyset.derivation_path == "m/0'/0'/0'"
|
||||
assert (
|
||||
keyset.public_keys_hex[1]
|
||||
== "026b714529f157d4c3de5a93e3a67618475711889b6434a497ae6ad8ace6682120"
|
||||
)
|
||||
assert keyset.id == "Zkdws9zWxNc4"
|
||||
Reference in New Issue
Block a user