`/price/:assetA/:assetB/history` turns a bad `limit` into a 500 and an unknown pair into an empty 200

Đang mở Phù hợp với người mới
#664 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@I-frenzy đang làm issue này rồi.

Từ ngày 20/11/2026.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
80/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
openapi, postgresql, typescript
Lĩnh vực
api, databases, testing

Hướng nghiên cứu

Đọc trình xử lý lịch sử trong src/api/rest.ts (dòng 305–376) trước, sau đó kiểm tra findPair và parseLimit trong src/api/rest.ts và src/pagination.ts. Trước tiên, hãy xem các bài kiểm thử route trong tests/rest-route.test.ts và src/__tests__/priceHistoryNetwork.test.ts. Cập nhật openapi.yaml và tạo lại các tệp được sinh; công việc hoàn tất khi giới hạn không hợp lệ trả về 400, các cặp không được theo dõi trả về 404, bí danh hợp lệ được phân giải và cấu trúc phản hồi hiện có được giữ nguyên.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area:api difficulty:easy help wanted points:100 Stellar Wave
Background

In src/api/rest.ts, the history handler parses limit like this (line 316):

const limit = Math.min(parseInt(req.query.limit ?? String(HISTORY_DEFAULT_LIMIT), 10), HISTORY_MAX_LIMIT)

?limit=abc gives NaN, and ?limit=-5 gives -5. Both are passed to Postgres as the LIMIT and the request fails with a 500. Every other paged route uses parseLimit from src/pagination.ts, which answers a non-number with a 400 and clamps the rest.

The same handler builds the pair key from the raw path (line 317, makePairKey(assetA, assetB)), while /price/:assetA/:assetB in the same file resolves the pair with findPair (line 222) and answers 404 unwatched_pair for a pair it does not watch. So /price/xlm/usdc/history, /price/native/USDC/history or a pair that does not exist all return 200 with an empty buckets list. An integrator cannot tell "no data yet" from "you spelled it wrong".

The window check also runs after the pair key and decimal work; it should be the first thing rejected.

What to build
  • Parse limit with parseLimit; a non-integer is a 400 with code invalid_parameter.
  • Resolve the pair with findPair, as the sibling routes do, and answer 404 unwatched_pair when it is not watched on that network. Query with the resolved pair.pairKey.
  • Keep the response shape and the gap declaration unchanged for a valid request.
  • Update openapi.yaml for the 400 and 404 and regenerate the generated files.
Where to look
  • src/api/rest.ts lines 305 to 376 and findPair at line 50
  • src/pagination.ts parseLimit
  • tests/rest-route.test.ts, src/__tests__/priceHistoryNetwork.test.ts
Done when
  • limit=abc returns 400, and limit=-5 and limit=999999 are clamped; none reaches Postgres as an invalid value
  • An unwatched pair returns 404 unwatched_pair; a lower-case or native spelling of a watched pair returns its data
  • A valid request returns the same body as before
  • Generated files are regenerated and npm test passes

Drips Wave · Complexity: Easy · 100 points


Repo: Divinity-Labs/Lens. Install with npm ci, typecheck with npx tsc --noEmit, test with npm test. Tests are vitest. Do not run jest: it reports zero tests and proves nothing.

You cannot reach the production service. Prove your change with local tests and fixtures. Mock the database (pgPool, prisma) the way the existing tests in src/__tests__/ and tests/ do.

Generated files are checked byte for byte by CI. If you add or change a route, edit openapi.yaml by hand and then regenerate the generated files and commit them: npm run openapi:gen (writes openapi.json and the README sections), npm run client:gen (the TypeScript client schema) and, if you touched the GraphQL schema, npm run graphql:schema:gen (writes schema.graphql). The full list is in the scripts section of package.json; also read CONTRIBUTING.md. If a check fails and the diff looks empty, it is line endings: commit with LF.

Prices are high-precision decimals. Do not add a new place where a price or amount goes through parseFloat, Number() or ::float before it reaches the caller.

MCP tools must return exactly the fields the matching REST route returns (tests/mcp-lens.test.ts asserts equality), and the MCP tool modules must not import the database driver directly. Reads are injected.

Do not remove or loosen an existing API-key scope, CORS rule or rate limit, and do not replace src/app.ts wholesale. Past pull requests did both by accident.

Do not weaken a test to make it pass. No real user data, wallet addresses of real users, keys, tokens or connection strings in code, tests or fixtures. Never shorten a Stellar address or contract id; copy it in full from the file that defines it.



Required: Before submitting, join the contributor Telegram so your work can be tracked and counted toward the Stellar Wave: https://t.me/+fxHXq8f1SwlkZDBk

Ngôn ngữ chính
TypeScript
Star
4
Fork
71
Merge trung bình
2 ngày 6 giờ
Pull request đã merge (30 ngày)
24

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Divinity-Labs/Lens

Tất cả issue của Divinity-Labs/Lens

Issue tương tự

Thêm issue về TypeScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.