test: add NIP-22 created_at integration coverage#547
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Cucumber integration coverage for NIP-22 created_at timestamp limit enforcement, ensuring events with implausible timestamps are accepted/rejected as configured.
Changes:
- Add new
@nip-22integration feature + step definitions to exercisecreatedAt.maxPositiveDelta/maxNegativeDelta. - Update
EventMessageHandler’s “too far in the future” reason prefix fromrejected:toinvalid:and align the corresponding unit test expectation. - Add a Changesets entry (currently marked as empty/tests-only).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/unit/handlers/event-message-handler.spec.ts | Updates expectation to match the new invalid: prefix for future created_at rejection. |
| test/integration/features/nip-22/nip-22.feature.ts | Adds step defs to set created_at limits and draft/send events with relative timestamps. |
| test/integration/features/nip-22/nip-22.feature | Adds scenarios for accepted/rejected created_at timestamps around configured deltas. |
| src/handlers/event-message-handler.ts | Changes rejection reason prefix for future created_at limit from rejected: to invalid:. |
| .changeset/nip-22-created-at-tests-empty.md | Adds an “empty” changeset despite the PR also changing runtime behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const setCreatedAtLimits = (maxPositiveDelta: number, maxNegativeDelta: number) => { | ||
| const settings = SettingsStatic._settings ?? SettingsStatic.createSettings() | ||
|
|
||
| SettingsStatic._settings = pipe( | ||
| assocPath(['limits', 'event', 'createdAt', 'maxPositiveDelta'], maxPositiveDelta), | ||
| assocPath(['limits', 'event', 'createdAt', 'maxNegativeDelta'], maxNegativeDelta), | ||
| )(settings) as any | ||
| } | ||
|
|
||
| After({ tags: '@nip-22' }, function() { | ||
| setCreatedAtLimits(900, 0) | ||
| }) |
There was a problem hiding this comment.
The @nip-22 After hook resets created_at limits to hard-coded defaults (900/0). Integration tests globally override limits.event.createdAt.maxPositiveDelta to 0 in test/integration/features/shared.ts to avoid time-based flakiness; restoring to 900 here will leak settings changes into subsequent scenarios/features and can cause flaky failures. Snapshot the previous settings (or previous createdAt limits) before modifying, and restore that snapshot in After instead of hard-coding values.
5978029 to
cbec93c
Compare
62ef026 to
32ac52e
Compare
|
@cameri thank you |
Description
Added integration tests for NIP-22
created_attimestamp limits as requested in issue #505.These tests verify that the relay correctly enforces:
createdAt.maxPositiveDelta(default: 900 seconds)createdAt.maxNegativeDelta(default: 0 = unlimited)Related Issue
Closes #505
Motivation and Context
Currently, there were no integration tests covering the timestamp validation logic for event
created_atfield.This PR adds proper Cucumber integration tests to ensure events with implausible timestamps (too far in future or past) are rejected while valid ones are accepted.
How Has This Been Tested?
test/integration/features/nip-22/nip-22.featuretest/integration/features/nip-22/nip-22.feature.tsmaxNegativeDelta→ rejectedmaxNegativeDelta→ acceptedTypes of changes
Checklist: