Firehose working

This commit is contained in:
pippellia-btc
2025-05-29 17:05:57 +02:00
parent de56ecd913
commit 768cec8fea
4 changed files with 196 additions and 0 deletions

41
pkg/pipe/pipe_test.go Normal file
View File

@@ -0,0 +1,41 @@
package pipe
import (
"context"
"fmt"
"testing"
"time"
"github.com/nbd-wtf/go-nostr"
)
var (
ctx = context.Background()
pip = "f683e87035f7ad4f44e0b98cfbd9537e16455a92cd38cefc4cb31db7557f5ef2"
)
// Manually change pip's follow list and see if the events gets printed. Works only with `go test`
func TestFirehose(t *testing.T) {
ctx, cancel := context.WithTimeout(ctx, time.Second*20)
defer cancel()
checker := mockChecker{pubkey: pip}
config := FirehoseConfig{Relays: defaultRelays}
Firehose(ctx, config, checker, print)
}
type mockChecker struct {
pubkey string
}
func (c mockChecker) Exists(ctx context.Context, pubkey string) (bool, error) {
return pubkey == c.pubkey, nil
}
func print(e *nostr.Event) error {
fmt.Printf("\nevent ID: %v", e.ID)
fmt.Printf("\nevent pubkey: %v", e.PubKey)
fmt.Printf("\nevent kind: %d\n", e.Kind)
return nil
}