mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-07-04 12:33:04 +02:00
follow list fetching test and related changes and fixes.
- make BatchedSubManyEose() use a single duplicate id index and use it for replaceable loaders; - fixes parsing follow entry from kind:3 events (and others); - adds a "cause" to most cancelation errors in relay/pool; - remove the inherent cache from dataloader (we have our own hopefully); - increase max frame size we can read from any websocket to 2**18 (262k), which gives over 2000 item lists.
This commit is contained in:
@ -2,13 +2,15 @@ package sdk
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nbd-wtf/go-nostr"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSystemFiatjaf(t *testing.T) {
|
||||
func TestMetadataAndEvents(t *testing.T) {
|
||||
sys := NewSystem()
|
||||
ctx := context.Background()
|
||||
|
||||
@ -33,3 +35,53 @@ func TestSystemFiatjaf(t *testing.T) {
|
||||
require.NotEmpty(t, events[meta.PubKey])
|
||||
require.GreaterOrEqual(t, len(events[meta.PubKey]), 5)
|
||||
}
|
||||
|
||||
func TestFollowListRecursion(t *testing.T) {
|
||||
sys := NewSystem()
|
||||
ctx := context.Background()
|
||||
|
||||
// fetch initial follow list
|
||||
followList := sys.FetchFollowList(ctx, "3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d")
|
||||
fmt.Println("~", len(followList.Items))
|
||||
require.Greater(t, len(followList.Items), 400, "should follow more than 400 accounts")
|
||||
|
||||
// fetch metadata and follow lists for each followed account concurrently
|
||||
type result struct {
|
||||
pubkey string
|
||||
followList GenericList[ProfileRef]
|
||||
metadata ProfileMetadata
|
||||
}
|
||||
|
||||
results := make(chan result)
|
||||
go func() {
|
||||
for _, item := range followList.Items {
|
||||
go func() {
|
||||
fl := sys.FetchFollowList(ctx, item.Pubkey)
|
||||
meta := sys.FetchProfileMetadata(ctx, item.Pubkey)
|
||||
fmt.Println(" ~", item.Pubkey, meta.Name, len(fl.Items))
|
||||
results <- result{item.Pubkey, fl, meta}
|
||||
}()
|
||||
}
|
||||
}()
|
||||
|
||||
// collect results
|
||||
var validAccounts int
|
||||
var accountsWithManyFollows int
|
||||
for i := 0; i < len(followList.Items); i++ {
|
||||
r := <-results
|
||||
|
||||
// skip if metadata has "bot" in name
|
||||
if strings.Contains(strings.ToLower(r.metadata.Name), "bot") {
|
||||
continue
|
||||
}
|
||||
|
||||
validAccounts++
|
||||
if len(r.followList.Items) > 20 {
|
||||
accountsWithManyFollows++
|
||||
}
|
||||
}
|
||||
|
||||
// check if at least 90% of non-bot accounts follow more than 20 accounts
|
||||
ratio := float64(accountsWithManyFollows) / float64(validAccounts)
|
||||
require.Greater(t, ratio, 0.9, "at least 90%% of accounts should follow more than 20 others (actual: %.2f%%)", ratio*100)
|
||||
}
|
||||
|
Reference in New Issue
Block a user