Switch to genEvent from Nostrify

This commit is contained in:
Alex Gleason 2025-02-18 16:35:45 -06:00
parent 32813485a5
commit c29fc57a8c
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
6 changed files with 10 additions and 26 deletions

View file

@ -1,12 +1,13 @@
import { confMw } from '@ditto/api/middleware'; import { confMw } from '@ditto/api/middleware';
import { Env as HonoEnv, Hono } from '@hono/hono'; import { Env as HonoEnv, Hono } from '@hono/hono';
import { NostrSigner, NSecSigner, NStore } from '@nostrify/nostrify'; import { NostrSigner, NSecSigner, NStore } from '@nostrify/nostrify';
import { genEvent } from '@nostrify/nostrify/test';
import { generateSecretKey, getPublicKey } from 'nostr-tools'; import { generateSecretKey, getPublicKey } from 'nostr-tools';
import { bytesToString, stringToBytes } from '@scure/base'; import { bytesToString, stringToBytes } from '@scure/base';
import { stub } from '@std/testing/mock'; import { stub } from '@std/testing/mock';
import { assertEquals, assertExists, assertObjectMatch } from '@std/assert'; 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 cashuApp from '@/controllers/api/cashu.ts';
import { walletSchema } from '@/schema.ts'; import { walletSchema } from '@/schema.ts';

View file

@ -1,8 +1,9 @@
import { assertEquals, assertRejects } from '@std/assert'; import { assertEquals, assertRejects } from '@std/assert';
import { genEvent } from '@nostrify/nostrify/test';
import { generateSecretKey } from 'nostr-tools'; import { generateSecretKey } from 'nostr-tools';
import { RelayError } from '@/RelayError.ts'; import { RelayError } from '@/RelayError.ts';
import { eventFixture, genEvent } from '@/test.ts'; import { eventFixture } from '@/test.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { EventsDB } from '@/storages/EventsDB.ts'; import { EventsDB } from '@/storages/EventsDB.ts';
import { createTestDB } from '@/test.ts'; import { createTestDB } from '@/test.ts';

View file

@ -1,5 +1,6 @@
import { jsonlEvents } from '@nostrify/nostrify/test';
import { assembleEvents } from '@/storages/hydrate.ts'; import { assembleEvents } from '@/storages/hydrate.ts';
import { jsonlEvents } from '@/test.ts';
const testEvents = await jsonlEvents('fixtures/hydrated.jsonl'); const testEvents = await jsonlEvents('fixtures/hydrated.jsonl');
const testStats = JSON.parse(await Deno.readTextFile('fixtures/stats.json')); const testStats = JSON.parse(await Deno.readTextFile('fixtures/stats.json'));

View file

@ -1,10 +1,8 @@
import { DittoDB } from '@ditto/db'; import { DittoDB } from '@ditto/db';
import { NostrEvent } from '@nostrify/nostrify'; import { NostrEvent } from '@nostrify/nostrify';
import { finalizeEvent, generateSecretKey } from 'nostr-tools';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { EventsDB } from '@/storages/EventsDB.ts'; import { EventsDB } from '@/storages/EventsDB.ts';
import { purifyEvent } from '@/utils/purify.ts';
import { sql } from 'kysely'; import { sql } from 'kysely';
/** Import an event fixture by name in tests. */ /** Import an event fixture by name in tests. */
@ -13,25 +11,6 @@ export async function eventFixture(name: string): Promise<NostrEvent> {
return structuredClone(result.default); return structuredClone(result.default);
} }
/** Import a JSONL fixture by name in tests. */
export async function jsonlEvents(path: string): Promise<NostrEvent[]> {
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<NostrEvent> = {}, 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. */ /** Create a database for testing. It uses `DATABASE_URL`, or creates an in-memory database by default. */
export async function createTestDB(opts?: { pure?: boolean }) { export async function createTestDB(opts?: { pure?: boolean }) {
const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 }); const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 });

View file

@ -1,8 +1,9 @@
import { assertEquals } from '@std/assert'; import { assertEquals } from '@std/assert';
import { genEvent } from '@nostrify/nostrify/test';
import { generateSecretKey, NostrEvent } from 'nostr-tools'; import { generateSecretKey, NostrEvent } from 'nostr-tools';
import { getTrendingTagValues } from '@/trends.ts'; 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 () => { Deno.test("getTrendingTagValues(): 'e' tag and WITHOUT language parameter", async () => {
await using db = await createTestDB(); await using db = await createTestDB();

View file

@ -1,7 +1,8 @@
import { genEvent } from '@nostrify/nostrify/test';
import { assertEquals } from '@std/assert'; import { assertEquals } from '@std/assert';
import { generateSecretKey, getPublicKey } from 'nostr-tools'; 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'; import { countAuthorStats, getAuthorStats, getEventStats, getFollowDiff, updateStats } from '@/utils/stats.ts';
Deno.test('updateStats with kind 1 increments notes count', async () => { Deno.test('updateStats with kind 1 increments notes count', async () => {