Skip to content

Commit 3460c98

Browse files
authored
fix: enforce positive token list limits (#11)
* fix: enforce positive token list limits * fix: add top alias for token commands
1 parent 5532c06 commit 3460c98

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/pumpfun_cli/commands/tokens.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,29 @@ def _display_tokens(ctx: typer.Context, tokens: list[dict]):
6060

6161

6262
@app.command("trending")
63-
def trending(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
63+
def trending(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
6464
"""Top runners + recommended tokens."""
6565
tokens = asyncio.run(get_trending_tokens(limit=limit))
6666
_display_tokens(ctx, tokens)
6767

6868

6969
@app.command("new")
70-
def new(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
70+
def new(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
7171
"""Recently launched tokens."""
7272
tokens = asyncio.run(get_new_tokens(limit=limit))
7373
_display_tokens(ctx, tokens)
7474

7575

7676
@app.command("graduating")
77-
def graduating(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
77+
def graduating(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
7878
"""Tokens near bonding curve completion."""
7979
tokens = asyncio.run(get_graduating_tokens(limit=limit))
8080
_display_tokens(ctx, tokens)
8181

8282

8383
@app.command("recommended")
84-
def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n")):
84+
@app.command("top", hidden=True)
85+
def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n", min=1)):
8586
"""Recommended tokens by pump.fun."""
8687
tokens = asyncio.run(get_recommended_tokens(limit=limit))
8788
_display_tokens(ctx, tokens)
@@ -91,7 +92,7 @@ def recommended(ctx: typer.Context, limit: int = typer.Option(20, "--limit", "-n
9192
def search(
9293
ctx: typer.Context,
9394
query: str = typer.Argument(...),
94-
limit: int = typer.Option(20, "--limit", "-n"),
95+
limit: int = typer.Option(20, "--limit", "-n", min=1),
9596
):
9697
"""Search tokens by keyword."""
9798
tokens = asyncio.run(search_tokens(query, limit=limit))

tests/test_commands/test_smoke.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import re
55

6+
import pytest
67
from typer.testing import CliRunner
78

89
from pumpfun_cli.cli import app
@@ -170,3 +171,25 @@ def test_tokens_no_subcommand_shows_help():
170171
"""Bare 'tokens' with no subcommand exits 0 and shows help."""
171172
result = runner.invoke(app, ["tokens"])
172173
assert result.exit_code == 0
174+
175+
176+
@pytest.mark.parametrize("limit", ["0", "-1"])
177+
@pytest.mark.parametrize(
178+
("subcommand", "extra_args"),
179+
[
180+
("trending", []),
181+
("new", []),
182+
("graduating", []),
183+
("top", []),
184+
("recommended", []),
185+
("search", ["dog"]),
186+
],
187+
)
188+
def test_tokens_limit_must_be_at_least_one(limit, subcommand, extra_args):
189+
"""Token listing commands reject zero and negative limits before execution."""
190+
result = runner.invoke(app, ["tokens", subcommand, *extra_args, "--limit", limit])
191+
192+
assert result.exit_code == 2
193+
output = _strip_ansi(result.output)
194+
assert "Invalid value for" in output
195+
assert "--limit" in output

0 commit comments

Comments
 (0)