From 239e2e5d5d6460d04faaad66c7ab73c9198f211e Mon Sep 17 00:00:00 2001 From: 9qeklajc Date: Sat, 8 Aug 2026 00:47:35 +0200 Subject: [PATCH] test: mock store_cashu_transaction in credit_balance unit tests The three credit_balance unit tests mock the DB session but let credit_balance call the real store_cashu_transaction_with_retry, which opens its own session against the global engine. In CI that database has no cashu_transactions table; since storage failures now propagate (a60b04ae) instead of being silently swallowed, the tests failed with sqlite3.OperationalError. Patch the audit store like the existing propagation test already does. --- tests/unit/test_wallet.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_wallet.py b/tests/unit/test_wallet.py index aa79797a..c8cecc55 100644 --- a/tests/unit/test_wallet.py +++ b/tests/unit/test_wallet.py @@ -613,7 +613,8 @@ async def test_credit_balance() -> None: "routstr.wallet.recieve_token", return_value=(1000, "sat", "http://mint:3338"), ): - amount = await credit_balance(token_str, mock_key, mock_session) + with patch("routstr.wallet.store_cashu_transaction", AsyncMock()): + amount = await credit_balance(token_str, mock_key, mock_session) assert amount == 1000000 # converted to msat assert mock_key.balance == 6000000 # Should be updated after refresh # Verify atomic operations were used @@ -636,7 +637,8 @@ async def test_credit_balance_constrains_redemption_to_key_mint() -> None: receive = AsyncMock(return_value=(1000, "sat", key_mint)) with patch("routstr.wallet.recieve_token", receive): - await credit_balance("cashuAtoken", mock_key, mock_session) + with patch("routstr.wallet.store_cashu_transaction", AsyncMock()): + await credit_balance("cashuAtoken", mock_key, mock_session) receive.assert_awaited_once_with( "cashuAtoken", destination_mint=key_mint, destination_unit="sat" @@ -1503,7 +1505,8 @@ async def test_credit_balance_msat_unit_not_converted() -> None: "routstr.wallet.recieve_token", return_value=(1_000_000, "msat", "http://mint:3338"), ): - amount = await credit_balance("cashuAtest", mock_key, mock_session) + with patch("routstr.wallet.store_cashu_transaction", AsyncMock()): + amount = await credit_balance("cashuAtest", mock_key, mock_session) assert amount == 1_000_000 assert mock_session.commit.called