-
Notifications
You must be signed in to change notification settings - Fork 24
Add validation tests for key event types #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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")); |
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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")); |
Copilot uses AI. Check for mistakes.
Summary
impl
to exercisevalidate()
onContactListEvent
,ZapRequestEvent
, andTextNoteEvent
Testing
mvn -q verify
ContactListEventValidateTest
: Tests run: 4, Failures: 0ZapRequestEventValidateTest
: Tests run: 6, Failures: 0TextNoteEventValidateTest
: Tests run: 4, Failures: 0https://chatgpt.com/codex/tasks/task_b_688a850853888331a9229ebce247afe0