mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 19:14:19 +01:00
* Add REST API for Cashu wallet * Add simple way to start REST API server * Add simple tests for wallet REST API * Add TokenV3 to REST API * Improve tests for wallet REST API * Make format * Remove unused import * Rename nostr module for API * Unify helper functions for CLI and API * Make format * Move error handling from helper functions to API * Remove 'is_api' flag where possible * Make format, cleanup, add comments * Fix typo for burn also in API * Improve error handling for API * Add flag 'trust_new_mint' to receive command To enable trusting or mistrusting unknown mints via API * Allow selecting mint for sending from API * Fix: set specific mint via API * Fix: select mint with maximum balance via CLI * Use different variables for mint_nr * Allow selecting mint when sending via nostr via API * Remove unnessecary 'is_api' flags from 'send_nostr' * Remove HTTPException from nostr.py * Allow selecting mint for sending with parameter also via CLI * Allow trusting unknown mint for receiving also via CLI * Make format * Enable trusting unknown mint also when receiving via nostr * Fix: wrong indentation of in receive function * Use relative imports for wallet API * Unify get_mint_wallet for CLI and API * Unify send command for CLI and API * Unify receive for CLI and API * Catch errors in nostr via API * Remove flag 'is_api' from verify_mints_tokenv2 * Remove cli_helpers left from last merge * refactor cli selection * load mint in nostr_send * cleanup * add cli_helpers.py * legacy deserialization in cli * make format * clean up api response * fix tests * try pk * verify mints in api * try github tests * Fix: verify_mints for API * Uncomment verify_mints in receive of API * update README * Show mint url in pending * clean up balance response * fix test * mint selection in api * clean up API * CLI: verify mint for receive -a * clean up * Rest -> REST * Remove unused imports --------- Co-authored-by: sihamon <sihamon@proton.me> Co-authored-by: sihamon <126967444+sihamon@users.noreply.github.com>
121 lines
3.7 KiB
Python
121 lines
3.7 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
from cashu.core.settings import settings
|
|
from cashu.wallet.api.app import app
|
|
|
|
|
|
def test_invoice(mint):
|
|
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()["balance"]
|
|
assert response.json()["amount"]
|
|
|
|
|
|
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"]
|
|
|
|
|
|
def test_send(mint):
|
|
with TestClient(app) as client:
|
|
response = client.post("/send?amount=10")
|
|
assert response.status_code == 200
|
|
assert response.json()["balance"]
|
|
|
|
|
|
def test_pending():
|
|
with TestClient(app) as client:
|
|
response = client.get("/pending")
|
|
assert response.status_code == 200
|
|
assert response.json()["0"]
|
|
|
|
|
|
def test_receive_all(mint):
|
|
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"]
|
|
|
|
|
|
def test_burn_all(mint):
|
|
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"]
|
|
|
|
|
|
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
|
|
|
|
|
|
def test_lock():
|
|
with TestClient(app) as client:
|
|
response = client.get("/lock")
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_locks():
|
|
with TestClient(app) as client:
|
|
response = client.get("/locks")
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_invoices():
|
|
with TestClient(app) as client:
|
|
response = client.get("/invoices")
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_wallets():
|
|
with TestClient(app) as client:
|
|
response = client.get("/wallets")
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_info():
|
|
with TestClient(app) as client:
|
|
response = client.get("/info")
|
|
assert response.status_code == 200
|
|
assert response.json()["version"]
|
|
|
|
|
|
def test_flow(mint):
|
|
with TestClient(app) as client:
|
|
if not settings.lightning:
|
|
response = client.get("/balance")
|
|
initial_balance = response.json()["balance"]
|
|
response = client.post("/invoice?amount=100")
|
|
assert response.json()["balance"] == initial_balance + 100
|
|
response = client.post("/send?amount=50")
|
|
assert response.json()["balance"] == initial_balance + 50
|
|
response = client.post("/send?amount=50")
|
|
assert response.json()["balance"] == initial_balance
|
|
response = client.get("/pending")
|
|
token = response.json()["0"]["token"]
|
|
amount = response.json()["0"]["amount"]
|
|
response = client.post(f"/receive?token={token}")
|
|
assert response.json()["balance"] == initial_balance + amount
|