Skip to content

Add comprehensive unit tests (366 new tests)#4

Open
b3y0urs3lf wants to merge 1 commit into
mainfrom
feature/comprehensive-unit-tests
Open

Add comprehensive unit tests (366 new tests)#4
b3y0urs3lf wants to merge 1 commit into
mainfrom
feature/comprehensive-unit-tests

Conversation

@b3y0urs3lf

Copy link
Copy Markdown

No production code changes — only test files added/extended.

New test files (14):

  • SecurityCriticalTest: key clearing, copy semantics, NIP-17 anonymity
  • NIP44EdgeCasesTest: version validation, payload bounds, padding
  • EventMutabilityTest: tags mutability, null-ID equality, JSON serialization
  • NostrEventListenerTest: callback patterns, default methods
  • Bech32Test, NIP04EncryptionTest, NostrKeyManagerTest, SchnorrSignerTest
  • EventKindsTest, EventTest, NametagBindingTest, NametagUtilsTest
  • PaymentRequestProtocolTest, TokenTransferProtocolTest

Extended existing tests (2):

  • NIP44EncryptionTest: padding boundaries, tampering detection
  • NIP17ProtocolTest: gift wrap scenarios, rumor handling

Key findings from testing:

Security concerns documented:

  • clear() doesn't prevent further key use (zeroed key still works)
  • No curve point validation in NIP-04 ECDH
  • Ephemeral key material lingers in JVM heap (BigInteger immutable)

Design decisions with user impact:

  • Two null-ID Events are considered equal (HashSet data loss risk)
  • Phone heuristic can misclassify text nametags with many digits
  • NIP-04 uses SHA-256 hashed shared secret (non-standard, Unicity-specific)
  • getTags() returns mutable internal reference

All core logic verified correct:

  • Encryption round-trips (NIP-04, NIP-44, NIP-17) work properly
  • Schnorr signing deterministic, verification rejects tampering
  • NIP-44 padding follows spec (power-of-2 chunks, min 32 bytes)
  • Gift wrap timestamp randomization within ±2 day window
  • Payment request/response/decline flow works end-to-end
  • Defensive copies made for private keys in NostrKeyManager

Total: 442 tests across 19 test files

No production code changes — only test files added/extended.

New test files (14):
- SecurityCriticalTest: key clearing, copy semantics, NIP-17 anonymity
- NIP44EdgeCasesTest: version validation, payload bounds, padding
- EventMutabilityTest: tags mutability, null-ID equality, JSON serialization
- NostrEventListenerTest: callback patterns, default methods
- Bech32Test, NIP04EncryptionTest, NostrKeyManagerTest, SchnorrSignerTest
- EventKindsTest, EventTest, NametagBindingTest, NametagUtilsTest
- PaymentRequestProtocolTest, TokenTransferProtocolTest

Extended existing tests (2):
- NIP44EncryptionTest: padding boundaries, tampering detection
- NIP17ProtocolTest: gift wrap scenarios, rumor handling

Key findings from testing:

Security concerns documented:
- clear() doesn't prevent further key use (zeroed key still works)
- No curve point validation in NIP-04 ECDH
- Ephemeral key material lingers in JVM heap (BigInteger immutable)

Design decisions with user impact:
- Two null-ID Events are considered equal (HashSet data loss risk)
- Phone heuristic can misclassify text nametags with many digits
- NIP-04 uses SHA-256 hashed shared secret (non-standard, Unicity-specific)
- getTags() returns mutable internal reference

All core logic verified correct:
- Encryption round-trips (NIP-04, NIP-44, NIP-17) work properly
- Schnorr signing deterministic, verification rejects tampering
- NIP-44 padding follows spec (power-of-2 chunks, min 32 bytes)
- Gift wrap timestamp randomization within ±2 day window
- Payment request/response/decline flow works end-to-end
- Defensive copies made for private keys in NostrKeyManager

Total: 442 tests across 19 test files

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

MastaP added a commit that referenced this pull request May 7, 2026
…connect re-check

Four issues from Copilot review #4 on the Java PR:

1. RelayConnection.connected was a non-volatile boolean. Written from
   the OkHttp WebSocket listener thread (onOpen / onClosed /
   onFailure) and from the executor thread (disconnect /
   scheduleReconnect); read from listener threads via
   allRelaysDoneFor for multi-relay query settlement. Without
   volatile, a stale "connected = true" read after disconnect could
   prevent prompt query settlement on the very disconnect path
   allRelaysDoneFor is supposed to handle. Made connected (and
   wasConnected for symmetry) volatile.

2. Relay disconnect mid-query never triggered allRelaysDoneFor
   re-check — Copilot raised this on TS but it applies equally to
   Java. Added a synthetic onError fan-out in BOTH onClosed and
   onFailure for active subs, so queryWithFirstSeenWins settles
   promptly when a relay drops without sending EOSE/CLOSED.

3. Tests didn't actually drive the relay-aware path. Existing
   reflection invoked handleRelayMessage(String), passing
   relay=null, so the per-relay closedSubIds / eosedSubIds
   bookkeeping was never exercised. Added two new tests that
   construct a RelayConnection via reflection (it's a non-static
   inner class, so we pass the outer NostrClient to its
   constructor), mark it connected, and drive
   handleRelayMessage(RelayConnection, String) directly:
   - closedFrameOnRealRelayPopulatesPerRelayClosedSubIds —
     covers terminal CLOSED → closedSubIds populated; and
     auth-required CLOSED → closedSubIds NOT populated
     (transient).
   - eosedFrameOnRealRelayPopulatesPerRelayEosedSubIds —
     covers EOSE → eosedSubIds populated.

4. Misleading test class Javadocs (both RelayFixesTest and
   RelayFixesE2ETest claimed coverage they didn't actually have).
   Updated to accurately describe which paths each suite exercises
   and to point at the new relay-aware tests for the per-relay
   bookkeeping.

13/13 unit + 5/5 e2e passing.
MastaP added a commit that referenced this pull request May 11, 2026
…connect re-check

Four issues from Copilot review #4 on the Java PR:

1. RelayConnection.connected was a non-volatile boolean. Written from
   the OkHttp WebSocket listener thread (onOpen / onClosed /
   onFailure) and from the executor thread (disconnect /
   scheduleReconnect); read from listener threads via
   allRelaysDoneFor for multi-relay query settlement. Without
   volatile, a stale "connected = true" read after disconnect could
   prevent prompt query settlement on the very disconnect path
   allRelaysDoneFor is supposed to handle. Made connected (and
   wasConnected for symmetry) volatile.

2. Relay disconnect mid-query never triggered allRelaysDoneFor
   re-check — Copilot raised this on TS but it applies equally to
   Java. Added a synthetic onError fan-out in BOTH onClosed and
   onFailure for active subs, so queryWithFirstSeenWins settles
   promptly when a relay drops without sending EOSE/CLOSED.

3. Tests didn't actually drive the relay-aware path. Existing
   reflection invoked handleRelayMessage(String), passing
   relay=null, so the per-relay closedSubIds / eosedSubIds
   bookkeeping was never exercised. Added two new tests that
   construct a RelayConnection via reflection (it's a non-static
   inner class, so we pass the outer NostrClient to its
   constructor), mark it connected, and drive
   handleRelayMessage(RelayConnection, String) directly:
   - closedFrameOnRealRelayPopulatesPerRelayClosedSubIds —
     covers terminal CLOSED → closedSubIds populated; and
     auth-required CLOSED → closedSubIds NOT populated
     (transient).
   - eosedFrameOnRealRelayPopulatesPerRelayEosedSubIds —
     covers EOSE → eosedSubIds populated.

4. Misleading test class Javadocs (both RelayFixesTest and
   RelayFixesE2ETest claimed coverage they didn't actually have).
   Updated to accurately describe which paths each suite exercises
   and to point at the new relay-aware tests for the per-relay
   bookkeeping.

13/13 unit + 5/5 e2e passing.
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.

2 participants