diff --git a/packages/ditto/controllers/api/cashu.test.ts b/packages/ditto/controllers/api/cashu.test.ts index 773e9800..ee73661b 100644 --- a/packages/ditto/controllers/api/cashu.test.ts +++ b/packages/ditto/controllers/api/cashu.test.ts @@ -1,12 +1,13 @@ import { confMw } from '@ditto/api/middleware'; import { Env as HonoEnv, Hono } from '@hono/hono'; import { NostrSigner, NSecSigner, NStore } from '@nostrify/nostrify'; +import { genEvent } from '@nostrify/nostrify/test'; import { generateSecretKey, getPublicKey } from 'nostr-tools'; import { bytesToString, stringToBytes } from '@scure/base'; import { stub } from '@std/testing/mock'; import { assertEquals, assertExists, assertObjectMatch } from '@std/assert'; -import { createTestDB, genEvent } from '@/test.ts'; +import { createTestDB } from '@/test.ts'; import cashuApp from '@/controllers/api/cashu.ts'; import { walletSchema } from '@/schema.ts'; diff --git a/packages/ditto/storages/EventsDB.test.ts b/packages/ditto/storages/EventsDB.test.ts index d0947075..03f31d35 100644 --- a/packages/ditto/storages/EventsDB.test.ts +++ b/packages/ditto/storages/EventsDB.test.ts @@ -1,8 +1,9 @@ import { assertEquals, assertRejects } from '@std/assert'; +import { genEvent } from '@nostrify/nostrify/test'; import { generateSecretKey } from 'nostr-tools'; import { RelayError } from '@/RelayError.ts'; -import { eventFixture, genEvent } from '@/test.ts'; +import { eventFixture } from '@/test.ts'; import { Conf } from '@/config.ts'; import { EventsDB } from '@/storages/EventsDB.ts'; import { createTestDB } from '@/test.ts'; diff --git a/packages/ditto/storages/hydrate.bench.ts b/packages/ditto/storages/hydrate.bench.ts index eeacec50..026b1f81 100644 --- a/packages/ditto/storages/hydrate.bench.ts +++ b/packages/ditto/storages/hydrate.bench.ts @@ -1,5 +1,6 @@ +import { jsonlEvents } from '@nostrify/nostrify/test'; + import { assembleEvents } from '@/storages/hydrate.ts'; -import { jsonlEvents } from '@/test.ts'; const testEvents = await jsonlEvents('fixtures/hydrated.jsonl'); const testStats = JSON.parse(await Deno.readTextFile('fixtures/stats.json')); diff --git a/packages/ditto/test.ts b/packages/ditto/test.ts index 47052b8d..dcf428a6 100644 --- a/packages/ditto/test.ts +++ b/packages/ditto/test.ts @@ -1,10 +1,8 @@ import { DittoDB } from '@ditto/db'; import { NostrEvent } from '@nostrify/nostrify'; -import { finalizeEvent, generateSecretKey } from 'nostr-tools'; import { Conf } from '@/config.ts'; import { EventsDB } from '@/storages/EventsDB.ts'; -import { purifyEvent } from '@/utils/purify.ts'; import { sql } from 'kysely'; /** Import an event fixture by name in tests. */ @@ -13,25 +11,6 @@ export async function eventFixture(name: string): Promise { return structuredClone(result.default); } -/** Import a JSONL fixture by name in tests. */ -export async function jsonlEvents(path: string): Promise { - const data = await Deno.readTextFile(path); - return data.split('\n').map((line) => JSON.parse(line)); -} - -/** Generate an event for use in tests. */ -export function genEvent(t: Partial = {}, sk: Uint8Array = generateSecretKey()): NostrEvent { - const event = finalizeEvent({ - kind: 255, - created_at: 0, - content: '', - tags: [], - ...t, - }, sk); - - return purifyEvent(event); -} - /** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */ export async function createTestDB(opts?: { pure?: boolean }) { const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 }); diff --git a/packages/ditto/trends.test.ts b/packages/ditto/trends.test.ts index 79eaf8e0..a99b4eb4 100644 --- a/packages/ditto/trends.test.ts +++ b/packages/ditto/trends.test.ts @@ -1,8 +1,9 @@ import { assertEquals } from '@std/assert'; +import { genEvent } from '@nostrify/nostrify/test'; import { generateSecretKey, NostrEvent } from 'nostr-tools'; import { getTrendingTagValues } from '@/trends.ts'; -import { createTestDB, genEvent } from '@/test.ts'; +import { createTestDB } from '@/test.ts'; Deno.test("getTrendingTagValues(): 'e' tag and WITHOUT language parameter", async () => { await using db = await createTestDB(); diff --git a/packages/ditto/utils/stats.test.ts b/packages/ditto/utils/stats.test.ts index 797f78da..762db37c 100644 --- a/packages/ditto/utils/stats.test.ts +++ b/packages/ditto/utils/stats.test.ts @@ -1,7 +1,8 @@ +import { genEvent } from '@nostrify/nostrify/test'; import { assertEquals } from '@std/assert'; import { generateSecretKey, getPublicKey } from 'nostr-tools'; -import { createTestDB, genEvent } from '@/test.ts'; +import { createTestDB } from '@/test.ts'; import { countAuthorStats, getAuthorStats, getEventStats, getFollowDiff, updateStats } from '@/utils/stats.ts'; Deno.test('updateStats with kind 1 increments notes count', async () => {