eventstore tests.
This commit is contained in:
@@ -43,10 +43,8 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
// query
|
||||
w := eventstore.RelayWrapper{Store: db}
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{}))
|
||||
require.Len(t, results, len(allEvents))
|
||||
require.ElementsMatch(t,
|
||||
allEvents,
|
||||
@@ -57,8 +55,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
{
|
||||
for i := 0; i < 10; i++ {
|
||||
since := nostr.Timestamp(i*10 + 1)
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Since: &since})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Since: &since}))
|
||||
require.ElementsMatch(t,
|
||||
allEvents[i:],
|
||||
results,
|
||||
@@ -67,8 +64,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{IDs: []nostr.ID{allEvents[7].ID, allEvents[9].ID}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{IDs: []nostr.ID{allEvents[7].ID, allEvents[9].ID}}))
|
||||
require.Len(t, results, 2)
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[7], allEvents[9]},
|
||||
@@ -77,8 +73,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Kinds: []uint16{1}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Kinds: []uint16{1}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[1], allEvents[3], allEvents[5], allEvents[7], allEvents[9]},
|
||||
results,
|
||||
@@ -86,8 +81,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Kinds: []uint16{9}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Kinds: []uint16{9}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[0], allEvents[2], allEvents[4], allEvents[6], allEvents[8]},
|
||||
results,
|
||||
@@ -96,8 +90,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
|
||||
{
|
||||
pk4 := nostr.GetPublicKey(sk4)
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Authors: []nostr.PubKey{pk4}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Authors: []nostr.PubKey{pk4}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[0], allEvents[3], allEvents[6], allEvents[9]},
|
||||
results,
|
||||
@@ -106,8 +99,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
|
||||
{
|
||||
pk3 := nostr.GetPublicKey(sk3)
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Kinds: []uint16{9}, Authors: []nostr.PubKey{pk3}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Kinds: []uint16{9}, Authors: []nostr.PubKey{pk3}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[2], allEvents[4], allEvents[8]},
|
||||
results,
|
||||
@@ -117,9 +109,8 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
{
|
||||
pk3 := nostr.GetPublicKey(sk3)
|
||||
pk4 := nostr.GetPublicKey(sk4)
|
||||
pk4[1] = 'a'
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Kinds: []uint16{9, 5, 7}, Authors: []nostr.PubKey{pk3, pk4}})
|
||||
require.NoError(t, err)
|
||||
pk4[1] = 9 // this is so it doesn't match
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Kinds: []uint16{9, 5, 7}, Authors: []nostr.PubKey{pk3, pk4}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[0], allEvents[2], allEvents[4], allEvents[6], allEvents[8]},
|
||||
results,
|
||||
@@ -127,8 +118,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Tags: nostr.TagMap{"t": []string{"2", "4", "6"}}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"t": []string{"2", "4", "6"}}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[2], allEvents[4], allEvents[6]},
|
||||
results,
|
||||
@@ -141,8 +131,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
|
||||
// query again
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{}))
|
||||
require.ElementsMatch(t,
|
||||
slices.Concat(allEvents[0:4], allEvents[6:]),
|
||||
results,
|
||||
@@ -150,8 +139,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Tags: nostr.TagMap{"t": []string{"2", "6"}}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"t": []string{"2", "6"}}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[2], allEvents[6]},
|
||||
results,
|
||||
@@ -159,8 +147,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Tags: nostr.TagMap{"e": []string{allEvents[3].Tags[1][1]}}})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"e": []string{allEvents[3].Tags[1][1]}}}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{allEvents[3]},
|
||||
results,
|
||||
@@ -170,8 +157,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
{
|
||||
for i := 0; i < 4; i++ {
|
||||
until := nostr.Timestamp(i*10 + 1)
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{Until: &until})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Until: &until}))
|
||||
|
||||
require.ElementsMatch(t,
|
||||
allEvents[:i],
|
||||
@@ -203,12 +189,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{
|
||||
Tags: nostr.TagMap{"p": []string{p}},
|
||||
Kinds: []uint16{1984},
|
||||
Limit: 2,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"p": []string{p}}, Kinds: []uint16{1984}, Limit: 2}))
|
||||
require.ElementsMatch(t,
|
||||
[]nostr.Event{newEvents[2], newEvents[1]},
|
||||
results,
|
||||
@@ -216,11 +197,7 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{
|
||||
Tags: nostr.TagMap{"p": []string{p}, "t": []string{"x"}},
|
||||
Limit: 4,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"p": []string{p}, "t": []string{"x"}}, Limit: 4}))
|
||||
require.ElementsMatch(t,
|
||||
// the results won't be in canonical time order because this query is too awful, needs a kind
|
||||
[]nostr.Event{newEvents[1]},
|
||||
@@ -229,18 +206,12 @@ func runFirstTestOn(t *testing.T, db eventstore.Store) {
|
||||
}
|
||||
|
||||
{
|
||||
results, err := w.QuerySync(ctx, nostr.Filter{
|
||||
Tags: nostr.TagMap{"p": []string{p, p2}},
|
||||
Kinds: []uint16{1},
|
||||
Limit: 4,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
|
||||
results := slices.Collect(db.QueryEvents(nostr.Filter{Tags: nostr.TagMap{"p": []string{p, p2}}, Kinds: []uint16{1}, Limit: 4}))
|
||||
for _, idx := range []int{5, 6, 7} {
|
||||
require.True(t,
|
||||
slices.ContainsFunc(
|
||||
results,
|
||||
func(evt *nostr.Event) bool { return evt.ID == newEvents[idx].ID },
|
||||
func(evt nostr.Event) bool { return evt.ID == newEvents[idx].ID },
|
||||
),
|
||||
"'p' tag 3 query error")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user