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
11 changes: 11 additions & 0 deletions tests/data-api.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,17 @@ test("GET /api/v1/extrinsics uses a composite cursor seek instead of OFFSET", as
expect(text).not.toContain("OFFSET");
});

test("GET /api/v1/extrinsics clamps page size and offset before querying Postgres", async () => {
mockRows.current = [EXTRINSIC_ROW];
await req("/api/v1/extrinsics?limit=999999&offset=999999999");

const queryValues = sqlCalls.flatMap((call) => call.values);
expect(queryValues).toContain(BLOCK_PAGINATION.maxLimit);
expect(queryValues).toContain(MAX_OFFSET);
expect(queryValues).not.toContain(999999);
expect(queryValues).not.toContain(999999999);
});

test("GET /api/v1/extrinsics/:ref resolves a hash ref with embedded account_events", async () => {
const eventRow = {
block_number: "8586300",
Expand Down
2 changes: 1 addition & 1 deletion workers/data-api.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export default {
// cover the same access patterns D1's INDEXED BY hints targeted) --
// Postgres has no INDEXED BY equivalent.
if (url.pathname === "/api/v1/extrinsics") {
const limit = clampLimit(url.searchParams.get("limit"));
const limit = clampBlockLimit(url.searchParams.get("limit"));
const offset = clampOffset(url.searchParams.get("offset"));
const cursor = decodeCursor(url.searchParams.get("cursor"), 2);
const block = nonNegativeIntegerParam(url.searchParams, "block");
Expand Down
Loading