relaypool: add a unique events subscription smoke test

was trying to reproduce the issue described in
https://github.com/nbd-wtf/go-nostr/issues/23

no success in reproducing that specific problem, but i believe the test
can still be useful to help in avoiding regression bugs in the future.
This commit is contained in:
alex
2022-12-26 19:54:37 +01:00
committed by fiatjaf
parent 435579dc75
commit 28663f21f0
3 changed files with 172 additions and 0 deletions

View File

@ -187,6 +187,31 @@ func parseEventMessage(t *testing.T, raw []json.RawMessage) Event {
return event
}
func parseSubscriptionMessage(t *testing.T, raw []json.RawMessage) (subid string, filters []Filter) {
t.Helper()
if len(raw) < 3 {
t.Fatalf("len(raw) = %d; want at least 3", len(raw))
}
var typ string
json.Unmarshal(raw[0], &typ)
if typ != "REQ" {
t.Errorf("typ = %q; want REQ", typ)
}
var id string
if err := json.Unmarshal(raw[1], &id); err != nil {
t.Errorf("json.Unmarshal sub id: %v", err)
}
var ff []Filter
for i, b := range raw[2:] {
var f Filter
if err := json.Unmarshal(b, &f); err != nil {
t.Errorf("json.Unmarshal filter %d: %v", i, err)
}
ff = append(ff, f)
}
return id, ff
}
func testPublishStatus(t *testing.T, ch <-chan Status, want map[Status]bool) {
for stat := range ch {
if !want[stat] {