Skip to content

feat: add NIP-13 Proof of Work enforcement scenarios and implementation#513

Merged
cameri merged 4 commits intocameri:mainfrom
Mahmoud-s-Khedr:integration-test-001
Apr 19, 2026
Merged

feat: add NIP-13 Proof of Work enforcement scenarios and implementation#513
cameri merged 4 commits intocameri:mainfrom
Mahmoud-s-Khedr:integration-test-001

Conversation

@Mahmoud-s-Khedr
Copy link
Copy Markdown
Contributor

Description

Adds integration coverage for NIP-13 Proof of Work enforcement by introducing a new Cucumber suite under test/integration/features/nip-13/.

Included coverage:

  • limits.event.eventId.minLeadingZeroBits = 0 accepts events regardless of PoW.
  • limits.event.eventId.minLeadingZeroBits > 0 rejects insufficient event-id PoW with exact OK reason (pow: difficulty X<Y).
  • limits.event.eventId.minLeadingZeroBits > 0 accepts sufficient event-id PoW.
  • limits.event.pubkey.minLeadingZeroBits > 0 rejects insufficient pubkey PoW with exact OK reason (pow: pubkey difficulty X<Y).
  • limits.event.pubkey.minLeadingZeroBits > 0 accepts sufficient pubkey PoW.

Implementation details:

  • Added deterministic mining helpers in step definitions for event-id and pubkey PoW targets (below / at least threshold), avoiding flaky random behavior.
  • Added test-local settings override for PoW thresholds and restoration via @nip13 After hook to avoid cross-scenario leakage.
  • Kept scenario content assertions stable by varying a nonce tag during event-id mining.
  • Added explicit timeout for mining-heavy steps to prevent intermittent timeout failures in slower environments.

No production API/schema behavior was changed; this is test-only coverage.

Related Issue

Motivation and Context

The relay already enforces PoW using limits.event.eventId.minLeadingZeroBits and limits.event.pubkey.minLeadingZeroBits, but there was no integration coverage proving real end-to-end behavior at websocket command level.

This change closes that gap by validating:

  • default acceptance when PoW requirements are disabled,
  • correct rejection paths and exact rejection messages when enabled,
  • successful acceptance paths when PoW requirements are met.

How Has This Been Tested?

Executed in the integration docker environment to ensure DB/cache/bootstrap conditions match integration expectations:

npm run docker:integration:run -- npm run test:integration -- test/integration/features/nip-13/nip-13.feature

Result:

  • 39 scenarios (39 passed)
  • 226 steps (226 passed)

Also validated local type/lint during implementation:

  • npm run build:check
  • npm run lint -- test/integration/features/nip-13

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist:

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

@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 18, 2026

Coverage Status

coverage: 68.308%. remained the same — Mahmoud-s-Khedr:integration-test-001 into cameri:main

Copilot AI review requested due to automatic review settings April 18, 2026 20:44
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 end-to-end integration coverage for NIP-13 Proof-of-Work enforcement by introducing a dedicated Cucumber feature suite and step definitions that deterministically mine event-id and pubkey PoW and toggle relay settings per scenario.

Changes:

  • Added @nip13 Cucumber scenarios asserting accept/reject behavior and exact OK rejection reasons for event-id and pubkey PoW thresholds.
  • Implemented deterministic PoW “mining” helpers in step definitions, plus per-scenario settings overrides with restoration in an After hook.
  • Added a Changesets file (currently empty frontmatter).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
test/integration/features/nip-13/nip-13.feature.ts New step definitions: settings overrides, deterministic PoW mining, and command/result assertions.
test/integration/features/nip-13/nip-13.feature New @nip13 feature with scenarios covering disabled/enabled PoW for event-id and pubkey.
.changeset/old-toys-stare.md Adds a Changesets entry (needs proper package bump + summary).

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

Comment thread .changeset/old-toys-stare.md
Comment thread test/integration/features/nip-13/nip-13.feature.ts Outdated
Comment thread test/integration/features/nip-13/nip-13.feature.ts
Copy link
Copy Markdown
Owner

@cameri cameri left a comment

Choose a reason for hiding this comment

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

👏

Comment thread test/integration/features/nip-13/nip-13.feature.ts
@cameri cameri self-assigned this Apr 19, 2026
@cameri cameri merged commit f5093cb into cameri:main Apr 19, 2026
13 checks passed
@Mahmoud-s-Khedr Mahmoud-s-Khedr deleted the integration-test-001 branch April 22, 2026 03:44
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 Proof of Work enforcement (NIP-13)

4 participants