Skip to content

Conversation

tcheeric
Copy link
Owner

@tcheeric tcheeric commented Aug 9, 2025

Summary

  • add tests for hex string validation, Nostr utilities and NIP-05 validator
  • ensure validator handles invalid local parts and domains, and public key extraction
  • cover additional utility methods for integer conversion, hashing, XOR and JSON escaping

Testing

  • mvn -q verify -pl nostr-java-util
  • mvn -q verify (fails: Coverage checks have not been met for module nostr-java-base)

https://chatgpt.com/codex/tasks/task_b_6896bba1911483319469c33966735aee

Copy link
Contributor

@Copilot 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

This PR adds comprehensive test coverage for utility modules including hex string validation, Nostr utilities, and NIP-05 validator functionality. The changes focus on testing error conditions and edge cases to improve code coverage.

  • Add tests for hex string validation covering valid/invalid characters and length mismatches
  • Add tests for NIP-05 validator covering invalid local parts, unknown domains, and public key extraction via reflection
  • Add tests for NostrUtil methods including integer conversion, hashing, XOR operations, and JSON escaping

Reviewed Changes

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

File Description
nostr-java-util/src/test/java/nostr/util/validator/Nip05ValidatorTest.java Tests NIP-05 validation error cases and private method access via reflection
nostr-java-util/src/test/java/nostr/util/validator/HexStringValidatorTest.java Tests hex string validation for various invalid inputs and edge cases
nostr-java-util/src/test/java/nostr/util/NostrUtilExtendedTest.java Tests utility methods for data conversion, hashing, and string manipulation

assertEquals("abc", result);
String missing = (String) m.invoke(validator, new StringBuilder(json), "bob");
assertNull(missing);
}
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

Testing private methods via reflection breaks encapsulation and makes tests brittle to internal implementation changes. Consider testing the public API behavior instead or making the method package-private with a @VisibleForTesting annotation if direct testing is necessary.

Suggested change
}

Copilot uses AI. Check for mistakes.


@Test
public void testHexLengthConversions() {
String hex128 = "a".repeat(128);
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 128 should be extracted to a named constant to clarify its significance and improve maintainability.

Suggested change
String hex128 = "a".repeat(128);
String hex128 = "a".repeat(HEX_128_LENGTH);

Copilot uses AI. Check for mistakes.

String hex128 = "a".repeat(128);
assertEquals(64, NostrUtil.hex128ToBytes(hex128).length);

String nip04 = "a".repeat(66);
Copy link
Preview

Copilot AI Aug 9, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 66 should be extracted to a named constant to clarify its significance and improve maintainability.

Suggested change
String nip04 = "a".repeat(66);
String nip04 = "a".repeat(NIP04_PUBKEY_HEX_LENGTH);

Copilot uses AI. Check for mistakes.

@tcheeric tcheeric merged commit d1871a7 into develop Aug 9, 2025
1 check failed
@tcheeric tcheeric deleted the codex/fix-coverage-checks-in-nostr-java-util branch August 9, 2025 03:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant