Skip to content

Commit

Permalink
fastapi type hints break things
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 17, 2023
1 parent af2db22 commit 6254b21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cashu/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ class PostSplitResponse_Deprecated(BaseModel):
promises: List[BlindedSignature] = []


class PostSplitResponse_Deprecated_Deprecated(BaseModel):
class PostSplitResponse_Very_Deprecated(BaseModel):
fst: List[BlindedSignature] = []
snd: List[BlindedSignature] = []
deprecated: str = "The amount field is deprecated since 0.13.0"
Expand Down
12 changes: 5 additions & 7 deletions cashu/mint/router_deprecated.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List, Optional, Union
from typing import List, Optional

from fastapi import APIRouter
from loguru import logger
Expand All @@ -20,7 +20,7 @@
PostMintResponse_deprecated,
PostSplitRequest_Deprecated,
PostSplitResponse_Deprecated,
PostSplitResponse_Deprecated_Deprecated,
PostSplitResponse_Very_Deprecated,
)
from ..core.errors import CashuError
from ..core.settings import settings
Expand Down Expand Up @@ -238,7 +238,7 @@ async def check_fees(payload: CheckFeesRequest) -> CheckFeesResponse:
name="Split",
summary="Split proofs at a specified amount",
# response_model=Union[
# PostSplitResponse_Deprecated_Deprecated, PostSplitResponse_Deprecated
# PostSplitResponse_Very_Deprecated, PostSplitResponse_Deprecated
# ],
response_description=(
"A list of blinded signatures that can be used to create proofs."
Expand All @@ -247,7 +247,7 @@ async def check_fees(payload: CheckFeesRequest) -> CheckFeesResponse:
)
async def split_deprecated(
payload: PostSplitRequest_Deprecated,
) -> Union[PostSplitResponse_Deprecated_Deprecated, PostSplitResponse_Deprecated]:
):
"""
Requests a set of Proofs to be split into two a new set of BlindedSignatures.
Expand Down Expand Up @@ -279,9 +279,7 @@ async def split_deprecated(
f" {sum([p.amount for p in frst_promises])} sat and send:"
f" {len(scnd_promises)}: {sum([p.amount for p in scnd_promises])} sat"
)
return PostSplitResponse_Deprecated_Deprecated(
fst=frst_promises, snd=scnd_promises
)
return PostSplitResponse_Very_Deprecated(fst=frst_promises, snd=scnd_promises)
# END backwards compatibility < 0.13
else:
return PostSplitResponse_Deprecated(promises=promises)
15 changes: 10 additions & 5 deletions tests/test_mint_api_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,28 @@ async def wallet(mint):


@pytest.mark.asyncio
async def test_api_keys(ledger):
async def test_api_keys(ledger: Ledger):
response = httpx.get(f"{BASE_URL}/keys")
assert response.status_code == 200, f"{response.url} {response.status_code}"
assert ledger.keyset.public_keys
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):
async def test_api_keysets(ledger: Ledger):
response = httpx.get(f"{BASE_URL}/keysets")
assert response.status_code == 200, f"{response.url} {response.status_code}"
assert ledger.keyset.public_keys
assert response.json()["keysets"] == list(ledger.keysets.keysets.keys())


@pytest.mark.asyncio
async def test_api_keyset_keys(ledger):
async def test_api_keyset_keys(ledger: Ledger):
response = httpx.get(f"{BASE_URL}/keys/d5c08d2006765ffc")
assert response.status_code == 200, f"{response.url} {response.status_code}"
assert ledger.keyset.public_keys
assert response.json() == {
str(k): v.serialize().hex() for k, v in ledger.keyset.public_keys.items()
}
Expand All @@ -51,7 +54,7 @@ async def test_split(ledger: Ledger, wallet: Wallet):
pay_if_regtest(invoice.bolt11)
await wallet.mint(64, id=invoice.id)
assert wallet.balance == 64
secrets, rs, derivation_paths = await wallet.generate_secrets_from_to(2000, 2001)
secrets, rs, derivation_paths = await wallet.generate_secrets_from_to(200, 201)
outputs, rs = wallet._construct_outputs([32, 32], secrets, rs)
# outputs = wallet._construct_outputs([32, 32], ["a", "b"], ["c", "d"])
inputs_payload = [p.to_dict() for p in wallet.proofs]
Expand All @@ -69,15 +72,17 @@ async def test_split_deprecated_with_amount(ledger: Ledger, wallet: Wallet):
pay_if_regtest(invoice.bolt11)
await wallet.mint(64, id=invoice.id)
assert wallet.balance == 64
secrets, rs, derivation_paths = await wallet.generate_secrets_from_to(2002, 2003)
secrets, rs, derivation_paths = await wallet.generate_secrets_from_to(300, 301)
outputs, rs = wallet._construct_outputs([32, 32], secrets, rs)
# outputs = wallet._construct_outputs([32, 32], ["a", "b"], ["c", "d"])
inputs_payload = [p.to_dict() for p in wallet.proofs]
outputs_payload = [o.dict() for o in outputs]
# we supply an amount here, which should cause the very old deprecated split endpoint to be used
payload = {"proofs": inputs_payload, "outputs": outputs_payload, "amount": 32}
response = httpx.post(f"{BASE_URL}/split", json=payload, timeout=None)
assert response.status_code == 200, f"{response.url} {response.status_code}"
result = response.json()
# old deprecated output format
assert result["fst"]
assert result["snd"]

Expand Down

0 comments on commit 6254b21

Please sign in to comment.