Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: cycles response for empty cycle info #1914

Merged
merged 1 commit into from
Mar 28, 2024
Merged
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
3 changes: 2 additions & 1 deletion src/datastore/pg-store-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,11 +486,12 @@ export class PgStoreV2 extends BasePgStoreModule {
OFFSET ${offset}
LIMIT ${limit}
`;
const total = results.length > 0 ? results[0].total : 0;
return {
limit,
offset,
results: results,
total: results[0].total,
total,
};
});
}
Expand Down
14 changes: 14 additions & 0 deletions src/tests/pox-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import { ChainID } from '@stacks/common';
import { ApiServer, startApiServer } from '../api/init';
import { PgWriteStore } from '../datastore/pg-write-store';
import { importEventsFromTsv } from '../event-replay/event-replay';
import { migrate } from '../test-utils/test-helpers';

describe('PoX tests', () => {
let db: PgWriteStore;
let client: PgSqlClient;
let api: ApiServer;

beforeEach(async () => {
await migrate('up');
db = await PgWriteStore.connect({
usageName: 'tests',
withNotifier: true,
Expand All @@ -23,6 +25,18 @@ describe('PoX tests', () => {
afterEach(async () => {
await api.terminate();
await db?.close();
await migrate('down');
});

test('api with empty cycles', async () => {
const cycles0 = await supertest(api.server).get(`/extended/v2/pox/cycles`);
expect(cycles0.status).toBe(200);
expect(JSON.parse(cycles0.text)).toStrictEqual({
limit: 20,
offset: 0,
results: [],
total: 0,
});
});

test('api', async () => {
Expand Down
Loading