Nut07/proof pending (#277)

* add pending state

* proofs spendable check and tests

* bump version to 0.12.3

* remove sleep for testing

* comment clarify

* use list comprehension in pending list
This commit is contained in:
callebtc
2023-07-08 22:50:17 +02:00
committed by GitHub
parent 56040594b7
commit 73b015b642
11 changed files with 90 additions and 40 deletions

View File

@@ -93,20 +93,20 @@ async def ledger():
yield ledger
@pytest.fixture(autouse=True, scope="session")
def mint_3338():
settings.mint_listen_port = 3338
settings.port = 3338
settings.mint_url = "http://localhost:3338"
settings.port = settings.mint_listen_port
config = uvicorn.Config(
"cashu.mint.app:app",
port=settings.mint_listen_port,
host="127.0.0.1",
)
# @pytest.fixture(autouse=True, scope="session")
# def mint_3338():
# settings.mint_listen_port = 3338
# settings.port = 3338
# settings.mint_url = "http://localhost:3338"
# settings.port = settings.mint_listen_port
# config = uvicorn.Config(
# "cashu.mint.app:app",
# port=settings.mint_listen_port,
# host="127.0.0.1",
# )
server = UvicornServer(config=config, private_key="SECOND_PRIVATE_KEY")
server.start()
time.sleep(1)
yield server
server.stop()
# server = UvicornServer(config=config, private_key="SECOND_PRIVATE_KEY")
# server.start()
# time.sleep(1)
# yield server
# server.stop()

View File

@@ -1,9 +1,11 @@
import asyncio
import json
import pytest
import pytest_asyncio
import requests
from cashu.core.base import CheckSpendableRequest, CheckSpendableResponse, Proof
from cashu.core.settings import settings
from tests.conftest import ledger
@@ -54,3 +56,22 @@ async def test_api_mint_validation(ledger):
assert "error" in response.json()
response = requests.get(f"{BASE_URL}/mint?amount=1")
assert "error" 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

View File

@@ -367,3 +367,12 @@ async def test_p2sh_receive_with_wrong_wallet(wallet1: Wallet, wallet2: Wallet):
wallet1.proofs, 8, secret_lock
) # sender side
await assert_err(wallet2.redeem(send_proofs), "lock not found.") # wrong receiver
@pytest.mark.asyncio
async def test_token_state(wallet1: Wallet):
await wallet1.mint(64)
assert wallet1.balance == 64
resp = await wallet1.check_proof_state(wallet1.proofs)
assert resp.dict()["spendable"]
assert resp.dict()["pending"]