mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-03-18 05:42:20 +01:00
another event serialization test, now reversed.
This commit is contained in:
parent
4a3aea6d4b
commit
ac25c2071e
@ -3,6 +3,7 @@ package nostr
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEventParsingAndVerifying(t *testing.T) {
|
||||
@ -37,3 +38,50 @@ func TestEventParsingAndVerifying(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventSerialization(t *testing.T) {
|
||||
events := []Event{
|
||||
{
|
||||
ID: "92570b321da503eac8014b23447301eb3d0bbdfbace0d11a4e4072e72bb7205d",
|
||||
PubKey: "e9142f724955c5854de36324dab0434f97b15ec6b33464d56ebe491e3f559d1b",
|
||||
Kind: 4,
|
||||
CreatedAt: time.Unix(1671028682, 0),
|
||||
Tags: Tags{Tag{"p", "f8340b2bde651576b75af61aa26c80e13c65029f00f7f64004eece679bf7059f"}},
|
||||
Content: "you say yes, I say no",
|
||||
Sig: "ed08d2dd5b0f7b6a3cdc74643d4adee3158ddede9cc848e8cd97630c097001acc2d052d2d3ec2b7ac4708b2314b797106d1b3c107322e61b5e5cc2116e099b79",
|
||||
},
|
||||
}
|
||||
|
||||
for _, evt := range events {
|
||||
b, err := json.Marshal(evt)
|
||||
if err != nil {
|
||||
t.Log(evt)
|
||||
t.Error("failed to serialize this event")
|
||||
}
|
||||
|
||||
var re Event
|
||||
if err := json.Unmarshal(b, &re); err != nil {
|
||||
t.Log(string(b))
|
||||
t.Error("failed to re parse event just serialized")
|
||||
}
|
||||
|
||||
if evt.ID != re.ID || evt.PubKey != re.PubKey || evt.Content != re.Content ||
|
||||
!evt.CreatedAt.Equal(re.CreatedAt) || evt.Sig != re.Sig ||
|
||||
len(evt.Tags) != len(evt.Tags) {
|
||||
t.Error("reparsed event differs from original")
|
||||
}
|
||||
|
||||
for i := range evt.Tags {
|
||||
if len(evt.Tags[i]) != len(re.Tags[i]) {
|
||||
t.Errorf("reparsed tags %d length differ from original", i)
|
||||
continue
|
||||
}
|
||||
|
||||
for j := range evt.Tags[i] {
|
||||
if evt.Tags[i][j] != re.Tags[i][j] {
|
||||
t.Errorf("reparsed tag content %d %d length differ from original", i, j)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user