Skip to content

Commit a7a4558

Browse files
authored
fix: cycles response for empty cycle info (#1914)
1 parent 44fcf75 commit a7a4558

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/datastore/pg-store-v2.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,11 +486,12 @@ export class PgStoreV2 extends BasePgStoreModule {
486486
OFFSET ${offset}
487487
LIMIT ${limit}
488488
`;
489+
const total = results.length > 0 ? results[0].total : 0;
489490
return {
490491
limit,
491492
offset,
492493
results: results,
493-
total: results[0].total,
494+
total,
494495
};
495496
});
496497
}

src/tests/pox-tests.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { ChainID } from '@stacks/common';
44
import { ApiServer, startApiServer } from '../api/init';
55
import { PgWriteStore } from '../datastore/pg-write-store';
66
import { importEventsFromTsv } from '../event-replay/event-replay';
7+
import { migrate } from '../test-utils/test-helpers';
78

89
describe('PoX tests', () => {
910
let db: PgWriteStore;
1011
let client: PgSqlClient;
1112
let api: ApiServer;
1213

1314
beforeEach(async () => {
15+
await migrate('up');
1416
db = await PgWriteStore.connect({
1517
usageName: 'tests',
1618
withNotifier: true,
@@ -23,6 +25,18 @@ describe('PoX tests', () => {
2325
afterEach(async () => {
2426
await api.terminate();
2527
await db?.close();
28+
await migrate('down');
29+
});
30+
31+
test('api with empty cycles', async () => {
32+
const cycles0 = await supertest(api.server).get(`/extended/v2/pox/cycles`);
33+
expect(cycles0.status).toBe(200);
34+
expect(JSON.parse(cycles0.text)).toStrictEqual({
35+
limit: 20,
36+
offset: 0,
37+
results: [],
38+
total: 0,
39+
});
2640
});
2741

2842
test('api', async () => {

0 commit comments

Comments
 (0)