mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
Merge branch 'genevent' into 'main'
Switch to genEvent from Nostrify See merge request soapbox-pub/ditto!678
This commit is contained in:
commit
d3a20fa2dc
6 changed files with 10 additions and 26 deletions
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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'));
|
||||
|
|
|
|||
|
|
@ -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<NostrEvent> {
|
|||
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. */
|
||||
export async function createTestDB(opts?: { pure?: boolean }) {
|
||||
const { kysely } = DittoDB.create(Conf.databaseUrl, { poolSize: 1 });
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue