mirror of
https://github.com/aljazceru/nutshell.git
synced 2026-02-04 00:04: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:
@@ -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