| 1 | package consumer_test |
| 2 | |
| 3 | import ( |
| 4 | "reflect" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/FelineStateMachine/tinyrelay/protocol/nostr" |
| 9 | "github.com/FelineStateMachine/tinyrelay/tinyclient" |
| 10 | "github.com/FelineStateMachine/tinyrelay/tinygit" |
| 11 | ) |
| 12 | |
| 13 | func TestPublicEventRoundTripAndConsumerTypes(t *testing.T) { |
| 14 | e := nostr.Event{CreatedAt: 1, Kind: 1, Content: "hello <world>\u2028" , Tags: [][]string{{"t" , "go" }}} |
| 15 | if err := nostr.Sign(&e, strings.Repeat("0" , 63)+"1" ); err != nil { |
| 16 | t.Fatal(err) |
| 17 | } |
| 18 | raw, err := nostr.Canonical(e) |
| 19 | if err != nil { |
| 20 | t.Fatal(err) |
| 21 | } |
| 22 | parsed, err := nostr.Parse(raw) |
| 23 | if err != nil || !reflect.DeepEqual(parsed, e) { |
| 24 | t.Fatalf("round trip: %#v, %v" , parsed, err) |
| 25 | } |
| 26 | var gitEvent tinygit.Event = parsed |
| 27 | var message tinyclient.RoomMessage = gitEvent |
| 28 | if reflect.TypeOf(message).PkgPath() != "github.com/FelineStateMachine/tinyrelay/protocol/nostr" { |
| 29 | t.Fatalf("public event is owned by %s" , reflect.TypeOf(message).PkgPath()) |
| 30 | } |
| 31 | f, err := nostr.ParseFilter([]byte(`{"#t":["go"],"since":1,"until":1}` )) |
| 32 | if err != nil || !nostr.Matches(f, message) { |
| 33 | t.Fatalf("filter round trip: %#v, %v" , f, err) |
| 34 | } |
| 35 | // Matching is not host visibility policy, even for private feature kinds. |
| 36 | message.Kind, message.Content = 30390, "hello" |
| 37 | if !nostr.Matches(nostr.Filter{Search: "hello" }, message) { |
| 38 | t.Fatal("generic matcher applied host privacy policy" ) |
| 39 | } |
| 40 | } |