Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mint API: Check ?amount is within a sensible range #226

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cashu/mint/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ async def request_mint(amount: int = 0) -> Union[GetMintResponse, CashuError]:
Call `POST /mint` after paying the invoice.
"""
logger.trace(f"> GET /mint: amount={amount}")
if amount > 21_000_000 * 100_000_000 or amount <= 0:
return CashuError(code=0, error="Amount must be a valid amount of sats.")
if settings.mint_peg_out_only:
return CashuError(code=0, error="Mint does not allow minting new tokens.")
try:
Expand Down
12 changes: 12 additions & 0 deletions tests/test_mint_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,15 @@ async def test_api_keyset_keys(ledger):
assert response.json() == {
str(k): v.serialize().hex() for k, v in ledger.keyset.public_keys.items()
}


@pytest.mark.asyncio
async def test_api_mint_validation(ledger):
response = requests.get(f"{BASE_URL}/mint?amount=-21")
assert "error" in response.json()
response = requests.get(f"{BASE_URL}/mint?amount=0")
assert "error" in response.json()
response = requests.get(f"{BASE_URL}/mint?amount=2100000000000001")
assert "error" in response.json()
response = requests.get(f"{BASE_URL}/mint?amount=1")
assert "error" not in response.json()
Loading