NUT-04 and NUT-05: Add state field to quotes (#560)

* wip adding states, tests failing

* add state field to quotes

* responses from quotes

* store correct state

* cleaner test

* fix swap check

* oops
This commit is contained in:
callebtc
2024-06-26 03:06:01 +02:00
committed by GitHub
parent e846acf946
commit 6b38ef6c29
26 changed files with 330 additions and 84 deletions

View File

@@ -3,7 +3,7 @@ import asyncio
import pytest
import pytest_asyncio
from cashu.core.base import Method, ProofState
from cashu.core.base import Method, MintQuoteState, ProofSpentState, ProofState
from cashu.core.json_rpc.base import JSONRPCNotficationParams
from cashu.core.nuts import WEBSOCKETS_NUT
from cashu.core.settings import settings
@@ -51,20 +51,17 @@ async def test_wallet_subscription_mint(wallet: Wallet):
wait = settings.fakewallet_delay_incoming_payment or 2
await asyncio.sleep(wait + 2)
# TODO: check for pending and paid states according to: https://github.com/cashubtc/nuts/pull/136
# TODO: we have three messages here, but the value "paid" only changes once
# the mint sends an update when the quote is pending but the API does not express that yet
# first we expect the issued=False state to arrive
assert triggered
assert len(msg_stack) == 3
assert msg_stack[0].payload["paid"] is False
assert msg_stack[0].payload["state"] == MintQuoteState.unpaid.value
assert msg_stack[1].payload["paid"] is True
assert msg_stack[1].payload["state"] == MintQuoteState.paid.value
assert msg_stack[2].payload["paid"] is True
assert msg_stack[2].payload["state"] == MintQuoteState.issued.value
@pytest.mark.asyncio
@@ -103,16 +100,16 @@ async def test_wallet_subscription_swap(wallet: Wallet):
pending_stack = msg_stack[:n_subscriptions]
for msg in pending_stack:
proof_state = ProofState.parse_obj(msg.payload)
assert proof_state.state.value == "UNSPENT"
assert proof_state.state == ProofSpentState.unspent
# the second one is the PENDING state
spent_stack = msg_stack[n_subscriptions : n_subscriptions * 2]
for msg in spent_stack:
proof_state = ProofState.parse_obj(msg.payload)
assert proof_state.state.value == "PENDING"
assert proof_state.state == ProofSpentState.pending
# the third one is the SPENT state
spent_stack = msg_stack[n_subscriptions * 2 :]
for msg in spent_stack:
proof_state = ProofState.parse_obj(msg.payload)
assert proof_state.state.value == "SPENT"
assert proof_state.state == ProofSpentState.spent