From 9cb63a99183ab2e09adf5ba90846f505f6f52fb2 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 20:18:11 -0300 Subject: [PATCH 1/8] test: kind 0(user 'dictator') fixture --- fixtures/events/kind-0-dictator.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fixtures/events/kind-0-dictator.json diff --git a/fixtures/events/kind-0-dictator.json b/fixtures/events/kind-0-dictator.json new file mode 100644 index 0000000..a547332 --- /dev/null +++ b/fixtures/events/kind-0-dictator.json @@ -0,0 +1,9 @@ +{ + "id": "2238893aee54bbe9188498a5aa124d62870d5757894bf52cdb362d1a0874ed18", + "pubkey": "c9f5508526e213c3bc5468161f1b738a86063a2ece540730f9412e7becd5f0b2", + "created_at": 1715517440, + "kind": 0, + "tags": [], + "content": "{\"name\":\"dictator\",\"about\":\"\",\"nip05\":\"\"}", + "sig": "a630ba158833eea10289fe077087ccad22c71ddfbe475153958cfc158ae94fb0a5f7b7626e62da6a3ef8bfbe67321e8f993517ed7f1578a45aff11bc2bec484c" +} From aec0afd731d6da6247d6ee2cd272f00a5ba9a583 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 20:18:42 -0300 Subject: [PATCH 2/8] test: kind 0(user 'george orwell') fixture --- fixtures/events/kind-0-george-orwell.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fixtures/events/kind-0-george-orwell.json diff --git a/fixtures/events/kind-0-george-orwell.json b/fixtures/events/kind-0-george-orwell.json new file mode 100644 index 0000000..d835447 --- /dev/null +++ b/fixtures/events/kind-0-george-orwell.json @@ -0,0 +1,9 @@ +{ + "id": "da4e1e727c6456cee2b0341a1d7a2356e4263523374a2570a7dd318ab5d73f93", + "pubkey": "e4d96e951739787e62ada74ee06a9a185af22791a899a6166ec23aab58c5d700", + "created_at": 1715517565, + "kind": 0, + "tags": [], + "content": "{\"name\":\"george orwell\",\"about\":\"\",\"nip05\":\"\"}", + "sig": "cd375e2065cf452d3bfefa9951b04ab63018ab7c253803256cca1d89d03b38e454c71ed36fdd3c28a8ff2723cc19b21371ce0f9bbd39a92b1d1aa946137237bd" +} From f225f7498df6383ee8978d1c7d31468192327535 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 20:19:30 -0300 Subject: [PATCH 3/8] test: kind 1 (author is 'george orwell') fixture --- fixtures/events/kind-1-author-george-orwell.json | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 fixtures/events/kind-1-author-george-orwell.json diff --git a/fixtures/events/kind-1-author-george-orwell.json b/fixtures/events/kind-1-author-george-orwell.json new file mode 100644 index 0000000..d1bd4ab --- /dev/null +++ b/fixtures/events/kind-1-author-george-orwell.json @@ -0,0 +1,9 @@ +{ + "id": "44f19148f5af60b0f43ed8c737fbda31b165e05bb55562003c45d9a9f02e8228", + "pubkey": "e4d96e951739787e62ada74ee06a9a185af22791a899a6166ec23aab58c5d700", + "created_at": 1715636249, + "kind": 1, + "tags": [], + "content": "I like free speech", + "sig": "6b50db9c1c02bd8b0e64512e71d53a0058569f44e8dcff65ad17fce544d6ae79f8f79fa0f9a615446fa8cbc2375709bf835751843b0cd10e62ae5d505fe106d4" +} From c67cb034b08d10e867dbc4a1a6b3c6fc53d48f10 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 20:20:18 -0300 Subject: [PATCH 4/8] test: kind 1984 (author 'dictator') fixture --- ...d-1984-dictator-reports-george-orwell.json | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 fixtures/events/kind-1984-dictator-reports-george-orwell.json diff --git a/fixtures/events/kind-1984-dictator-reports-george-orwell.json b/fixtures/events/kind-1984-dictator-reports-george-orwell.json new file mode 100644 index 0000000..7280c59 --- /dev/null +++ b/fixtures/events/kind-1984-dictator-reports-george-orwell.json @@ -0,0 +1,24 @@ +{ + "id": "129b2749330a7f1189d3e74c6764a955851f1e4017a818dfd51ab8e24192b0f3", + "pubkey": "c9f5508526e213c3bc5468161f1b738a86063a2ece540730f9412e7becd5f0b2", + "created_at": 1715636348, + "kind": 1984, + "tags": [ + [ + "p", + "e4d96e951739787e62ada74ee06a9a185af22791a899a6166ec23aab58c5d700", + "other" + ], + [ + "P", + "e724b1c1b90eab9cc0f5976b380b80dda050de1820dc143e62d9e4f27a9a0b2c" + ], + [ + "e", + "44f19148f5af60b0f43ed8c737fbda31b165e05bb55562003c45d9a9f02e8228", + "other" + ] + ], + "content": "freedom of speech not freedom of reach", + "sig": "cd05a14749cdf0c7664d056e2c02518740000387732218dacd0c71de5b96c0c3c99a0b927b0cd0778f25a211525fa03b4ed4f4f537bb1221c73467780d4ee1bc" +} From 78137f373f7e14c7b228b0b8a630df532817c1e4 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 20:22:27 -0300 Subject: [PATCH 5/8] test(hydrate): kind 1984 --- src/storages/hydrate.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/storages/hydrate.test.ts b/src/storages/hydrate.test.ts index 4e38d8a..1664a6d 100644 --- a/src/storages/hydrate.test.ts +++ b/src/storages/hydrate.test.ts @@ -129,3 +129,31 @@ Deno.test('hydrateEvents(): repost of quote repost --- WITHOUT stats', async () }; assertEquals(event6copy, expectedEvent6); }); + +Deno.test('hydrateEvents(): report pubkey and post // kind 1984 --- WITHOUT stats', async () => { + const db = new MockRelay(); + + const authorDictator = await eventFixture('kind-0-dictator'); + const authorVictim = await eventFixture('kind-0-george-orwell'); + const reportEvent = await eventFixture('kind-1984-dictator-reports-george-orwell'); + const event1 = await eventFixture('kind-1-author-george-orwell'); + + // Save events to database + await db.event(authorDictator); + await db.event(authorVictim); + await db.event(reportEvent); + await db.event(event1); + + await hydrateEvents({ + events: [reportEvent], + storage: db, + }); + + const expectedEvent: DittoEvent = { + ...reportEvent, + author: authorDictator, + reported_notes: [event1], + reported_profile: authorVictim, + }; + assertEquals(reportEvent, expectedEvent); +}); From caaa7016f0feb875105166704974755398b2c063 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Mon, 13 May 2024 21:56:29 -0300 Subject: [PATCH 6/8] test(hydrate): refactor to import fixtures with 'eventFixture' function --- src/storages/hydrate.test.ts | 102 ++++++++++++++--------------------- 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/src/storages/hydrate.test.ts b/src/storages/hydrate.test.ts index 1664a6d..b55cd2b 100644 --- a/src/storages/hydrate.test.ts +++ b/src/storages/hydrate.test.ts @@ -5,129 +5,105 @@ import { MockRelay } from '@nostrify/nostrify/test'; import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { eventFixture } from '@/test.ts'; -import event0madePost from '~/fixtures/events/event-0-the-one-who-post-and-users-repost.json' with { type: 'json' }; -import event0madeRepost from '~/fixtures/events/event-0-the-one-who-repost.json' with { type: 'json' }; -import event0madeQuoteRepost from '~/fixtures/events/event-0-the-one-who-quote-repost.json' with { type: 'json' }; -import event1 from '~/fixtures/events/event-1.json' with { type: 'json' }; -import event1quoteRepost from '~/fixtures/events/event-1-quote-repost.json' with { type: 'json' }; -import event1futureIsMine from '~/fixtures/events/event-1-will-be-reposted-with-quote-repost.json' with { - type: 'json', -}; -import event1quoteRepostLatin from '~/fixtures/events/event-1-quote-repost-will-be-reposted.json' with { type: 'json' }; -import event1willBeQuoteReposted from '~/fixtures/events/event-1-that-will-be-quote-reposted.json' with { - type: 'json', -}; -import event1reposted from '~/fixtures/events/event-1-reposted.json' with { type: 'json' }; -import event6 from '~/fixtures/events/event-6.json' with { type: 'json' }; -import event6ofQuoteRepost from '~/fixtures/events/event-6-of-quote-repost.json' with { type: 'json' }; - Deno.test('hydrateEvents(): author --- WITHOUT stats', async () => { const db = new MockRelay(); const event0 = await eventFixture('event-0'); - const event1copy = structuredClone(event1); + const event1 = await eventFixture('event-1'); // Save events to database await db.event(event0); - await db.event(event1copy); - - assertEquals((event1copy as DittoEvent).author, undefined, "Event hasn't been hydrated yet"); + await db.event(event1); await hydrateEvents({ - events: [event1copy], + events: [event1], storage: db, }); - const expectedEvent = { ...event1copy, author: event0 }; - assertEquals(event1copy, expectedEvent); + const expectedEvent = { ...event1, author: event0 }; + assertEquals(event1, expectedEvent); }); Deno.test('hydrateEvents(): repost --- WITHOUT stats', async () => { const db = new MockRelay(); - const event0madePostCopy = structuredClone(event0madePost); - const event0madeRepostCopy = structuredClone(event0madeRepost); - const event1repostedCopy = structuredClone(event1reposted); - const event6copy = structuredClone(event6); + const event0madePost = await eventFixture('event-0-the-one-who-post-and-users-repost'); + const event0madeRepost = await eventFixture('event-0-the-one-who-repost'); + const event1reposted = await eventFixture('event-1-reposted'); + const event6 = await eventFixture('event-6'); // Save events to database - await db.event(event0madePostCopy); - await db.event(event0madeRepostCopy); - await db.event(event1repostedCopy); - await db.event(event6copy); - - assertEquals((event6copy as DittoEvent).author, undefined, "Event hasn't hydrated author yet"); - assertEquals((event6copy as DittoEvent).repost, undefined, "Event hasn't hydrated repost yet"); + await db.event(event0madePost); + await db.event(event0madeRepost); + await db.event(event1reposted); + await db.event(event6); await hydrateEvents({ - events: [event6copy], + events: [event6], storage: db, }); const expectedEvent6 = { - ...event6copy, - author: event0madeRepostCopy, - repost: { ...event1repostedCopy, author: event0madePostCopy }, + ...event6, + author: event0madeRepost, + repost: { ...event1reposted, author: event0madePost }, }; - assertEquals(event6copy, expectedEvent6); + assertEquals(event6, expectedEvent6); }); Deno.test('hydrateEvents(): quote repost --- WITHOUT stats', async () => { const db = new MockRelay(); - const event0madeQuoteRepostCopy = structuredClone(event0madeQuoteRepost); + const event0madeQuoteRepost = await eventFixture('event-0-the-one-who-quote-repost'); const event0 = await eventFixture('event-0'); - const event1quoteRepostCopy = structuredClone(event1quoteRepost); - const event1willBeQuoteRepostedCopy = structuredClone(event1willBeQuoteReposted); + const event1quoteRepost = await eventFixture('event-1-quote-repost'); + const event1willBeQuoteReposted = await eventFixture('event-1-that-will-be-quote-reposted'); // Save events to database - await db.event(event0madeQuoteRepostCopy); + await db.event(event0madeQuoteRepost); await db.event(event0); - await db.event(event1quoteRepostCopy); - await db.event(event1willBeQuoteRepostedCopy); + await db.event(event1quoteRepost); + await db.event(event1willBeQuoteReposted); await hydrateEvents({ - events: [event1quoteRepostCopy], + events: [event1quoteRepost], storage: db, }); const expectedEvent1quoteRepost = { - ...event1quoteRepostCopy, - author: event0madeQuoteRepostCopy, - quote: { ...event1willBeQuoteRepostedCopy, author: event0 }, + ...event1quoteRepost, + author: event0madeQuoteRepost, + quote: { ...event1willBeQuoteReposted, author: event0 }, }; - assertEquals(event1quoteRepostCopy, expectedEvent1quoteRepost); + assertEquals(event1quoteRepost, expectedEvent1quoteRepost); }); Deno.test('hydrateEvents(): repost of quote repost --- WITHOUT stats', async () => { const db = new MockRelay(); const author = await eventFixture('event-0-makes-repost-with-quote-repost'); - const event1copy = structuredClone(event1futureIsMine); - const event1quoteCopy = structuredClone(event1quoteRepostLatin); - const event6copy = structuredClone(event6ofQuoteRepost); + const event1 = await eventFixture('event-1-will-be-reposted-with-quote-repost'); + const event6 = await eventFixture('event-6-of-quote-repost'); + const event1quote = await eventFixture('event-1-quote-repost-will-be-reposted'); // Save events to database await db.event(author); - await db.event(event1copy); - await db.event(event1quoteCopy); - await db.event(event6copy); - - assertEquals((event6copy as DittoEvent).author, undefined, "Event hasn't hydrated author yet"); - assertEquals((event6copy as DittoEvent).repost, undefined, "Event hasn't hydrated repost yet"); + await db.event(event1); + await db.event(event1quote); + await db.event(event6); await hydrateEvents({ - events: [event6copy], + events: [event6], storage: db, }); const expectedEvent6 = { - ...event6copy, + ...event6, author, - repost: { ...event1quoteCopy, author, quote: { author, ...event1copy } }, + repost: { ...event1quote, author, quote: { author, ...event1 } }, }; - assertEquals(event6copy, expectedEvent6); + assertEquals(event6, expectedEvent6); }); Deno.test('hydrateEvents(): report pubkey and post // kind 1984 --- WITHOUT stats', async () => { From dd3c64ef849e3dfeb5e1cd4847e4a1c954369edb Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 13:09:16 -0500 Subject: [PATCH 7/8] Remove accidentally checked in file --- ..env.swp | Bin 1024 -> 0 bytes .gitignore | 1 + 2 files changed, 1 insertion(+) delete mode 100644 ..env.swp diff --git a/..env.swp b/..env.swp deleted file mode 100644 index 2ab134254314be032359c6894717262e417e7684..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmYc?$V<%2S1{8vVn6|1lPwq$b5bi%1aWW*@(XnHi*ZOI3G1cil_7CQnWG^v8Uh0x F0sw&A3CREe diff --git a/.gitignore b/.gitignore index d816f9d..39dbfbb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .env *.cpuprofile +*.swp deno-test.xml \ No newline at end of file From b5f0d2f0e60c23bb7025727a13ad59c409ce5212 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 14:12:43 -0500 Subject: [PATCH 8/8] docs/events: clean up User event kind --- docs/events.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/events.md b/docs/events.md index e850fcb..1674239 100644 --- a/docs/events.md +++ b/docs/events.md @@ -9,9 +9,7 @@ The Ditto server publishes kind `30361` events to represent users. These events User events have the following tags: - `d` - pubkey of the user. -- `name` - NIP-05 username granted to the user, without the domain. - `role` - one of `admin` or `user`. -- `origin` - the origin of the user's NIP-05, at the time the event was published. Example: @@ -25,7 +23,6 @@ Example: "tags": [ ["d", "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6"], ["role", "user"], - ["origin", "https://ditto.ngrok.app"], ["alt", "User's account was updated by the admins of ditto.ngrok.app"] ], "sig": "fc12db77b1c8f8aa86c73b617f0cd4af1e6ba244239eaf3164a292de6d39363f32d6b817ffff796ace7a103d75e1d8e6a0fb7f618819b32d81a953b4a75d7507" @@ -40,4 +37,4 @@ The sections below describe the `content` field. Some are encrypted and some are ### `pub.ditto.pleroma.config` -NIP-04 encrypted JSON array of Pleroma ConfigDB objects. Pleroma admin API endpoints set this config, and Ditto reads from it. \ No newline at end of file +NIP-04 encrypted JSON array of Pleroma ConfigDB objects. Pleroma admin API endpoints set this config, and Ditto reads from it.