Skip to content

Commit 5978029

Browse files
fix nip-22 review feedback
1 parent 37669d2 commit 5978029

3 files changed

Lines changed: 13 additions & 14 deletions

File tree

src/handlers/event-message-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export class EventMessageHandler implements IMessageHandler {
165165
limits.createdAt.maxPositiveDelta > 0 &&
166166
event.created_at > now + limits.createdAt.maxPositiveDelta
167167
) {
168-
return `invalid: created_at is more than ${limits.createdAt.maxPositiveDelta} seconds in the future`
168+
return `rejected: created_at is more than ${limits.createdAt.maxPositiveDelta} seconds in the future`
169169
}
170170

171171
if (

test/integration/features/nip-22/nip-22.feature

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,11 @@ Feature: NIP-22 created_at timestamp limits
88
When Alice subscribes to author Alice
99
Then Alice receives a text_note event from Alice with content "test event"
1010

11-
Scenario: Event with created_at at positive delta limit is accepted
12-
Given someone called Alice
13-
And created_at limits are set to maxPositiveDelta 900 and maxNegativeDelta 0
14-
When Alice drafts a text_note event with content "test event" and created_at 900 seconds from now
15-
Then Alice sends their last draft event successfully
16-
When Alice subscribes to author Alice
17-
Then Alice receives a text_note event from Alice with content "test event"
18-
1911
Scenario: Event with created_at above positive delta limit is rejected
2012
Given someone called Alice
2113
And created_at limits are set to maxPositiveDelta 900 and maxNegativeDelta 0
22-
When Alice drafts a text_note event with content "test event" and created_at 901 seconds from now
23-
Then Alice sends their last draft event unsuccessfully with reason containing "invalid"
14+
When Alice drafts a text_note event with content "test event" and created_at 910 seconds from now
15+
Then Alice sends their last draft event unsuccessfully with reason containing "rejected"
2416

2517
Scenario: Event older than configured negative delta limit is rejected
2618
Given someone called Alice

test/integration/features/nip-22/nip-22.feature.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { After, Given, Then, When } from '@cucumber/cucumber'
1+
import { After, Before, Given, Then, When } from '@cucumber/cucumber'
22
import { assocPath, pipe } from 'ramda'
33

44
import { CommandResult, MessageType } from '../../../../src/@types/messages'
@@ -10,6 +10,8 @@ import { isDraft } from '../shared'
1010
import { SettingsStatic } from '../../../../src/utils/settings'
1111
import WebSocket from 'ws'
1212

13+
const previousSettingsSnapshot = Symbol('nip22PreviousSettingsSnapshot')
14+
1315
const setCreatedAtLimits = (maxPositiveDelta: number, maxNegativeDelta: number) => {
1416
const settings = SettingsStatic._settings ?? SettingsStatic.createSettings()
1517

@@ -19,8 +21,13 @@ const setCreatedAtLimits = (maxPositiveDelta: number, maxNegativeDelta: number)
1921
)(settings) as any
2022
}
2123

22-
After({ tags: '@nip-22' }, function() {
23-
setCreatedAtLimits(900, 0)
24+
Before({ tags: '@nip-22' }, function(this: any) {
25+
this[previousSettingsSnapshot] = SettingsStatic._settings
26+
})
27+
28+
After({ tags: '@nip-22' }, function(this: any) {
29+
SettingsStatic._settings = this[previousSettingsSnapshot]
30+
delete this[previousSettingsSnapshot]
2431
})
2532

2633
Given(/^created_at limits are set to maxPositiveDelta (\d+) and maxNegativeDelta (\d+)$/, function(

0 commit comments

Comments
 (0)