Skip to content

test: add NIP-22 created_at integration coverage#547

Merged
cameri merged 2 commits intocameri: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 intocameri: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
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 20, 2026

Coverage Status

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

@cameri cameri requested a review from Copilot April 20, 2026 01:23
@cameri cameri self-assigned this Apr 20, 2026
Comment thread src/handlers/event-message-handler.ts
Comment thread test/integration/features/nip-22/nip-22.feature Outdated
Comment thread test/integration/features/nip-22/nip-22.feature Outdated
Copy link
Copy Markdown

Copilot AI left a comment

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
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.

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)
})
Copy link

Copilot AI Apr 20, 2026

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 thread test/integration/features/nip-22/nip-22.feature.ts
Comment on lines 165 to 169
limits.createdAt.maxPositiveDelta > 0 &&
event.created_at > now + limits.createdAt.maxPositiveDelta
) {
return `rejected: created_at is more than ${limits.createdAt.maxPositiveDelta} seconds in the future`
return `invalid: created_at is more than ${limits.createdAt.maxPositiveDelta} seconds in the future`
}
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This change alters the OK failure reason prefix from rejected: to invalid: for a production validation path. The PR title/description indicate only test additions, and the changeset added is marked as an empty tests-only change; either update the PR description/changeset to reflect this user-visible protocol change (and ensure it’s intended), or keep behavior consistent with the existing rejected: semantics.

Copilot uses AI. Check for mistakes.
Comment on lines +1 to +4
---
---

Add empty changeset for NIP-22 created_at integration test coverage (issue #505).
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

This changeset is declared as empty/tests-only, but this PR also changes runtime behavior in EventMessageHandler (switching a rejection reason prefix to invalid:). If that behavior change is kept, the changeset should include the appropriate package release entry (or the code change should be moved/reverted so the changeset matches the PR scope).

Copilot uses AI. Check for mistakes.
@Priyanshubhartistm Priyanshubhartistm force-pushed the feat/integration-tests-nip-22-timestamp-limits branch from 5978029 to cbec93c Compare April 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 Priyanshubhartistm force-pushed the feat/integration-tests-nip-22-timestamp-limits branch from 62ef026 to 32ac52e Compare April 21, 2026 23:43
@cameri cameri merged commit 664168a into cameri:main Apr 22, 2026
13 checks passed
@Priyanshubhartistm
Copy link
Copy Markdown
Collaborator Author

@cameri thanku

Sign up for free to 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