mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
[Mint] add mint api tests (#189)
* add mint api tests * add /info test and fix NUT-09 contact info strings * add test mint api * replace with requests
This commit is contained in:
@@ -25,12 +25,12 @@ NOSTR_RELAYS=["wss://nostr-pub.wellorder.net"]
|
||||
|
||||
# --------- MINT ---------
|
||||
|
||||
# MINT
|
||||
MINT_INFO_NAME="My Cashu mint"
|
||||
MINT_INFO_PUBKEY="<hex_pubkey>"
|
||||
MINT_INFO_DESCRIPTION="The short mint description"
|
||||
MINT_INFO_DESCRIPTION_LONG="A long mint description that can be a long piece of text."
|
||||
MINT_INFO_CONTACT=["Email: contact@me.com", "Twitter: @me", "Nostr: npub..."]
|
||||
# MINT_INFO_MOTD="Message to users"
|
||||
MINT_INFO_CONTACT=[["email","contact@me.com"], ["twitter","@me"], ["nostr", "npub..."]]
|
||||
MINT_INFO_MOTD="Message to users"
|
||||
|
||||
MINT_PRIVATE_KEY=supersecretprivatekey
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ class GetInfoResponse(BaseModel):
|
||||
version: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
description_long: Optional[str] = None
|
||||
contact: Optional[List[str]] = None
|
||||
contact: Optional[List[List[str]]] = None
|
||||
nuts: Optional[List[str]] = None
|
||||
motd: Optional[str] = None
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class CashuSettings(BaseSettings):
|
||||
class EnvSettings(CashuSettings):
|
||||
debug: bool = Field(default=False)
|
||||
host: str = Field(default="127.0.0.1")
|
||||
port: int = Field(default=5000)
|
||||
port: int = Field(default=3338)
|
||||
cashu_dir: str = Field(default=os.path.join(str(Path.home()), ".cashu"))
|
||||
|
||||
|
||||
@@ -64,8 +64,8 @@ class MintInformation(CashuSettings):
|
||||
mint_info_name: str = Field(default="Cashu mint")
|
||||
mint_info_description: str = Field(default=None)
|
||||
mint_info_description_long: str = Field(default=None)
|
||||
mint_info_contact: List[str] = Field(default=[])
|
||||
mint_info_nuts: List[str] = Field(default=["NUT-07", "NUT-08"])
|
||||
mint_info_contact: List[List[str]] = Field(default=[["", ""]])
|
||||
mint_info_nuts: List[str] = Field(default=["NUT-07", "NUT-08", "NUT-09"])
|
||||
mint_info_motd: str = Field(default=None)
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from pathlib import Path
|
||||
@@ -8,9 +9,13 @@ import pytest_asyncio
|
||||
import uvicorn
|
||||
from uvicorn import Config, Server
|
||||
|
||||
from cashu.core.db import Database
|
||||
from cashu.core.migrations import migrate_databases
|
||||
from cashu.core.settings import settings
|
||||
from cashu.wallet import migrations
|
||||
from cashu.lightning.fake import FakeWallet
|
||||
from cashu.mint import migrations as migrations_mint
|
||||
from cashu.mint.ledger import Ledger
|
||||
from cashu.wallet import migrations as migrations_wallet
|
||||
from cashu.wallet.wallet import Wallet
|
||||
|
||||
SERVER_ENDPOINT = "http://localhost:3337"
|
||||
@@ -61,3 +66,23 @@ def mint():
|
||||
time.sleep(1)
|
||||
yield server
|
||||
server.stop()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def ledger():
|
||||
async def start_mint_init(ledger):
|
||||
await migrate_databases(ledger.db, migrations_mint)
|
||||
await ledger.load_used_proofs()
|
||||
await ledger.init_keysets()
|
||||
|
||||
db_file = "data/mint/test.sqlite3"
|
||||
if os.path.exists(db_file):
|
||||
os.remove(db_file)
|
||||
ledger = Ledger(
|
||||
db=Database("test", "data/mint"),
|
||||
seed="TEST_PRIVATE_KEY",
|
||||
derivation_path="0/0/0/0",
|
||||
lightning=FakeWallet(),
|
||||
)
|
||||
await start_mint_init(ledger)
|
||||
yield ledger
|
||||
|
||||
@@ -1,20 +1,15 @@
|
||||
from typing import List
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
|
||||
from cashu.core.base import BlindedMessage, Proof
|
||||
from cashu.core.migrations import migrate_databases
|
||||
|
||||
SERVER_ENDPOINT = "http://localhost:3338"
|
||||
|
||||
import os
|
||||
|
||||
from cashu.core.db import Database
|
||||
from cashu.core.settings import settings
|
||||
from cashu.lightning.fake import FakeWallet
|
||||
from cashu.mint import migrations
|
||||
from cashu.mint.ledger import Ledger
|
||||
from tests.conftest import ledger
|
||||
|
||||
|
||||
async def assert_err(f, msg):
|
||||
@@ -32,27 +27,6 @@ def assert_amt(proofs: List[Proof], expected: int):
|
||||
assert [p.amount for p in proofs] == expected
|
||||
|
||||
|
||||
async def start_mint_init(ledger):
|
||||
await migrate_databases(ledger.db, migrations)
|
||||
await ledger.load_used_proofs()
|
||||
await ledger.init_keysets()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture(scope="function")
|
||||
async def ledger():
|
||||
db_file = "data/mint/test.sqlite3"
|
||||
if os.path.exists(db_file):
|
||||
os.remove(db_file)
|
||||
ledger = Ledger(
|
||||
db=Database("test", "data/mint"),
|
||||
seed="TEST_PRIVATE_KEY",
|
||||
derivation_path="0/0/0/0",
|
||||
lightning=FakeWallet(),
|
||||
)
|
||||
await start_mint_init(ledger)
|
||||
yield ledger
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_pubkeys(ledger: Ledger):
|
||||
assert ledger.keyset.public_keys
|
||||
|
||||
44
tests/test_mint_api.py
Normal file
44
tests/test_mint_api.py
Normal file
@@ -0,0 +1,44 @@
|
||||
import asyncio
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
import requests
|
||||
|
||||
from cashu.core.settings import settings
|
||||
from tests.conftest import ledger
|
||||
|
||||
BASE_URL = f"http://localhost:3337"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_info(ledger):
|
||||
response = requests.get(f"{BASE_URL}/info")
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
assert response.json()["pubkey"] == ledger.pubkey.serialize().hex()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_keys(ledger):
|
||||
response = requests.get(f"{BASE_URL}/keys")
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
assert response.json() == {
|
||||
str(k): v.serialize().hex() for k, v in ledger.keyset.public_keys.items()
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_keysets(ledger):
|
||||
response = requests.get(f"{BASE_URL}/keysets")
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
assert response.json()["keysets"] == list(ledger.keysets.keysets.keys())
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_api_keyset_keys(ledger):
|
||||
response = requests.get(
|
||||
f"{BASE_URL}/keys/{'1cCNIAZ2X/w1'.replace('/', '_').replace('+', '-')}"
|
||||
)
|
||||
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
||||
assert response.json() == {
|
||||
str(k): v.serialize().hex() for k, v in ledger.keyset.public_keys.items()
|
||||
}
|
||||
Reference in New Issue
Block a user