Skip to content

Commit a89a95e

Browse files
authored
test(integration): add NIP-62 vanish tests and fix test enviroment (#537)
* test(integration): add NIP-62 vanish tests and fix test enviroment * fix(redis-adapter): replace leftover debug calls with logger * test(integration): improve NIP-62 assertions
1 parent 9496685 commit a89a95e

3 files changed

Lines changed: 77 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nostream": patch
3+
---
4+
5+
Add NIP-62 integration tests for Request to Vanish
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Feature: NIP-62
2+
Scenario: Alice requests to vanish
3+
Given someone called Alice
4+
And someone called Bob
5+
And Alice sends a set_metadata event
6+
And Alice sends a text_note event with content "please forget this"
7+
When Alice sends a request_to_vanish event
8+
And Bob subscribes to author Alice
9+
Then Bob receives 1 request_to_vanish event from Alice and EOSE
10+
11+
Scenario: Alice cannot publish after requesting to vanish
12+
Given someone called Alice
13+
When Alice sends a request_to_vanish event
14+
And Alice drafts a text_note event with content "I should be blocked"
15+
Then Alice sends their last draft event unsuccessfully because "blocked: request to vanish active for pubkey"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Then, When } from '@cucumber/cucumber'
2+
import { expect } from 'chai'
3+
import WebSocket from 'ws'
4+
5+
import { createEvent, sendEvent, waitForEventCount } from '../helpers'
6+
import { ALL_RELAYS, EventKinds, EventTags } from '../../../../src/constants/base'
7+
import { Event } from '../../../../src/@types/event'
8+
import { isDraft } from '../shared'
9+
10+
When(/^(\w+) sends a request_to_vanish event$/, async function (name: string) {
11+
const ws = this.parameters.clients[name] as WebSocket
12+
const { pubkey, privkey } = this.parameters.identities[name]
13+
14+
const event: Event = await createEvent(
15+
{ pubkey, kind: EventKinds.REQUEST_TO_VANISH, content: '', tags: [[EventTags.Relay, ALL_RELAYS]] },
16+
privkey,
17+
)
18+
19+
await sendEvent(ws, event)
20+
this.parameters.events[name].push(event)
21+
})
22+
23+
Then(
24+
/(\w+) receives (\d+) request_to_vanish events? from (\w+) and EOSE$/,
25+
async function (name: string, count: string, author: string) {
26+
const ws = this.parameters.clients[name] as WebSocket
27+
const subscription = this.parameters.subscriptions[name][this.parameters.subscriptions[name].length - 1]
28+
const expectedCount = Number(count)
29+
const expectedPubkey = this.parameters.identities[author].pubkey
30+
const events = await waitForEventCount(ws, subscription.name, expectedCount, true)
31+
32+
expect(events.length).to.equal(expectedCount)
33+
for (const event of events) {
34+
expect(event.kind).to.equal(EventKinds.REQUEST_TO_VANISH)
35+
expect(event.pubkey).to.equal(expectedPubkey)
36+
}
37+
},
38+
)
39+
40+
Then(
41+
/^(\w+) sends their last draft event unsuccessfully because "([^"]+)"$/,
42+
async function (name: string, reason: string) {
43+
const ws = this.parameters.clients[name] as WebSocket
44+
const event = this.parameters.events[name].findLast((event: Event) => event[isDraft])
45+
46+
if (!event) {
47+
throw new Error(`No draft event found for ${name}`)
48+
}
49+
50+
delete event[isDraft]
51+
52+
const command = await sendEvent(ws, event, false)
53+
expect(command[1]).to.equal(event.id)
54+
expect(command[2]).to.be.false
55+
expect(command[3]).to.equal(reason)
56+
},
57+
)

0 commit comments

Comments
 (0)