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.
This commit is contained in:
9qeklajc
2026-08-08 00:47:35 +02:00
parent a60b04aea0
commit 239e2e5d5d
+6 -3
View File
@@ -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