Skip to content

Commit

Permalink
fix event loop scope
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 1, 2024
1 parent c8a4b39 commit c78d039
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 51 deletions.
74 changes: 26 additions & 48 deletions cashu/mint/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ async def get_keyset(
derivation_path: str = "",
seed: str = "",
conn: Optional[Connection] = None,
) -> List[MintKeyset]:
...
) -> List[MintKeyset]: ...

@abstractmethod
async def get_proofs_used(
Expand All @@ -42,8 +41,7 @@ async def get_proofs_used(
Ys: List[str],
db: Database,
conn: Optional[Connection] = None,
) -> List[Proof]:
...
) -> List[Proof]: ...

@abstractmethod
async def invalidate_proof(
Expand All @@ -53,17 +51,15 @@ async def invalidate_proof(
proof: Proof,
quote_id: Optional[str] = None,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def get_all_melt_quotes_from_pending_proofs(
self,
*,
db: Database,
conn: Optional[Connection] = None,
) -> List[MeltQuote]:
...
) -> List[MeltQuote]: ...

@abstractmethod
async def get_pending_proofs_for_quote(
Expand All @@ -72,8 +68,7 @@ async def get_pending_proofs_for_quote(
quote_id: str,
db: Database,
conn: Optional[Connection] = None,
) -> List[Proof]:
...
) -> List[Proof]: ...

@abstractmethod
async def get_proofs_pending(
Expand All @@ -82,8 +77,7 @@ async def get_proofs_pending(
Ys: List[str],
db: Database,
conn: Optional[Connection] = None,
) -> List[Proof]:
...
) -> List[Proof]: ...

@abstractmethod
async def set_proof_pending(
Expand All @@ -93,8 +87,7 @@ async def set_proof_pending(
proof: Proof,
quote_id: Optional[str] = None,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def unset_proof_pending(
Expand All @@ -103,8 +96,7 @@ async def unset_proof_pending(
proof: Proof,
db: Database,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def store_keyset(
Expand All @@ -113,8 +105,7 @@ async def store_keyset(
db: Database,
keyset: MintKeyset,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def update_keyset(
Expand All @@ -123,16 +114,14 @@ async def update_keyset(
db: Database,
keyset: MintKeyset,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def get_balance(
self,
db: Database,
conn: Optional[Connection] = None,
) -> int:
...
) -> int: ...

@abstractmethod
async def store_promise(
Expand All @@ -146,8 +135,7 @@ async def store_promise(
e: str = "",
s: str = "",
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def get_promise(
Expand All @@ -156,8 +144,7 @@ async def get_promise(
db: Database,
b_: str,
conn: Optional[Connection] = None,
) -> Optional[BlindedSignature]:
...
) -> Optional[BlindedSignature]: ...

@abstractmethod
async def get_promises(
Expand All @@ -166,8 +153,7 @@ async def get_promises(
db: Database,
b_s: List[str],
conn: Optional[Connection] = None,
) -> List[BlindedSignature]:
...
) -> List[BlindedSignature]: ...

@abstractmethod
async def store_mint_quote(
Expand All @@ -176,8 +162,7 @@ async def store_mint_quote(
quote: MintQuote,
db: Database,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def get_mint_quote(
Expand All @@ -188,8 +173,7 @@ async def get_mint_quote(
request: Optional[str] = None,
db: Database,
conn: Optional[Connection] = None,
) -> Optional[MintQuote]:
...
) -> Optional[MintQuote]: ...

@abstractmethod
async def get_mint_quote_by_request(
Expand All @@ -198,8 +182,7 @@ async def get_mint_quote_by_request(
request: str,
db: Database,
conn: Optional[Connection] = None,
) -> Optional[MintQuote]:
...
) -> Optional[MintQuote]: ...

@abstractmethod
async def update_mint_quote(
Expand All @@ -208,8 +191,7 @@ async def update_mint_quote(
quote: MintQuote,
db: Database,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def store_melt_quote(
Expand All @@ -218,8 +200,7 @@ async def store_melt_quote(
quote: MeltQuote,
db: Database,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...

@abstractmethod
async def get_melt_quote(
Expand All @@ -230,8 +211,7 @@ async def get_melt_quote(
request: Optional[str] = None,
db: Database,
conn: Optional[Connection] = None,
) -> Optional[MeltQuote]:
...
) -> Optional[MeltQuote]: ...

@abstractmethod
async def get_melt_quote_by_request(
Expand All @@ -240,8 +220,7 @@ async def get_melt_quote_by_request(
request: str,
db: Database,
conn: Optional[Connection] = None,
) -> Optional[MeltQuote]:
...
) -> Optional[MeltQuote]: ...

@abstractmethod
async def update_melt_quote(
Expand All @@ -250,8 +229,7 @@ async def update_melt_quote(
quote: MeltQuote,
db: Database,
conn: Optional[Connection] = None,
) -> None:
...
) -> None: ...


class LedgerCrudSqlite(LedgerCrud):
Expand Down Expand Up @@ -359,7 +337,7 @@ async def get_all_melt_quotes_from_pending_proofs(
SELECT * from {db.table_with_schema('melt_quotes')} WHERE quote in (SELECT DISTINCT melt_quote FROM {db.table_with_schema('proofs_pending')})
"""
)
return [MeltQuote.from_row(r) for r in rows]
return [MeltQuote.from_row(r) for r in rows] # type: ignore

async def get_pending_proofs_for_quote(
self,
Expand Down Expand Up @@ -601,7 +579,7 @@ async def get_melt_quote(
""",
values,
)
return MeltQuote.from_row(row) if row else None
return MeltQuote.from_row(row) if row else None # type: ignore

async def get_melt_quote_by_request(
self,
Expand All @@ -617,7 +595,7 @@ async def get_melt_quote_by_request(
""",
{"request": request},
)
return MeltQuote.from_row(row) if row else None
return MeltQuote.from_row(row) if row else None # type: ignore

async def update_melt_quote(
self,
Expand Down Expand Up @@ -685,7 +663,7 @@ async def get_balance(
db: Database,
conn: Optional[Connection] = None,
) -> int:
row: List = await (conn or db).fetchone(
row = await (conn or db).fetchone(
f"""
SELECT * from {db.table_with_schema('balance')}
"""
Expand Down
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@
# from cashu.mint.startup import lightning_backend # noqa


@pytest.fixture(scope="session")
@pytest.fixture(scope="function")
def event_loop():
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
loop = asyncio.new_event_loop()
yield loop
loop.close()

Expand Down

0 comments on commit c78d039

Please sign in to comment.