fix: js-waku / nwaku interop - pt2

This commit is contained in:
Richard Ramos 2022-06-14 11:36:34 -04:00
parent b749cf22c0
commit 25c3887342
10 changed files with 37 additions and 55 deletions

View File

@ -221,7 +221,7 @@ func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) {
sqlQuery := `SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version sqlQuery := `SELECT id, receiverTimestamp, senderTimestamp, contentTopic, pubsubTopic, payload, version
FROM message FROM message
%s %s
ORDER BY senderTimestamp %s, pubsubTopic, id ORDER BY senderTimestamp %s, pubsubTopic, id %s
LIMIT ?` LIMIT ?`
var conditions []string var conditions []string
@ -291,7 +291,7 @@ func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) {
orderDirection = "DESC" orderDirection = "DESC"
} }
sqlQuery = fmt.Sprintf(sqlQuery, conditionStr, orderDirection) sqlQuery = fmt.Sprintf(sqlQuery, conditionStr, orderDirection, orderDirection)
stmt, err := d.db.Prepare(sqlQuery) stmt, err := d.db.Prepare(sqlQuery)
if err != nil { if err != nil {

View File

@ -40,21 +40,17 @@ func (a *AdminService) PostV1Peers(req *http.Request, args *PeersArgs, reply *Su
addr, err := ma.NewMultiaddr(peer) addr, err := ma.NewMultiaddr(peer)
if err != nil { if err != nil {
a.log.Error("building multiaddr", zap.Error(err)) a.log.Error("building multiaddr", zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
err = a.node.DialPeerWithMultiAddress(req.Context(), addr) err = a.node.DialPeerWithMultiAddress(req.Context(), addr)
if err != nil { if err != nil {
a.log.Error("dialing peers", zap.Error(err)) a.log.Error("dialing peers", zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
} }
reply.Success = true *reply = true
return nil return nil
} }

View File

@ -60,7 +60,7 @@ func TestV1Peers(t *testing.T) {
} }
err = a.PostV1Peers(request, &PeersArgs{Peers: []string{addr.String()}}, &reply2) err = a.PostV1Peers(request, &PeersArgs{Peers: []string{addr.String()}}, &reply2)
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply2.Success) require.True(t, reply2)
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)

View File

@ -81,14 +81,13 @@ func (f *FilterService) PostV1Subscription(req *http.Request, args *FilterConten
) )
if err != nil { if err != nil {
f.log.Error("subscribing to topic", zap.String("topic", args.Topic), zap.Error(err)) f.log.Error("subscribing to topic", zap.String("topic", args.Topic), zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
for _, contentFilter := range args.ContentFilters { for _, contentFilter := range args.ContentFilters {
f.messages[contentFilter.ContentTopic] = make([]*pb.WakuMessage, 0) f.messages[contentFilter.ContentTopic] = make([]*pb.WakuMessage, 0)
} }
reply.Success = true
*reply = true
return nil return nil
} }
@ -99,15 +98,13 @@ func (f *FilterService) DeleteV1Subscription(req *http.Request, args *FilterCont
) )
if err != nil { if err != nil {
f.log.Error("unsubscribing from topic", zap.String("topic", args.Topic), zap.Error(err)) f.log.Error("unsubscribing from topic", zap.String("topic", args.Topic), zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
for _, contentFilter := range args.ContentFilters { for _, contentFilter := range args.ContentFilters {
delete(f.messages, contentFilter.ContentTopic) delete(f.messages, contentFilter.ContentTopic)
} }
reply.Success = true *reply = true
return nil return nil
} }

View File

@ -71,7 +71,7 @@ func TestFilterSubscription(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
err = d.DeleteV1Subscription( err = d.DeleteV1Subscription(
makeRequest(t), makeRequest(t),
@ -79,7 +79,7 @@ func TestFilterSubscription(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
} }
func TestFilterGetV1Messages(t *testing.T) { func TestFilterGetV1Messages(t *testing.T) {
@ -111,7 +111,7 @@ func TestFilterGetV1Messages(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
// Wait for the subscription to be started // Wait for the subscription to be started
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
@ -122,7 +122,7 @@ func TestFilterGetV1Messages(t *testing.T) {
testTopic, testTopic,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
// Wait for the message to be received // Wait for the message to be received
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View File

@ -121,9 +121,7 @@ func (p *PrivateService) PostV1SymmetricMessage(req *http.Request, args *Symmetr
err = node.EncodeWakuMessage(msg, keyInfo) err = node.EncodeWakuMessage(msg, keyInfo)
if err != nil { if err != nil {
reply.Error = err.Error() return err
reply.Success = false
return nil
} }
topic := args.Topic topic := args.Topic
@ -133,12 +131,10 @@ func (p *PrivateService) PostV1SymmetricMessage(req *http.Request, args *Symmetr
_, err = p.node.Relay().PublishToTopic(req.Context(), msg, topic) _, err = p.node.Relay().PublishToTopic(req.Context(), msg, topic)
if err != nil { if err != nil {
reply.Error = err.Error() return err
reply.Success = false
return nil
} }
reply.Success = true *reply = true
return nil return nil
} }
@ -177,7 +173,6 @@ func (p *PrivateService) PostV1AsymmetricMessage(req *http.Request, args *Asymme
} }
*reply = true *reply = true
return nil return nil
} }

View File

@ -65,7 +65,7 @@ func TestPostV1SymmetricMessage(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
} }
func TestPostV1AsymmetricMessage(t *testing.T) { func TestPostV1AsymmetricMessage(t *testing.T) {
@ -106,7 +106,7 @@ func TestGetV1SymmetricMessages(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
time.Sleep(500 * time.Millisecond) time.Sleep(500 * time.Millisecond)

View File

@ -85,11 +85,10 @@ func (r *RelayService) PostV1Message(req *http.Request, args *RelayMessageArgs,
} }
if err != nil { if err != nil {
r.log.Error("publishing message", zap.Error(err)) r.log.Error("publishing message", zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
} else {
reply.Success = true
} }
*reply = true
return nil return nil
} }
@ -108,13 +107,12 @@ func (r *RelayService) PostV1Subscription(req *http.Request, args *TopicsArgs, r
} }
if err != nil { if err != nil {
r.log.Error("subscribing to topic", zap.String("topic", topic), zap.Error(err)) r.log.Error("subscribing to topic", zap.String("topic", topic), zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
r.messages[topic] = make([]*pb.WakuMessage, 0) r.messages[topic] = make([]*pb.WakuMessage, 0)
} }
reply.Success = true
*reply = true
return nil return nil
} }
@ -124,14 +122,13 @@ func (r *RelayService) DeleteV1Subscription(req *http.Request, args *TopicsArgs,
err := r.node.Relay().Unsubscribe(ctx, topic) err := r.node.Relay().Unsubscribe(ctx, topic)
if err != nil { if err != nil {
r.log.Error("unsubscribing from topic", zap.String("topic", topic), zap.Error(err)) r.log.Error("unsubscribing from topic", zap.String("topic", topic), zap.Error(err))
reply.Success = false return err
reply.Error = err.Error()
return nil
} }
delete(r.messages, topic) delete(r.messages, topic)
} }
reply.Success = true
*reply = true
return nil return nil
} }

View File

@ -32,7 +32,7 @@ func TestPostV1Message(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
} }
func TestRelaySubscription(t *testing.T) { func TestRelaySubscription(t *testing.T) {
@ -47,7 +47,7 @@ func TestRelaySubscription(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
err = d.DeleteV1Subscription( err = d.DeleteV1Subscription(
makeRequest(t), makeRequest(t),
@ -55,7 +55,7 @@ func TestRelaySubscription(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
} }
func TestRelayGetV1Messages(t *testing.T) { func TestRelayGetV1Messages(t *testing.T) {
@ -87,7 +87,7 @@ func TestRelayGetV1Messages(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
// Wait for the subscription to be started // Wait for the subscription to be started
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
@ -103,7 +103,7 @@ func TestRelayGetV1Messages(t *testing.T) {
&reply, &reply,
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, reply.Success) require.True(t, reply)
// Wait for the message to be received // Wait for the message to be received
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View File

@ -1,13 +1,10 @@
package rpc package rpc
type SuccessReply struct { type SuccessReply = bool
Success bool `json:"success,omitempty"`
Error string `json:"error,omitempty"`
}
type Empty struct { type Empty struct {
} }
type MessagesReply []*RPCWakuMessage type MessagesReply = []*RPCWakuMessage
type RelayMessagesReply []*RPCWakuRelayMessage type RelayMessagesReply = []*RPCWakuRelayMessage