Skip to content

test: add NIP-22 created_at integration coverage - #547

Merged
cameri merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:feat/integration-tests-nip-22-timestamp-limits
Apr 22, 2026
Merged

test: add NIP-22 created_at integration coverage#547
cameri merged 2 commits into
cameri:mainfrom
Priyanshubhartistm:feat/integration-tests-nip-22-timestamp-limits

Conversation

@Priyanshubhartistm

Copy link
Copy Markdown
Collaborator

Description

Added integration tests for NIP-22 created_at timestamp 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_at field.
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?

  • Added new feature file: test/integration/features/nip-22/nip-22.feature
  • Added corresponding step definitions: test/integration/features/nip-22/nip-22.feature.ts
  • Tests cover all cases mentioned in the issue:
    • Event at current time → accepted
    • Event at +900s (limit) → accepted
    • Event at +901s → rejected with "invalid"
    • Event older than configured maxNegativeDelta → rejected
    • Event within maxNegativeDelta → accepted
  • Tests were written following the existing integration test patterns in the project.
  • After hook properly restores default settings to avoid affecting other tests.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

  • My code follows the code style of this project.
  • I have added tests to cover my code changes.
  • All new and existing tests passed.

@coveralls

coveralls commented Apr 20, 2026

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 74.929% (+0.2%) from 74.712% — Priyanshubhartistm:feat/integration-tests-nip-22-timestamp-limits into cameri:main

Comment threadsrc/handlers/event-message-handler.ts
Comment threadtest/integration/features/nip-22/nip-22.feature Outdated
Comment threadtest/integration/features/nip-22/nip-22.feature Outdated

CopilotAI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-22 integration feature + step definitions to exercise createdAt.maxPositiveDelta / maxNegativeDelta.
  • Update EventMessageHandler’s “too far in the future” reason prefix from rejected: to invalid: 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
FileDescription
test/unit/handlers/event-message-handler.spec.tsUpdates expectation to match the new invalid: prefix for future created_at rejection.
test/integration/features/nip-22/nip-22.feature.tsAdds step defs to set created_at limits and draft/send events with relative timestamps.
test/integration/features/nip-22/nip-22.featureAdds scenarios for accepted/rejected created_at timestamps around configured deltas.
src/handlers/event-message-handler.tsChanges rejection reason prefix for future created_at limit from rejected: to invalid:.
.changeset/nip-22-created-at-tests-empty.mdAdds an “empty” changeset despite the PR also changing runtime behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +13 to +24
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)
})

CopilotAIApr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment threadtest/integration/features/nip-22/nip-22.feature.ts
Comment threadsrc/handlers/event-message-handler.ts
Comment thread.changeset/nip-22-created-at-tests-empty.md Outdated
@Priyanshubhartistm
Priyanshubhartistmforce-pushed the feat/integration-tests-nip-22-timestamp-limits branch from 5978029 to cbec93cCompareApril 20, 2026 13:41
@Priyanshubhartistm
Priyanshubhartistm marked this pull request as draft April 20, 2026 22:40
@Priyanshubhartistm
Priyanshubhartistm marked this pull request as ready for review April 21, 2026 21:17
@Priyanshubhartistm
Priyanshubhartistmforce-pushed the feat/integration-tests-nip-22-timestamp-limits branch from 62ef026 to 32ac52eCompareApril 21, 2026 23:43
@cameri
cameri merged commit 664168a into cameri:mainApr 22, 2026
13 checks passed
@Priyanshubhartistm

Priyanshubhartistm commented Apr 22, 2026

Copy link
Copy Markdown
CollaboratorAuthor

@cameri thank you

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: integration tests for NIP-22 created_at timestamp limits

4 participants

@Priyanshubhartistm@coveralls@cameri