mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-11 11:47:50 +00:00
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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user