Skip to content

test: await first melt in test_melt_quote_reuse_same_outputs#846

Draft
b-l-u-e wants to merge 1 commit intocashubtc:mainfrom
b-l-u-e:test/fix-unawaited-coroutine-melt-test
Draft

test: await first melt in test_melt_quote_reuse_same_outputs#846
b-l-u-e wants to merge 1 commit intocashubtc:mainfrom
b-l-u-e:test/fix-unawaited-coroutine-melt-test

Conversation

@b-l-u-e
Copy link
Copy Markdown
Contributor

@b-l-u-e b-l-u-e commented Dec 11, 2025

The test test_melt_quote_reuse_same_outputs had an unawaited coroutine on line 245, causing:

  • A RuntimeWarning: coroutine 'Ledger.melt' was never awaited
  • The first melt never executing, so no outputs were stored
  • The test passing for the wrong reason - it wasn't actually testing output reuse protection

Solution

Add await to the first melt call:

# Before (line 245):
ledger.melt(proofs=proofs1, quote=melt_quote1.quote, outputs=change_outputs)

# After:
await ledger.melt(proofs=proofs1, quote=melt_quote1.quote, outputs=change_outputs)

The test verifies that reusing the same outputs in two melt requests fails:

  1. Line 893 (ledger.py): _verify_outputs() checks if outputs were already signed via _check_outputs_pending_or_issued_before()
  2. Line 158 (verification.py): _check_outputs_pending_or_issued_before() queries the promises table by b_ (blinded message)
  3. Line 140 (verification.py): If any outputs are found, it raises OutputsAlreadySignedError()
  4. Line 933 (ledger.py): If outputs pass verification, they are stored in the promises table via _store_blinded_messages() with melt_id=melt_quote.quote

Expected behavior:

  • First melt: Uses change_outputs - outputs stored in DB
  • Second melt: Reuses the same change_outputs - should fail with OutputsAlreadySignedError

Without awaiting the first melt:

  • The first melt never runs
  • Outputs are never stored
  • The second melt may not fail as expected
  • The test may pass for the wrong reason

the test should validate that the system prevents reusing the same outputs in multiple melt operations, but without await, it doesn't actually test this protection.

Fix unawaited coroutine that prevented the test from actually validating
output reuse protection. Without await, the first melt never executed,
causing the test to pass for the wrong reason.
@callebtc
Copy link
Copy Markdown
Collaborator

I wonder how it is possible that the test succeeded before

@ye0man ye0man added this to nutshell Jan 21, 2026
@github-project-automation github-project-automation bot moved this to Backlog in nutshell Jan 21, 2026
@b-l-u-e
Copy link
Copy Markdown
Contributor Author

b-l-u-e commented Feb 22, 2026

I wonder how it is possible that the test succeeded before

Sorry for delay caught up on other stuff
Let me rework on it again n see if reproduces the same issue

@b-l-u-e
Copy link
Copy Markdown
Contributor Author

b-l-u-e commented Feb 23, 2026

I wonder how it is possible that the test succeeded before

so i reproduced without await: the test still reports 1 passed, but pytest emits RuntimeWarning: coroutine 'Ledger.melt' was never awaited on the first melt call.


poetry run pytest tests/mint/test_mint_melt.py::test_melt_quote_reuse_same_outputs -q
.                                                                                                                         [100%]
======================================================= warnings summary ========================================================
../../../.cache/pypoetry/virtualenvs/cashu-PSOIcMEs-py3.10/lib/python3.10/site-packages/environs/__init__.py:58
 /home/user/.cache/pypoetry/virtualenvs/cashu-PSOIcMEs-py3.10/lib/python3.10/site-packages/environs/__init__.py:58: DeprecationWarning: The '__version_info__' attribute is deprecated and will be removed in in a future version. Use feature detection or 'packaging.Version(importlib.metadata.version("marshmallow")).release' instead.
   _SUPPORTS_LOAD_DEFAULT = ma.__version_info__ >= (3, 13)

tests/mint/test_mint_melt.py::test_melt_quote_reuse_same_outputs
 /home/user/projects/cashu-projects/nutshell/tests/mint/test_mint_melt.py:249: RuntimeWarning: coroutine 'Ledger.melt' was never awaited
   ledger.melt(proofs=proofs1, quote=melt_quote1.quote, outputs=change_outputs)
 Enable tracemalloc to get traceback where the object was allocated.
 See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
1 passed, 2 warnings in 6.50s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

3 participants