Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/commands/SpotCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
63 changes: 63 additions & 0 deletions src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
});
});