feat: validate slippage range in buy and sell commands#7
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds slippage bounds validation (0–100) to buy and sell commands, invoked before RPC/wallet initialization, and adds tests for out-of-range and boundary slippage cases including JSON and dry-run scenarios. Changes
Sequence Diagram(s)(omitted — change is a small validation addition and tests, not a multi-component flow that requires visualization) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pumpfun_cli/commands/trade.py`:
- Around line 79-80: Extract the duplicated slippage check into a shared helper
function (e.g., validate_slippage) and call it from both buy() and sell();
specifically, move the logic that currently checks "if slippage < 0 or slippage
> 100: error(...)" into validate_slippage(slippage) which performs the same
validation and error(...) call, then replace the two in-line guards in buy() and
sell() with a single call to validate_slippage(slippage); ensure the helper is
placed in the same module (or imported) so both functions reference the same
symbol and keep the exact error message/hint behavior.
In `@tests/test_commands/test_trade_cmd.py`:
- Around line 482-544: Add two mirror tests for sell slippage boundaries like
test_buy_slippage_zero and test_buy_slippage_100: create test_sell_slippage_zero
and test_sell_slippage_100 that set XDG_CONFIG_HOME and PUMPFUN_PASSWORD,
encrypt a Keypair into config_dir/wallet.enc (reuse Keypair and
encrypt_keypair), patch pumpfun_cli.commands.trade.sell_token with AsyncMock
returning a buy-like result (action "sell", mint _FAKE_MINT,
sol_spent/tokens_received/signature/explorer), invoke the CLI with
runner.invoke(app, ["--json","--rpc","http://rpc","sell","--slippage","0",
_FAKE_MINT, "0.01"]) and likewise with "--slippage","100", and assert
result.exit_code == 0 and that "Slippage must be between" is not in
result.output; ensure RPC/network is mocked via the AsyncMock patch of
sell_token.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 134cd9ff-5150-4dfd-846e-e6e3ef2894b3
📒 Files selected for processing (2)
src/pumpfun_cli/commands/trade.pytests/test_commands/test_trade_cmd.py
ebd66a3 to
8103367
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
tests/test_commands/test_trade_cmd.py (1)
482-544: 🛠️ Refactor suggestion | 🟠 MajorSell boundary tests (slippage=0, slippage=100) still missing.
Buy boundaries are covered, but sell boundaries are not. Add
test_sell_slippage_zeroandtest_sell_slippage_100for parity — same pattern as the buy tests, but invoking the sell command.,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_commands/test_trade_cmd.py` around lines 482 - 544, Add two mirror tests named test_sell_slippage_zero and test_sell_slippage_100 following the exact pattern of test_buy_slippage_zero and test_buy_slippage_100: set XDG_CONFIG_HOME and PUMPFUN_PASSWORD, create Keypair and encrypt_keypair into config_dir / "wallet.enc", patch pumpfun_cli.commands.trade.sell_token with AsyncMock to return the same fake result dict, invoke the CLI with ["--json", "--rpc", "http://rpc", "sell", "--slippage", "0", _FAKE_MINT, "0.01"] (and "--slippage", "100" for the other), and assert result.exit_code == 0 and that "Slippage must be between" not in result.output to match the buy boundary tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/pumpfun_cli/commands/trade.py`:
- Around line 46-50: Add an explicit return type annotation to the
_validate_slippage function to satisfy linting (Ruff) and maintain consistency:
change the signature of _validate_slippage to include "-> None" (i.e., def
_validate_slippage(slippage: int) -> None:), leaving the body and error() call
unchanged so behavior remains the same.
---
Duplicate comments:
In `@tests/test_commands/test_trade_cmd.py`:
- Around line 482-544: Add two mirror tests named test_sell_slippage_zero and
test_sell_slippage_100 following the exact pattern of test_buy_slippage_zero and
test_buy_slippage_100: set XDG_CONFIG_HOME and PUMPFUN_PASSWORD, create Keypair
and encrypt_keypair into config_dir / "wallet.enc", patch
pumpfun_cli.commands.trade.sell_token with AsyncMock to return the same fake
result dict, invoke the CLI with ["--json", "--rpc", "http://rpc", "sell",
"--slippage", "0", _FAKE_MINT, "0.01"] (and "--slippage", "100" for the other),
and assert result.exit_code == 0 and that "Slippage must be between" not in
result.output to match the buy boundary tests.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 81d01da2-692f-4777-8f5e-4aede9084215
📒 Files selected for processing (2)
src/pumpfun_cli/commands/trade.pytests/test_commands/test_trade_cmd.py
8103367 to
e846095
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/pumpfun_cli/commands/trade.py (1)
46-50:⚠️ Potential issue | 🟡 MinorAdd explicit
-> Noneon_validate_slippage.
_validate_slippagestill triggers ANN202; add the return type to keep lint clean and typing consistent.♻️ Suggested patch
-def _validate_slippage(slippage: int): +def _validate_slippage(slippage: int) -> None: """Validate slippage is between 0 and 100, or exit with error.""" if slippage < 0 or slippage > 100: error("Slippage must be between 0 and 100.", hint=f"Got: {slippage}")#!/bin/bash # Verify no unannotated _validate_slippage signature remains. rg -nP '^def _validate_slippage\(slippage: int\)(?!\s*->)' src/pumpfun_cli/commands/trade.py🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/pumpfun_cli/commands/trade.py` around lines 46 - 50, The function _validate_slippage currently lacks an explicit return type and triggers ANN202; update its signature to include an explicit -> None return annotation (i.e., def _validate_slippage(slippage: int) -> None:) and keep the body unchanged so the linter recognizes it as intentionally returning nothing; ensure the change is applied to the _validate_slippage definition in trade.py so the ripgrep check provided in the review will pass.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/pumpfun_cli/commands/trade.py`:
- Around line 46-50: The function _validate_slippage currently lacks an explicit
return type and triggers ANN202; update its signature to include an explicit ->
None return annotation (i.e., def _validate_slippage(slippage: int) -> None:)
and keep the body unchanged so the linter recognizes it as intentionally
returning nothing; ensure the change is applied to the _validate_slippage
definition in trade.py so the ripgrep check provided in the review will pass.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 04d555c9-f17f-4b7c-bb42-09b25cca9c34
📒 Files selected for processing (2)
src/pumpfun_cli/commands/trade.pytests/test_commands/test_trade_cmd.py
e846095 to
d5e6147
Compare
|
Added |
|
@UnknownHacker9991 please run:
Then commit and push. |
d5e6147 to
bcc8cd0
Compare
|
Done — formatted with ruff and force-pushed. |
bcc8cd0 to
e32db32
Compare
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
e32db32 to
540c1cf
Compare
Closes #1
Added slippage validation in both
buy()andsell()insrc/pumpfun_cli/commands/trade.py, right after_validate_mint(). Values outside 0-100 now exit with a clear error message.Changes:
src/pumpfun_cli/commands/trade.py— validation inbuy()andsell()tests/test_commands/test_trade_cmd.py— 6 new tests covering negative, above-100, and boundary values (0, 100)All 27 tests pass:
uv run pytest tests/test_commands/test_trade_cmd.py -vSummary by CodeRabbit
Bug Fixes
Tests