mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 10:34:20 +01:00
* init flake8 * exclude nostr client, and add ds_store to gitignore * fix flake8 F811 issue, redefinition of unused variables * add flake8 to workflow * F401 unused imports * F541 f-string is missing placeholders * E501 line too long > 150 characters * E722 no bare except * E402 module level import not at top of file * F405 no star imports * E712 comparison to False should be 'if cond is False:' * F841 local variable is assigned to but never used * E266 too many leading '#' for block comment * E265, E261 * E713 test for membership should be 'not in' * E711, E741 E741 ambiguous variable name 'l' E711 comparison to None should be 'if cond is None:' * flake config * isort * refactor makefile flake8 usage * reflaking the rebase * black * fix tests? * black * fix line lenght it test_cli * sort out makefile * fix strings * reintroduce black-check * reflake and mypy * isort * Update cashu/wallet/wallet.py Co-authored-by: Angus Pearson <angus@toaster.cc> * Update cashu/mint/ledger.py Co-authored-by: Angus Pearson <angus@toaster.cc> --------- Co-authored-by: Angus Pearson <angus@toaster.cc>
180 lines
5.5 KiB
Python
180 lines
5.5 KiB
Python
import pytest
|
|
import pytest_asyncio
|
|
from fastapi.testclient import TestClient
|
|
|
|
from cashu.core.settings import settings
|
|
from cashu.wallet.api.app import app
|
|
from cashu.wallet.wallet import Wallet
|
|
from tests.conftest import SERVER_ENDPOINT
|
|
|
|
|
|
@pytest_asyncio.fixture(scope="function")
|
|
async def wallet(mint):
|
|
wallet = await Wallet.with_db(
|
|
url=SERVER_ENDPOINT,
|
|
db="data/test_wallet_api",
|
|
name="wallet_api",
|
|
)
|
|
await wallet.load_mint()
|
|
wallet.status()
|
|
yield wallet
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_invoice(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/invoice?amount=100")
|
|
assert response.status_code == 200
|
|
if settings.lightning:
|
|
assert response.json()["invoice"]
|
|
else:
|
|
assert response.json()["amount"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_invoice_with_split(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/invoice?amount=10&split=1")
|
|
assert response.status_code == 200
|
|
if settings.lightning:
|
|
assert response.json()["invoice"]
|
|
else:
|
|
assert response.json()["amount"]
|
|
# await wallet.load_proofs(reload=True)
|
|
# assert wallet.proof_amounts.count(1) >= 10
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_balance():
|
|
with TestClient(app) as client:
|
|
response = client.get("/balance")
|
|
assert response.status_code == 200
|
|
assert response.json()["balance"]
|
|
assert response.json()["keysets"]
|
|
assert response.json()["mints"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_send(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/send?amount=10")
|
|
assert response.status_code == 200
|
|
assert response.json()["balance"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_send_without_split(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/send?amount=2&nosplit=true")
|
|
assert response.status_code == 200
|
|
assert response.json()["balance"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_send_without_split_but_wrong_amount(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/send?amount=10&nosplit=true")
|
|
assert response.status_code == 400
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pending():
|
|
with TestClient(app) as client:
|
|
response = client.get("/pending")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_receive_all(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/receive?all=true")
|
|
assert response.status_code == 200
|
|
assert response.json()["initial_balance"]
|
|
assert response.json()["balance"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_burn_all(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
response = client.post("/send?amount=20")
|
|
assert response.status_code == 200
|
|
response = client.post("/burn?all=true")
|
|
assert response.status_code == 200
|
|
assert response.json()["balance"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_pay():
|
|
with TestClient(app) as client:
|
|
invoice = (
|
|
"lnbc100n1pjzp22cpp58xvjxvagzywky9xz3vurue822aaax"
|
|
"735hzc5pj5fg307y58v5znqdq4vdshx6r4ypjx2ur0wd5hgl"
|
|
"h6ahauv24wdmac4zk478pmwfzd7sdvm8tje3dmfue3lc2g4l"
|
|
"9g40a073h39748uez9p8mxws5vqwjmkqr4wl5l7n4dlhj6z6"
|
|
"va963cqvufrs4"
|
|
)
|
|
response = client.post(f"/pay?invoice={invoice}")
|
|
if not settings.lightning:
|
|
assert response.status_code == 400
|
|
else:
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_lock():
|
|
with TestClient(app) as client:
|
|
response = client.get("/lock")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_locks():
|
|
with TestClient(app) as client:
|
|
response = client.get("/locks")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_invoices():
|
|
with TestClient(app) as client:
|
|
response = client.get("/invoices")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_wallets():
|
|
with TestClient(app) as client:
|
|
response = client.get("/wallets")
|
|
assert response.status_code == 200
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_info():
|
|
with TestClient(app) as client:
|
|
response = client.get("/info")
|
|
assert response.status_code == 200
|
|
assert response.json()["version"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_flow(wallet: Wallet):
|
|
with TestClient(app) as client:
|
|
if not settings.lightning:
|
|
response = client.get("/balance")
|
|
initial_balance = response.json()["balance"]
|
|
response = client.post("/invoice?amount=100")
|
|
response = client.get("/balance")
|
|
assert response.json()["balance"] == initial_balance + 100
|
|
response = client.post("/send?amount=50")
|
|
response = client.get("/balance")
|
|
assert response.json()["balance"] == initial_balance + 50
|
|
response = client.post("/send?amount=50")
|
|
response = client.get("/balance")
|
|
assert response.json()["balance"] == initial_balance
|
|
response = client.get("/pending")
|
|
token = response.json()["pending_token"]["0"]["token"]
|
|
amount = response.json()["pending_token"]["0"]["amount"]
|
|
response = client.post(f"/receive?token={token}")
|
|
response = client.get("/balance")
|
|
assert response.json()["balance"] == initial_balance + amount
|