From c78d0390257b71bca4dd64479b615538eb4c863c Mon Sep 17 00:00:00 2001 From: callebtc <93376500+callebtc@users.noreply.github.com> Date: Fri, 1 Nov 2024 13:48:16 +0100 Subject: [PATCH] fix event loop scope --- cashu/mint/crud.py | 74 ++++++++++++++++------------------------------ tests/conftest.py | 5 ++-- 2 files changed, 28 insertions(+), 51 deletions(-) diff --git a/cashu/mint/crud.py b/cashu/mint/crud.py index 1ddb8aa6..0fc53f8c 100644 --- a/cashu/mint/crud.py +++ b/cashu/mint/crud.py @@ -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( @@ -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( @@ -53,8 +51,7 @@ 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( @@ -62,8 +59,7 @@ async def get_all_melt_quotes_from_pending_proofs( *, db: Database, conn: Optional[Connection] = None, - ) -> List[MeltQuote]: - ... + ) -> List[MeltQuote]: ... @abstractmethod async def get_pending_proofs_for_quote( @@ -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( @@ -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( @@ -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( @@ -103,8 +96,7 @@ async def unset_proof_pending( proof: Proof, db: Database, conn: Optional[Connection] = None, - ) -> None: - ... + ) -> None: ... @abstractmethod async def store_keyset( @@ -113,8 +105,7 @@ async def store_keyset( db: Database, keyset: MintKeyset, conn: Optional[Connection] = None, - ) -> None: - ... + ) -> None: ... @abstractmethod async def update_keyset( @@ -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( @@ -146,8 +135,7 @@ async def store_promise( e: str = "", s: str = "", conn: Optional[Connection] = None, - ) -> None: - ... + ) -> None: ... @abstractmethod async def get_promise( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -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( @@ -250,8 +229,7 @@ async def update_melt_quote( quote: MeltQuote, db: Database, conn: Optional[Connection] = None, - ) -> None: - ... + ) -> None: ... class LedgerCrudSqlite(LedgerCrud): @@ -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, @@ -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, @@ -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, @@ -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')} """ diff --git a/tests/conftest.py b/tests/conftest.py index 4ccebc61..5ab85275 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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()