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
FROM message
%s
ORDER BY senderTimestamp %s, pubsubTopic, id
ORDER BY senderTimestamp %s, pubsubTopic, id %s
LIMIT ?`
var conditions []string
@ -291,7 +291,7 @@ func (d *DBStore) Query(query *pb.HistoryQuery) ([]StoredMessage, error) {
orderDirection = "DESC"
}
sqlQuery = fmt.Sprintf(sqlQuery, conditionStr, orderDirection)
sqlQuery = fmt.Sprintf(sqlQuery, conditionStr, orderDirection, orderDirection)
stmt, err := d.db.Prepare(sqlQuery)
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)
if err != nil {
a.log.Error("building multiaddr", zap.Error(err))
reply.Success = false
reply.Error = err.Error()
return nil
return err
}
err = a.node.DialPeerWithMultiAddress(req.Context(), addr)
if err != nil {
a.log.Error("dialing peers", zap.Error(err))
reply.Success = false
reply.Error = err.Error()
return nil
return err
}
}
reply.Success = true
*reply = true
return nil
}

View File

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

View File

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

View File

@ -71,7 +71,7 @@ func TestFilterSubscription(t *testing.T) {
&reply,
)
require.NoError(t, err)
require.True(t, reply.Success)
require.True(t, reply)
err = d.DeleteV1Subscription(
makeRequest(t),
@ -79,7 +79,7 @@ func TestFilterSubscription(t *testing.T) {
&reply,
)
require.NoError(t, err)
require.True(t, reply.Success)
require.True(t, reply)
}
func TestFilterGetV1Messages(t *testing.T) {
@ -111,7 +111,7 @@ func TestFilterGetV1Messages(t *testing.T) {
&reply,
)
require.NoError(t, err)
require.True(t, reply.Success)
require.True(t, reply)
// Wait for the subscription to be started
time.Sleep(1 * time.Second)
@ -122,7 +122,7 @@ func TestFilterGetV1Messages(t *testing.T) {
testTopic,
)
require.NoError(t, err)
require.True(t, reply.Success)
require.True(t, reply)
// Wait for the message to be received
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)
if err != nil {
reply.Error = err.Error()
reply.Success = false
return nil
return err
}
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)
if err != nil {
reply.Error = err.Error()
reply.Success = false
return nil
return err
}
reply.Success = true
*reply = true
return nil
}
@ -177,7 +173,6 @@ func (p *PrivateService) PostV1AsymmetricMessage(req *http.Request, args *Asymme
}
*reply = true
return nil
}

View File

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

View File

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

View File

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

View File

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