mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-22 11:24:19 +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>
72 lines
2.4 KiB
Python
72 lines
2.4 KiB
Python
import pytest
|
|
import requests
|
|
|
|
from cashu.core.base import CheckSpendableRequest, CheckSpendableResponse, Proof
|
|
|
|
BASE_URL = "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()
|
|
}
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_api_mint_validation(ledger):
|
|
response = requests.get(f"{BASE_URL}/mint?amount=-21")
|
|
assert "detail" in response.json()
|
|
response = requests.get(f"{BASE_URL}/mint?amount=0")
|
|
assert "detail" in response.json()
|
|
response = requests.get(f"{BASE_URL}/mint?amount=2100000000000001")
|
|
assert "detail" in response.json()
|
|
response = requests.get(f"{BASE_URL}/mint?amount=1")
|
|
assert "detail" not in response.json()
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_api_check_state(ledger):
|
|
proofs = [
|
|
Proof(id="1234", amount=0, secret="asdasdasd", C="asdasdasd"),
|
|
Proof(id="1234", amount=0, secret="asdasdasd1", C="asdasdasd1"),
|
|
]
|
|
payload = CheckSpendableRequest(proofs=proofs)
|
|
response = requests.post(
|
|
f"{BASE_URL}/check",
|
|
data=payload.json(),
|
|
)
|
|
assert response.status_code == 200, f"{response.url} {response.status_code}"
|
|
states = CheckSpendableResponse.parse_obj(response.json())
|
|
assert states.spendable
|
|
assert len(states.spendable) == 2
|
|
assert states.pending
|
|
assert len(states.pending) == 2
|