Add validation tests for key event types#225
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds comprehensive unit tests for the validate() method across three key event types: ContactListEvent, ZapRequestEvent, and TextNoteEvent. The tests systematically cover both positive validation scenarios and various failure cases including missing required tags, wrong event kinds, and invalid content.
- Adds validation test coverage for three event types with both success and failure scenarios
- Tests specific validation requirements for each event type (e.g., required tags, content validation)
- Implements systematic test patterns across all event validation test classes
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ContactListEventValidateTest.java | Tests validation for contact list events including P-tag requirements and content validation |
| ZapRequestEventValidateTest.java | Tests validation for zap request events including amount, lnurl, and P-tag requirements |
| TextNoteEventValidateTest.java | Tests validation for text note events with tag and content requirements using reflection |
|
|
||
| private void clearTags(TextNoteEvent event) { | ||
| try { | ||
| Field f = GenericEvent.class.getDeclaredField("tags"); |
There was a problem hiding this comment.
Using reflection to access private fields makes tests brittle and tightly coupled to implementation details. Consider providing a package-private setter method or using a test-specific constructor instead.
| List<BaseTag> tags = new ArrayList<>(); | ||
| tags.add(new PubKeyTag(new PublicKey(HEX_64_B))); | ||
| GenericTag amountTag = new GenericTag("amount"); | ||
| amountTag.addAttribute(new ElementAttribute("amount", "1000")); |
There was a problem hiding this comment.
[nitpick] The attribute key "amount" is duplicated with the tag code. This could be confusing and error-prone. Consider using a different attribute key or adding a comment explaining why both use the same value.
| amountTag.addAttribute(new ElementAttribute("amount", "1000")); | |
| amountTag.addAttribute(new ElementAttribute("amountValue", "1000")); |
| amountTag.addAttribute(new ElementAttribute("amount", "1000")); | ||
| tags.add(amountTag); | ||
| GenericTag lnurlTag = new GenericTag("lnurl"); | ||
| lnurlTag.addAttribute(new ElementAttribute("lnurl", "lnurl-value")); |
There was a problem hiding this comment.
[nitpick] The attribute key "lnurl" is duplicated with the tag code. This could be confusing and error-prone. Consider using a different attribute key or adding a comment explaining why both use the same value.
| lnurlTag.addAttribute(new ElementAttribute("lnurl", "lnurl-value")); | |
| lnurlTag.addAttribute(new ElementAttribute("lnurl_value", "lnurl-value")); |
Summary
implto exercisevalidate()onContactListEvent,ZapRequestEvent, andTextNoteEventTesting
mvn -q verifyContactListEventValidateTest: Tests run: 4, Failures: 0ZapRequestEventValidateTest: Tests run: 6, Failures: 0TextNoteEventValidateTest: Tests run: 4, Failures: 0https://chatgpt.com/codex/tasks/task_b_688a850853888331a9229ebce247afe0