graph_test.go raw

   1  package nostr
   2  
   3  import "testing"
   4  
   5  func TestGraphResultContent(t *testing.T) {
   6  	r := NewGraphResult()
   7  	r.AddPubkeyAtDepth("bb", 1)
   8  	r.AddPubkeyAtDepth("aa", 1)
   9  	r.AddPubkeyAtDepth("aa", 2) // duplicate at a later depth is ignored
  10  	r.AddPubkeyAtDepth("cc", 3)
  11  	r.Sort()
  12  	got := string(r.AppendContentJSON(nil))
  13  	want := `{"pubkeys_by_depth":[["aa","bb"],[],["cc"]],"total_pubkeys":3}`
  14  	if got != want {
  15  		t.Fatalf("content:\n got %s\nwant %s", got, want)
  16  	}
  17  
  18  	e := NewGraphResult()
  19  	e.AddEventAtDepth("dd", 1)
  20  	e.AddEventAtDepth("ee", 2)
  21  	e.Sort()
  22  	got = string(e.AppendContentJSON(nil))
  23  	want = `{"events_by_depth":[["dd"],["ee"]],"total_events":2}`
  24  	if got != want {
  25  		t.Fatalf("content:\n got %s\nwant %s", got, want)
  26  	}
  27  }
  28