Skip to content

Commit

Permalink
fix: bug with total being 0 on offset > total
Browse files Browse the repository at this point in the history
  • Loading branch information
brady.ouren committed Nov 27, 2024
1 parent b17895b commit 16982f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/datastore/pg-store-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ export class PgStoreV2 extends BasePgStoreModule {
LIMIT ${limit}
OFFSET ${offset}
`;
const total = resultQuery.length > 0 ? resultQuery[0].count : 0;
const total = resultQuery[0].count;
const parsed = resultQuery.map(r => parseAccountTransferSummaryTxQueryResult(r));
return {
total,
Expand Down Expand Up @@ -958,8 +958,8 @@ export class PgStoreV2 extends BasePgStoreModule {
COUNT(*) OVER()::int AS total
FROM pox_sets ps
INNER JOIN combined_stackers cs ON ps.signing_key = cs.signer_key
WHERE ps.canonical = TRUE
AND ps.cycle_number = ${cycleNumber}
WHERE ps.canonical = TRUE
AND ps.cycle_number = ${cycleNumber}
AND ps.signing_key = ${signerKey}
ORDER BY locked DESC
LIMIT ${limit}
Expand Down
7 changes: 7 additions & 0 deletions tests/api/address.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,13 @@ describe('address tests', () => {
expect(v2Fetch1offset.type).toBe('application/json');
const v2Fetch1offsetJson = JSON.parse(v2Fetch1offset.text);
expect(v2Fetch1offsetJson.total).toBe(7);
const v2Fetch7offset = await supertest(api.server).get(
`/extended/v2/addresses/${testAddr2}/transactions?offset=7`
);
expect(v2Fetch7offset.status).toBe(200);
expect(v2Fetch7offset.type).toBe('application/json');
const v2Fetch7offsetJson = JSON.parse(v2Fetch7offset.text);
expect(v2Fetch7offsetJson.total).toBe(7);

const v2Fetch2 = await supertest(api.server).get(
`/extended/v2/addresses/${testAddr2}/transactions/${v2Fetch1Json.results[0].tx.tx_id}/events?limit=3`
Expand Down

0 comments on commit 16982f3

Please sign in to comment.