Skip to content

Commit

Permalink
test: add intg tests for nip-33 events w/ expiration tag
Browse files Browse the repository at this point in the history
  • Loading branch information
cameri committed May 24, 2023
1 parent 7fec706 commit d439212
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 3 deletions.
28 changes: 25 additions & 3 deletions test/integration/features/nip-33/nip-33.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,28 @@ Feature: NIP-33 Parameterized replaceable events
When Alice sends a parameterized_replaceable_event_0 event with content "2" and tag d containing "variable"
When Alice subscribes to author Alice
Then Alice receives a parameterized_replaceable_event_0 event from Alice with content "2" and tag d containing "variable"
Then Alice unsubscribes from author Alice
When Alice subscribes to author Alice
Then Alice receives 1 parameterized_replaceable_event_0 event from Alice with content "2" and EOSE

Scenario: Alice adds an expiration tag to a parameterized replaceable event
Given someone called Alice
And someone called Bob
When Alice sends a parameterized_replaceable_event_1 event with content "woot" and tag d containing "stuff"
And Alice sends a parameterized_replaceable_event_1 event with content "nostr.watch" and tag d containing "stuff" and expiring in the future
And Bob subscribes to author Alice
Then Bob receives a parameterized_replaceable_event_1 event from Alice with content "nostr.watch" and tag d containing "stuff"

Scenario: Alice removes an expiration tag to a parameterized replaceable event
Given someone called Alice
And someone called Bob
When Alice sends a parameterized_replaceable_event_1 event with content "nostr.watch" and tag d containing "hey" and expiring in the future
And Alice sends a parameterized_replaceable_event_1 event with content "woot" and tag d containing "hey"
And Bob subscribes to author Alice
Then Bob receives a parameterized_replaceable_event_1 event from Alice with content "woot" and tag d containing "hey"

Scenario: Alice adds and removes an expiration tag to a parameterized replaceable event
Given someone called Alice
And someone called Bob
When Alice sends a parameterized_replaceable_event_1 event with content "first" and tag d containing "friends"
And Alice sends a parameterized_replaceable_event_1 event with content "second" and tag d containing "friends" and expiring in the future
And Alice sends a parameterized_replaceable_event_1 event with content "third" and tag d containing "friends"
And Bob subscribes to author Alice
Then Bob receives a parameterized_replaceable_event_1 event from Alice with content "third" and tag d containing "friends"
60 changes: 60 additions & 0 deletions test/integration/features/nip-33/nip-33.feature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { expect } from 'chai'
import WebSocket from 'ws'

import { createEvent, sendEvent, waitForEventCount, waitForNextEvent } from '../helpers'
import { EventKinds, EventTags } from '../../../../src/constants/base'
import { Event } from '../../../../src/@types/event'

When(/^(\w+) sends a parameterized_replaceable_event_0 event with content "([^"]+)" and tag (\w) containing "([^"]+)"$/, async function(
Expand All @@ -20,6 +21,52 @@ When(/^(\w+) sends a parameterized_replaceable_event_0 event with content "([^"]
this.parameters.events[name].push(event)
})

When(/^(\w+) sends a parameterized_replaceable_event_1 event with content "([^"]+)" and tag (\w) containing "([^"]+)"$/, async function(
name: string,
content: string,
tag: string,
value: string,
) {
const ws = this.parameters.clients[name] as WebSocket
const { pubkey, privkey } = this.parameters.identities[name]

const event: Event = await createEvent(
{
pubkey,
kind: EventKinds.PARAMETERIZED_REPLACEABLE_FIRST + 1,
content,
tags: [[tag, value]],
},
privkey,
)

await sendEvent(ws, event)
this.parameters.events[name].push(event)
})

When(/^(\w+) sends a parameterized_replaceable_event_1 event with content "([^"]+)" and tag (\w) containing "([^"]+)" and expiring in the future$/, async function(
name: string,
content: string,
tag: string,
value: string,
) {
const ws = this.parameters.clients[name] as WebSocket
const { pubkey, privkey } = this.parameters.identities[name]

const event: Event = await createEvent(
{
pubkey,
kind: EventKinds.PARAMETERIZED_REPLACEABLE_FIRST + 1,
content,
tags: [[tag, value], [EventTags.Expiration, Math.floor(new Date().getTime() / 1000 + 10).toString()]],
},
privkey,
)

await sendEvent(ws, event)
this.parameters.events[name].push(event)
})

Then(
/(\w+) receives a parameterized_replaceable_event_0 event from (\w+) with content "([^"]+?)" and tag (\w+) containing "([^"]+?)"/,
async function(name: string, author: string, content: string, tagName: string, tagValue: string) {
Expand All @@ -33,6 +80,19 @@ Then(
expect(receivedEvent.tags[0]).to.deep.equal([tagName, tagValue])
})

Then(
/(\w+) receives a parameterized_replaceable_event_1 event from (\w+) with content "([^"]+?)" and tag (\w+) containing "([^"]+?)"/,
async function(name: string, author: string, content: string, tagName: string, tagValue: string) {
const ws = this.parameters.clients[name] as WebSocket
const subscription = this.parameters.subscriptions[name][this.parameters.subscriptions[name].length - 1]
const receivedEvent = await waitForNextEvent(ws, subscription.name)

expect(receivedEvent.kind).to.equal(30001)
expect(receivedEvent.pubkey).to.equal(this.parameters.identities[author].pubkey)
expect(receivedEvent.content).to.equal(content)
expect(receivedEvent.tags[0]).to.deep.equal([tagName, tagValue])
})

Then(/(\w+) receives (\d+) parameterized_replaceable_event_0 events? from (\w+) with content "([^"]+?)" and EOSE/, async function(
name: string,
count: string,
Expand Down

0 comments on commit d439212

Please sign in to comment.