diff --git a/src/commands/SpotCommand.ts b/src/commands/SpotCommand.ts index ab28856..15ae65c 100644 --- a/src/commands/SpotCommand.ts +++ b/src/commands/SpotCommand.ts @@ -610,8 +610,8 @@ export class SpotCommand { } const limit = Number(opts.limit); - if (isNaN(limit) || limit <= 0) { - throw new Error("--limit must be a positive number."); + if (isNaN(limit) || limit <= 0 || limit > 15) { + throw new Error("--limit must be between 1 and 15."); } const address = diff --git a/src/e2e.test.ts b/src/e2e.test.ts index fc3f878..1fef834 100644 --- a/src/e2e.test.ts +++ b/src/e2e.test.ts @@ -106,3 +106,66 @@ describe("keys add (dist/index.js)", () => { expect(second.stdout + second.stderr).toContain("already exists"); }); }); + +describe("spot history", () => { + test("rejects --limit greater than 15", () => { + const result = runCli( + "spot", + "history", + "--limit", + "16", + "--address", + TEST_SEED_ADDRESS + ); + expect(result.status).not.toBe(0); + expect(result.stdout + result.stderr).toContain( + "--limit must be between 1 and 15" + ); + }); + + test("rejects --limit of 0", () => { + const result = runCli( + "spot", + "history", + "--limit", + "0", + "--address", + TEST_SEED_ADDRESS + ); + expect(result.status).not.toBe(0); + expect(result.stdout + result.stderr).toContain( + "--limit must be between 1 and 15" + ); + }); + + test("rejects --limit of negative number", () => { + const result = runCli( + "spot", + "history", + "--limit", + "-5", + "--address", + TEST_SEED_ADDRESS + ); + expect(result.status).not.toBe(0); + expect(result.stdout + result.stderr).toContain( + "--limit must be between 1 and 15" + ); + }); + + test("accepts valid --limit between 1 and 15", () => { + // This will fail on API call (no real address), but validation should pass + const result = runCli( + "spot", + "history", + "--limit", + "10", + "--address", + TEST_SEED_ADDRESS + ); + // Should fail due to API, not validation + expect(result.stdout + result.stderr).not.toContain( + "--limit must be between 1 and 15" + ); + }); +});