-
Notifications
You must be signed in to change notification settings - Fork 1
/
rpc_client_test.go
80 lines (74 loc) · 1.75 KB
/
rpc_client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package farcaster
import (
"context"
"fmt"
"github.com/alphaticks/go-farcaster/rpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"testing"
)
func TestGetUserData(t *testing.T) {
client, err := NewRPCClient("88.198.26.30:2283", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
res, err := client.GetUserDataByFid(context.Background(), &rpc.FidRequest{Fid: uint64(int64(800000))})
if err != nil {
t.Fatal(err)
}
fmt.Println(res)
res2, err := client.GetCastsByParent(context.Background(), &rpc.CastsByParentRequest{
Parent: nil,
})
if err != nil {
t.Fatal(err)
}
fmt.Println(res2)
}
func TestEvent(t *testing.T) {
client, err := NewRPCClient("88.198.26.30:2283", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
sub, err := client.Subscribe(context.Background(), &rpc.SubscribeRequest{})
if err != nil {
t.Fatal(err)
}
for {
msg, err := sub.Recv()
if err != nil {
t.Fatal(err)
}
fmt.Println(msg.Id)
}
}
func TestRPCClient(t *testing.T) {
/*
creds, err := credentials.NewClientTLSFromFile("/etc/ssl/certs/ca-certificates.crt", "")
if err != nil {
log.Fatalf("Failed to load credentials: %v", err)
}
*/
client, err := NewRPCClient("88.198.26.30:2283", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
res, err := client.GetCastsByFid(context.Background(), &rpc.FidRequest{
Fid: 2,
PageToken: nil,
Reverse: rpc.Bool(true),
})
if err != nil {
t.Fatal(err)
}
fmt.Println(len(res.Messages))
if len(res.Messages) == 0 {
t.Fatal("No messages")
}
it := client.GetCastsByFidIterator(2)
for it.Next() {
for _, msg := range it.Msgs {
fmt.Println(msg)
}
}
}