Skip to content
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
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ PG_PORT=5490
PG_USER=postgres
PG_PASSWORD=postgres
PG_DATABASE=stacks_blockchain_api
PG_SCHEMA=public
PG_SCHEMA=stacks_blockchain_api
PG_SSL=false
# Idle connection timeout in seconds, defaults to 30
# PG_IDLE_TIMEOUT=30
Expand Down
6 changes: 5 additions & 1 deletion tests/event-replay/import-export.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { exportEventsAsTsv, importEventsFromTsv } from '../../src/event-replay/e
import { startEventServer } from '../../src/event-stream/event-server';
import { httpPostRequest } from '../../src/helpers';
import { useWithCleanup } from '../api/test-helpers';
import { migrate } from '../utils/test-helpers';
import { createSchema, migrate } from '../utils/test-helpers';
import { PgSqlClient, dangerousDropAllTables, databaseHasData } from '@hirosystems/api-toolkit';
import { getConnectionArgs } from '../../src/datastore/connection';

Expand All @@ -27,7 +27,9 @@ describe('import/export tests', () => {
});

test('event import and export cycle - remote', async () => {
const args = getConnectionArgs();
// Import from mocknet TSV
await createSchema(args);
await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true);
const chainTip = await db.getChainTip(db.sql);
expect(chainTip.block_height).toBe(28);
Expand Down Expand Up @@ -60,7 +62,9 @@ describe('import/export tests', () => {
});

test('event import and export cycle - local', async () => {
const args = getConnectionArgs();
// Import from mocknet TSV
await createSchema(args);
await importEventsFromTsv('tests/event-replay/tsv/mocknet.tsv', 'archival', true, true);
const chainTip = await db.getChainTip(db.sql);
expect(chainTip.block_height).toBe(28);
Expand Down
14 changes: 12 additions & 2 deletions tests/utils/test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,25 @@ import { CoreRpcPoxInfo, StacksCoreRpcClient } from '../../src/core-rpc/client';
import { DbBlock, DbTx, DbTxStatus } from '../../src/datastore/common';
import { PgWriteStore } from '../../src/datastore/pg-write-store';
import { BitcoinAddressFormat, ECPair, getBitcoinAddressFromKey } from '../../src/ec-helpers';
import { coerceToBuffer, connectPostgres, runMigrations, timeout } from '@hirosystems/api-toolkit';
import {
coerceToBuffer,
connectPostgres,
PgConnectionArgs,
runMigrations,
timeout,
} from '@hirosystems/api-toolkit';
import { MIGRATIONS_DIR } from '../../src/datastore/pg-store';
import { getConnectionArgs } from '../../src/datastore/connection';
import { AddressStxBalance } from '../../src/api/schemas/entities/addresses';
import { ServerStatusResponse } from '../../src/api/schemas/responses/responses';

export async function migrate(direction: 'up' | 'down') {
const connArgs = getConnectionArgs();
await createSchema(connArgs);
await runMigrations(MIGRATIONS_DIR, direction, connArgs);
}

export async function createSchema(connArgs: PgConnectionArgs) {
if (typeof connArgs !== 'string' && connArgs.schema) {
const sql = await connectPostgres({
usageName: 'tests-migrations-setup',
Expand All @@ -61,7 +72,6 @@ export async function migrate(direction: 'up' | 'down') {
await sql`CREATE SCHEMA IF NOT EXISTS ${sql(connArgs.schema)}`;
await sql.end();
}
await runMigrations(MIGRATIONS_DIR, direction, connArgs);
}

export interface TestEnvContext {
Expand Down