add constructor functions with options. update tests.

This commit is contained in:
Jay
2026-05-04 13:41:56 -04:00
parent 29ba275293
commit 48dde86abd
10 changed files with 641 additions and 597 deletions
+12 -14
View File
@@ -7,7 +7,7 @@ import (
)
func TestUnmarshalEventJSON(t *testing.T) {
event := Event{}
event := NewEvent()
json.Unmarshal(testEventJSONBytes, &event)
if err := Validate(event); err != nil {
t.Error("unmarshalled event is invalid")
@@ -22,19 +22,17 @@ func TestMarshalEventJSON(t *testing.T) {
}
func TestEventJSONRoundTrip(t *testing.T) {
event := Event{
ID: "86e856d0527dd08527498cd8afd8a7d296bde37e4757a8921f034f0b344df3ad",
PubKey: testEvent.PubKey,
CreatedAt: testEvent.CreatedAt,
Kind: testEvent.Kind,
Tags: []Tag{
{"a", "value"},
{"b", "value", "optional"},
{"name", "value", "optional", "optional"},
},
Content: testEvent.Content,
Sig: "c05fe02a9c082ff56aad2b16b5347498a21665f02f050ba086dbe6bd593c8cd448505d2831d1c0340acc1793eaf89b7c0cb21bb696c71da6b8d6b857702bb557",
}
event := NewEvent(
WithID("86e856d0527dd08527498cd8afd8a7d296bde37e4757a8921f034f0b344df3ad"),
WithPubKey(testEvent.PubKey),
WithCreatedAt(testEvent.CreatedAt),
WithKind(testEvent.Kind),
WithTag(Tag{"a", "value"}),
WithTag(Tag{"b", "value", "optional"}),
WithTag(Tag{"name", "value", "optional", "optional"}),
WithContent(testEvent.Content),
WithSig("c05fe02a9c082ff56aad2b16b5347498a21665f02f050ba086dbe6bd593c8cd448505d2831d1c0340acc1793eaf89b7c0cb21bb696c71da6b8d6b857702bb557"),
)
expectedJSON := `{"id":"86e856d0527dd08527498cd8afd8a7d296bde37e4757a8921f034f0b344df3ad","pubkey":"cfa87f35acbde29ba1ab3ee42de527b2cad33ac487e80cf2d6405ea0042c8fef","created_at":1760740551,"kind":1,"tags":[["a","value"],["b","value","optional"],["name","value","optional","optional"]],"content":"hello world","sig":"c05fe02a9c082ff56aad2b16b5347498a21665f02f050ba086dbe6bd593c8cd448505d2831d1c0340acc1793eaf89b7c0cb21bb696c71da6b8d6b857702bb557"}`
if err := Validate(event); err != nil {