refactor: use diff logger for waku

This commit is contained in:
Richard Ramos 2022-05-06 15:29:31 -04:00
parent c6c7738c67
commit 7b3c853c15
No known key found for this signature in database
GPG Key ID: BD36D48BC9FFC88C
31 changed files with 104 additions and 93 deletions

View File

@ -1,8 +1,10 @@
# BUILD IMAGE -------------------------------------------------------- # BUILD IMAGE --------------------------------------------------------
FROM golang:1.15-alpine as builder FROM golang:1.16-alpine as builder
# Get build tools and required header files # Get build tools and required header files
RUN apk add --no-cache build-base RUN apk add --no-cache build-base
RUN apk add --no-cache bash
RUN apk add --no-cache git
WORKDIR /app WORKDIR /app
COPY . . COPY . .

View File

@ -173,19 +173,21 @@ func main() {
if enableDiscovery && dnsDiscoveryUrl != "" { if enableDiscovery && dnsDiscoveryUrl != "" {
ui.displayMessage(fmt.Sprintf("attempting DNS discovery with %s", dnsDiscoveryUrl)) ui.displayMessage(fmt.Sprintf("attempting DNS discovery with %s", dnsDiscoveryUrl))
multiaddresses, err := dnsdisc.RetrieveNodes(ctx, dnsDiscoveryUrl, dnsdisc.WithNameserver(dnsDiscoveryNameServer)) nodes, err := dnsdisc.RetrieveNodes(ctx, dnsDiscoveryUrl, dnsdisc.WithNameserver(dnsDiscoveryNameServer))
if err != nil { if err != nil {
ui.displayMessage("DNS discovery error: " + err.Error()) ui.displayMessage("DNS discovery error: " + err.Error())
} else { } else {
for _, m := range multiaddresses { for _, n := range nodes {
go func(ctx context.Context, m multiaddr.Multiaddr) { for _, m := range n.Addresses {
ctx, cancel := context.WithTimeout(ctx, time.Duration(3)*time.Second) go func(ctx context.Context, m multiaddr.Multiaddr) {
defer cancel() ctx, cancel := context.WithTimeout(ctx, time.Duration(3)*time.Second)
err = wakuNode.DialPeerWithMultiAddress(ctx, m) defer cancel()
if err != nil { err = wakuNode.DialPeerWithMultiAddress(ctx, m)
ui.displayMessage("error dialing peer: " + err.Error()) if err != nil {
} ui.displayMessage("error dialing peer: " + err.Error())
}(ctx, m) }
}(ctx, m)
}
} }
} }
} }

View File

@ -5,12 +5,12 @@ import (
"testing" "testing"
"time" "time"
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestStartAndStopMetricsServer(t *testing.T) { func TestStartAndStopMetricsServer(t *testing.T) {
server := NewMetricsServer("0.0.0.0", 9876, tests.Logger()) server := NewMetricsServer("0.0.0.0", 9876, utils.Logger())
go func() { go func() {
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View File

@ -29,7 +29,6 @@ import (
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
rendezvous "github.com/status-im/go-waku-rendezvous" rendezvous "github.com/status-im/go-waku-rendezvous"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/metrics" "github.com/status-im/go-waku/waku/metrics"
"github.com/status-im/go-waku/waku/persistence" "github.com/status-im/go-waku/waku/persistence"
"github.com/status-im/go-waku/waku/persistence/sqlite" "github.com/status-im/go-waku/waku/persistence/sqlite"
@ -102,12 +101,12 @@ func Execute(options Options) {
var metricsServer *metrics.Server var metricsServer *metrics.Server
if options.Metrics.Enable { if options.Metrics.Enable {
metricsServer = metrics.NewMetricsServer(options.Metrics.Address, options.Metrics.Port, tests.Logger()) metricsServer = metrics.NewMetricsServer(options.Metrics.Address, options.Metrics.Port, utils.Logger())
go metricsServer.Start() go metricsServer.Start()
} }
nodeOpts := []node.WakuNodeOption{ nodeOpts := []node.WakuNodeOption{
node.WithLogger(utils.Logger()), node.WithLogger(utils.Logger().Desugar()),
node.WithPrivateKey(prvKey), node.WithPrivateKey(prvKey),
node.WithHostAddress(hostAddr), node.WithHostAddress(hostAddr),
node.WithKeepAlive(time.Duration(options.KeepAlive) * time.Second), node.WithKeepAlive(time.Duration(options.KeepAlive) * time.Second),
@ -183,7 +182,7 @@ func Execute(options Options) {
if options.Store.Enable { if options.Store.Enable {
nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages)) nodeOpts = append(nodeOpts, node.WithWakuStoreAndRetentionPolicy(options.Store.ShouldResume, options.Store.RetentionMaxDaysDuration(), options.Store.RetentionMaxMessages))
if options.UseDB { if options.UseDB {
dbStore, err := persistence.NewDBStore(tests.Logger(), persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration())) dbStore, err := persistence.NewDBStore(utils.Logger(), persistence.WithDB(db), persistence.WithRetentionPolicy(options.Store.RetentionMaxMessages, options.Store.RetentionMaxDaysDuration()))
failOnErr(err, "DBStore") failOnErr(err, "DBStore")
nodeOpts = append(nodeOpts, node.WithMessageProvider(dbStore)) nodeOpts = append(nodeOpts, node.WithMessageProvider(dbStore))
} else { } else {
@ -292,7 +291,7 @@ func Execute(options Options) {
var rpcServer *rpc.WakuRpc var rpcServer *rpc.WakuRpc
if options.RPCServer.Enable { if options.RPCServer.Enable {
rpcServer = rpc.NewWakuRpc(wakuNode, options.RPCServer.Address, options.RPCServer.Port, tests.Logger()) rpcServer = rpc.NewWakuRpc(wakuNode, options.RPCServer.Address, options.RPCServer.Port, utils.Logger())
rpcServer.Start() rpcServer.Start()
} }

View File

@ -8,13 +8,14 @@ import (
_ "github.com/mattn/go-sqlite3" // Blank import to register the sqlite3 driver _ "github.com/mattn/go-sqlite3" // Blank import to register the sqlite3 driver
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func NewMock() *sql.DB { func NewMock() *sql.DB {
db, err := sql.Open("sqlite3", ":memory:") db, err := sql.Open("sqlite3", ":memory:")
if err != nil { if err != nil {
tests.Logger().Fatalf("an error '%s' was not expected when opening a stub database connection", err) utils.Logger().Fatalf("an error '%s' was not expected when opening a stub database connection", err)
} }
return db return db
@ -31,7 +32,7 @@ func createIndex(digest []byte, receiverTime int64) *pb.Index {
func TestDbStore(t *testing.T) { func TestDbStore(t *testing.T) {
db := NewMock() db := NewMock()
option := WithDB(db) option := WithDB(db)
store, err := NewDBStore(tests.Logger(), option) store, err := NewDBStore(utils.Logger(), option)
require.NoError(t, err) require.NoError(t, err)
res, err := store.GetAll() res, err := store.GetAll()
@ -52,7 +53,7 @@ func TestDbStore(t *testing.T) {
func TestStoreRetention(t *testing.T) { func TestStoreRetention(t *testing.T) {
db := NewMock() db := NewMock()
store, err := NewDBStore(tests.Logger(), WithDB(db), WithRetentionPolicy(5, 20*time.Second)) store, err := NewDBStore(utils.Logger(), WithDB(db), WithRetentionPolicy(5, 20*time.Second))
require.NoError(t, err) require.NoError(t, err)
insertTime := time.Now() insertTime := time.Now()
@ -72,7 +73,7 @@ func TestStoreRetention(t *testing.T) {
// This step simulates starting go-waku again from scratch // This step simulates starting go-waku again from scratch
store, err = NewDBStore(tests.Logger(), WithDB(db), WithRetentionPolicy(5, 40*time.Second)) store, err = NewDBStore(utils.Logger(), WithDB(db), WithRetentionPolicy(5, 40*time.Second))
require.NoError(t, err) require.NoError(t, err)
dbResults, err = store.GetAll() dbResults, err = store.GetAll()

View File

@ -170,13 +170,13 @@ func newLocalnode(priv *ecdsa.PrivateKey, ipAddr *net.TCPAddr, udpPort int, waku
if udpPort > 0 && udpPort <= math.MaxUint16 { if udpPort > 0 && udpPort <= math.MaxUint16 {
localnode.Set(enr.UDP(uint16(udpPort))) // lgtm [go/incorrect-integer-conversion] localnode.Set(enr.UDP(uint16(udpPort))) // lgtm [go/incorrect-integer-conversion]
} else { } else {
log.Error("could not set udpPort ", udpPort) log.Error("could not set udpPort ", zap.Int("port", udpPort))
} }
if ipAddr.Port > 0 && ipAddr.Port <= math.MaxUint16 { if ipAddr.Port > 0 && ipAddr.Port <= math.MaxUint16 {
localnode.Set(enr.TCP(uint16(ipAddr.Port))) // lgtm [go/incorrect-integer-conversion] localnode.Set(enr.TCP(uint16(ipAddr.Port))) // lgtm [go/incorrect-integer-conversion]
} else { } else {
log.Error("could not set tcpPort ", ipAddr.Port) log.Error("could not set tcpPort ", zap.Int("port", ipAddr.Port))
} }
if advertiseAddr != nil { if advertiseAddr != nil {

View File

@ -47,19 +47,19 @@ func TestDiscV5(t *testing.T) {
host1, _, prvKey1 := createHost(t) host1, _, prvKey1 := createHost(t)
udpPort1, err := tests.FindFreePort(t, "127.0.0.1", 3) udpPort1, err := tests.FindFreePort(t, "127.0.0.1", 3)
require.NoError(t, err) require.NoError(t, err)
d1, err := NewDiscoveryV5(host1, host1.Addrs(), prvKey1, utils.NewWakuEnrBitfield(true, true, true, true), tests.Logger(), WithUDPPort(udpPort1)) d1, err := NewDiscoveryV5(host1, host1.Addrs(), prvKey1, utils.NewWakuEnrBitfield(true, true, true, true), utils.Logger(), WithUDPPort(udpPort1))
require.NoError(t, err) require.NoError(t, err)
host2, _, prvKey2 := createHost(t) host2, _, prvKey2 := createHost(t)
udpPort2, err := tests.FindFreePort(t, "127.0.0.1", 3) udpPort2, err := tests.FindFreePort(t, "127.0.0.1", 3)
require.NoError(t, err) require.NoError(t, err)
d2, err := NewDiscoveryV5(host2, host2.Addrs(), prvKey2, utils.NewWakuEnrBitfield(true, true, true, true), tests.Logger(), WithUDPPort(udpPort2), WithBootnodes([]*enode.Node{d1.localnode.Node()})) d2, err := NewDiscoveryV5(host2, host2.Addrs(), prvKey2, utils.NewWakuEnrBitfield(true, true, true, true), utils.Logger(), WithUDPPort(udpPort2), WithBootnodes([]*enode.Node{d1.localnode.Node()}))
require.NoError(t, err) require.NoError(t, err)
host3, _, prvKey3 := createHost(t) host3, _, prvKey3 := createHost(t)
udpPort3, err := tests.FindFreePort(t, "127.0.0.1", 3) udpPort3, err := tests.FindFreePort(t, "127.0.0.1", 3)
require.NoError(t, err) require.NoError(t, err)
d3, err := NewDiscoveryV5(host3, host3.Addrs(), prvKey3, utils.NewWakuEnrBitfield(true, true, true, true), tests.Logger(), WithUDPPort(udpPort3), WithBootnodes([]*enode.Node{d2.localnode.Node()})) d3, err := NewDiscoveryV5(host3, host3.Addrs(), prvKey3, utils.NewWakuEnrBitfield(true, true, true, true), utils.Logger(), WithUDPPort(udpPort3), WithBootnodes([]*enode.Node{d2.localnode.Node()}))
require.NoError(t, err) require.NoError(t, err)
defer d1.Stop() defer d1.Stop()

View File

@ -9,7 +9,7 @@ import (
"github.com/libp2p/go-libp2p" "github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/peer" "github.com/libp2p/go-libp2p-core/peer"
"github.com/libp2p/go-libp2p-core/peerstore" "github.com/libp2p/go-libp2p-core/peerstore"
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -37,7 +37,7 @@ func TestKeepAlive(t *testing.T) {
host: host1, host: host1,
ctx: ctx2, ctx: ctx2,
wg: wg, wg: wg,
log: tests.Logger(), log: utils.Logger(),
keepAliveMutex: sync.Mutex{}, keepAliveMutex: sync.Mutex{},
keepAliveFails: make(map[peer.ID]int), keepAliveFails: make(map[peer.ID]int),
} }

View File

@ -89,7 +89,7 @@ type WakuNodeOption func(*WakuNodeParameters) error
// Default options used in the libp2p node // Default options used in the libp2p node
var DefaultWakuNodeOptions = []WakuNodeOption{ var DefaultWakuNodeOptions = []WakuNodeOption{
WithLogger(utils.Logger()), WithLogger(utils.Logger().Desugar()),
WithWakuRelay(), WithWakuRelay(),
} }

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,7 +25,7 @@ func TestFilterOption(t *testing.T) {
params := new(FilterSubscribeParameters) params := new(FilterSubscribeParameters)
params.host = host params.host = host
params.log = tests.Logger() params.log = utils.Logger()
for _, opt := range options { for _, opt := range options {
opt(params) opt(params)

View File

@ -12,6 +12,7 @@ import (
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
v2 "github.com/status-im/go-waku/waku/v2" v2 "github.com/status-im/go-waku/waku/v2"
"github.com/status-im/go-waku/waku/v2/protocol/relay" "github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -22,7 +23,7 @@ func makeWakuRelay(t *testing.T, topic string, broadcaster v2.Broadcaster) (*rel
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
relay, err := relay.NewWakuRelay(context.Background(), host, broadcaster, 0, tests.Logger()) relay, err := relay.NewWakuRelay(context.Background(), host, broadcaster, 0, utils.Logger())
require.NoError(t, err) require.NoError(t, err)
sub, err := relay.SubscribeToTopic(context.Background(), topic) sub, err := relay.SubscribeToTopic(context.Background(), topic)
@ -38,7 +39,7 @@ func makeWakuFilter(t *testing.T) (*WakuFilter, host.Host) {
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
filter, _ := NewWakuFilter(context.Background(), host, false, tests.Logger()) filter, _ := NewWakuFilter(context.Background(), host, false, utils.Logger())
return filter, host return filter, host
} }
@ -68,7 +69,7 @@ func TestWakuFilter(t *testing.T) {
defer node2.Stop() defer node2.Stop()
defer sub2.Unsubscribe() defer sub2.Unsubscribe()
node2Filter, _ := NewWakuFilter(ctx, host2, true, tests.Logger()) node2Filter, _ := NewWakuFilter(ctx, host2, true, utils.Logger())
broadcaster.Register(&testTopic, node2Filter.MsgC) broadcaster.Register(&testTopic, node2Filter.MsgC)
host1.Peerstore().AddAddr(host2.ID(), tests.GetHostAddress(host2), peerstore.PermanentAddrTTL) host1.Peerstore().AddAddr(host2.ID(), tests.GetHostAddress(host2), peerstore.PermanentAddrTTL)
@ -153,7 +154,7 @@ func TestWakuFilterPeerFailure(t *testing.T) {
defer node2.Stop() defer node2.Stop()
defer sub2.Unsubscribe() defer sub2.Unsubscribe()
node2Filter, _ := NewWakuFilter(ctx, host2, true, tests.Logger(), WithTimeout(3*time.Second)) node2Filter, _ := NewWakuFilter(ctx, host2, true, utils.Logger(), WithTimeout(3*time.Second))
broadcaster.Register(&testTopic, node2Filter.MsgC) broadcaster.Register(&testTopic, node2Filter.MsgC)
host1.Peerstore().AddAddr(host2.ID(), tests.GetHostAddress(host2), peerstore.PermanentAddrTTL) host1.Peerstore().AddAddr(host2.ID(), tests.GetHostAddress(host2), peerstore.PermanentAddrTTL)

View File

@ -6,6 +6,7 @@ import (
"testing" "testing"
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -26,7 +27,7 @@ func TestLightPushOption(t *testing.T) {
params := new(LightPushParameters) params := new(LightPushParameters)
params.host = host params.host = host
params.log = tests.Logger() params.log = utils.Logger()
for _, opt := range options { for _, opt := range options {
opt(params) opt(params)

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/go-waku/waku/v2/protocol" "github.com/status-im/go-waku/waku/v2/protocol"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/protocol/relay" "github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -24,7 +25,7 @@ func makeWakuRelay(t *testing.T, topic string) (*relay.WakuRelay, *relay.Subscri
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
relay, err := relay.NewWakuRelay(context.Background(), host, v2.NewBroadcaster(10), 0, tests.Logger()) relay, err := relay.NewWakuRelay(context.Background(), host, v2.NewBroadcaster(10), 0, utils.Logger())
require.NoError(t, err) require.NoError(t, err)
sub, err := relay.SubscribeToTopic(context.Background(), topic) sub, err := relay.SubscribeToTopic(context.Background(), topic)
@ -55,7 +56,7 @@ func TestWakuLightPush(t *testing.T) {
defer sub2.Unsubscribe() defer sub2.Unsubscribe()
ctx := context.Background() ctx := context.Background()
lightPushNode2 := NewWakuLightPush(ctx, host2, node2, tests.Logger()) lightPushNode2 := NewWakuLightPush(ctx, host2, node2, utils.Logger())
err := lightPushNode2.Start() err := lightPushNode2.Start()
require.NoError(t, err) require.NoError(t, err)
defer lightPushNode2.Stop() defer lightPushNode2.Stop()
@ -65,7 +66,7 @@ func TestWakuLightPush(t *testing.T) {
clientHost, err := tests.MakeHost(context.Background(), port, rand.Reader) clientHost, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
client := NewWakuLightPush(ctx, clientHost, nil, tests.Logger()) client := NewWakuLightPush(ctx, clientHost, nil, utils.Logger())
host2.Peerstore().AddAddr(host1.ID(), tests.GetHostAddress(host1), peerstore.PermanentAddrTTL) host2.Peerstore().AddAddr(host1.ID(), tests.GetHostAddress(host1), peerstore.PermanentAddrTTL)
err = host2.Peerstore().AddProtocols(host1.ID(), string(relay.WakuRelayID_v200)) err = host2.Peerstore().AddProtocols(host1.ID(), string(relay.WakuRelayID_v200))
@ -121,7 +122,7 @@ func TestWakuLightPushStartWithoutRelay(t *testing.T) {
clientHost, err := tests.MakeHost(context.Background(), 0, rand.Reader) clientHost, err := tests.MakeHost(context.Background(), 0, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
client := NewWakuLightPush(ctx, clientHost, nil, tests.Logger()) client := NewWakuLightPush(ctx, clientHost, nil, utils.Logger())
err = client.Start() err = client.Start()
require.Errorf(t, err, "relay is required") require.Errorf(t, err, "relay is required")
@ -135,7 +136,7 @@ func TestWakuLightPushNoPeers(t *testing.T) {
clientHost, err := tests.MakeHost(context.Background(), 0, rand.Reader) clientHost, err := tests.MakeHost(context.Background(), 0, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
client := NewWakuLightPush(ctx, clientHost, nil, tests.Logger()) client := NewWakuLightPush(ctx, clientHost, nil, utils.Logger())
_, err = client.PublishToTopic(ctx, tests.CreateWakuMessage("test", 0), testTopic) _, err = client.PublishToTopic(ctx, tests.CreateWakuMessage("test", 0), testTopic)
require.Errorf(t, err, "no suitable remote peers") require.Errorf(t, err, "no suitable remote peers")

View File

@ -7,6 +7,7 @@ import (
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -19,7 +20,7 @@ func TestWakuRelay(t *testing.T) {
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
relay, err := NewWakuRelay(context.Background(), host, nil, 0, tests.Logger()) relay, err := NewWakuRelay(context.Background(), host, nil, 0, utils.Logger())
defer relay.Stop() defer relay.Stop()
require.NoError(t, err) require.NoError(t, err)

View File

@ -10,6 +10,7 @@ import (
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/protocol" "github.com/status-im/go-waku/waku/v2/protocol"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -20,7 +21,7 @@ func TestFindLastSeenMessage(t *testing.T) {
msg4 := protocol.NewEnvelope(tests.CreateWakuMessage("4", 4), "test") msg4 := protocol.NewEnvelope(tests.CreateWakuMessage("4", 4), "test")
msg5 := protocol.NewEnvelope(tests.CreateWakuMessage("5", 5), "test") msg5 := protocol.NewEnvelope(tests.CreateWakuMessage("5", 5), "test")
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(msg1) _ = s.storeMessage(msg1)
_ = s.storeMessage(msg3) _ = s.storeMessage(msg3)
_ = s.storeMessage(msg5) _ = s.storeMessage(msg5)
@ -37,7 +38,7 @@ func TestResume(t *testing.T) {
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(host1, nil, nil, 0, 0, tests.Logger()) s1 := NewWakuStore(host1, nil, nil, 0, 0, utils.Logger())
s1.Start(ctx) s1.Start(ctx)
defer s1.Stop() defer s1.Stop()
@ -55,7 +56,7 @@ func TestResume(t *testing.T) {
host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s2 := NewWakuStore(host2, nil, nil, 0, 0, tests.Logger()) s2 := NewWakuStore(host2, nil, nil, 0, 0, utils.Logger())
s2.Start(ctx) s2.Start(ctx)
defer s2.Stop() defer s2.Stop()
@ -87,7 +88,7 @@ func TestResumeWithListOfPeers(t *testing.T) {
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(host1, nil, nil, 0, 0, tests.Logger()) s1 := NewWakuStore(host1, nil, nil, 0, 0, utils.Logger())
s1.Start(ctx) s1.Start(ctx)
defer s1.Stop() defer s1.Stop()
@ -98,7 +99,7 @@ func TestResumeWithListOfPeers(t *testing.T) {
host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s2 := NewWakuStore(host2, nil, nil, 0, 0, tests.Logger()) s2 := NewWakuStore(host2, nil, nil, 0, 0, utils.Logger())
s2.Start(ctx) s2.Start(ctx)
defer s2.Stop() defer s2.Stop()
@ -120,7 +121,7 @@ func TestResumeWithoutSpecifyingPeer(t *testing.T) {
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(host1, nil, nil, 0, 0, tests.Logger()) s1 := NewWakuStore(host1, nil, nil, 0, 0, utils.Logger())
s1.Start(ctx) s1.Start(ctx)
defer s1.Stop() defer s1.Stop()
@ -131,7 +132,7 @@ func TestResumeWithoutSpecifyingPeer(t *testing.T) {
host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host2, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s2 := NewWakuStore(host2, nil, nil, 0, 0, tests.Logger()) s2 := NewWakuStore(host2, nil, nil, 0, 0, utils.Logger())
s2.Start(ctx) s2.Start(ctx)
defer s2.Stop() defer s2.Stop()

View File

@ -5,7 +5,6 @@ import (
"database/sql" "database/sql"
"testing" "testing"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/persistence" "github.com/status-im/go-waku/waku/persistence"
"github.com/status-im/go-waku/waku/persistence/sqlite" "github.com/status-im/go-waku/waku/persistence/sqlite"
"github.com/status-im/go-waku/waku/v2/protocol" "github.com/status-im/go-waku/waku/v2/protocol"
@ -22,10 +21,10 @@ func TestStorePersistence(t *testing.T) {
db, err := sqlite.NewDB(":memory:") db, err := sqlite.NewDB(":memory:")
require.NoError(t, err) require.NoError(t, err)
dbStore, err := persistence.NewDBStore(tests.Logger(), persistence.WithDB(db)) dbStore, err := persistence.NewDBStore(utils.Logger(), persistence.WithDB(db))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(nil, nil, dbStore, 0, 0, tests.Logger()) s1 := NewWakuStore(nil, nil, dbStore, 0, 0, utils.Logger())
s1.fetchDBRecords(ctx) s1.fetchDBRecords(ctx)
require.Len(t, s1.messageQueue.messages, 0) require.Len(t, s1.messageQueue.messages, 0)
@ -40,7 +39,7 @@ func TestStorePersistence(t *testing.T) {
_ = s1.storeMessage(protocol.NewEnvelope(msg, defaultPubSubTopic)) _ = s1.storeMessage(protocol.NewEnvelope(msg, defaultPubSubTopic))
s2 := NewWakuStore(nil, nil, dbStore, 0, 0, tests.Logger()) s2 := NewWakuStore(nil, nil, dbStore, 0, 0, utils.Logger())
s2.fetchDBRecords(ctx) s2.fetchDBRecords(ctx)
require.Len(t, s2.messageQueue.messages, 1) require.Len(t, s2.messageQueue.messages, 1)
require.Equal(t, msg, s2.messageQueue.messages[0].msg) require.Equal(t, msg, s2.messageQueue.messages[0].msg)

View File

@ -20,7 +20,7 @@ func TestWakuStoreProtocolQuery(t *testing.T) {
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(host1, nil, nil, 0, 0, tests.Logger()) s1 := NewWakuStore(host1, nil, nil, 0, 0, utils.Logger())
s1.Start(ctx) s1.Start(ctx)
defer s1.Stop() defer s1.Stop()
@ -39,7 +39,7 @@ func TestWakuStoreProtocolQuery(t *testing.T) {
// Simulate a message has been received via relay protocol // Simulate a message has been received via relay protocol
s1.MsgC <- protocol.NewEnvelope(msg, pubsubTopic1) s1.MsgC <- protocol.NewEnvelope(msg, pubsubTopic1)
s2 := NewWakuStore(host2, nil, nil, 0, 0, tests.Logger()) s2 := NewWakuStore(host2, nil, nil, 0, 0, utils.Logger())
s2.Start(ctx) s2.Start(ctx)
defer s2.Stop() defer s2.Stop()
@ -66,7 +66,7 @@ func TestWakuStoreProtocolNext(t *testing.T) {
host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0")) host1, err := libp2p.New(libp2p.DefaultTransports, libp2p.ListenAddrStrings("/ip4/0.0.0.0/tcp/0"))
require.NoError(t, err) require.NoError(t, err)
s1 := NewWakuStore(host1, nil, nil, 0, 0, tests.Logger()) s1 := NewWakuStore(host1, nil, nil, 0, 0, utils.Logger())
s1.Start(ctx) s1.Start(ctx)
defer s1.Stop() defer s1.Stop()
@ -92,7 +92,7 @@ func TestWakuStoreProtocolNext(t *testing.T) {
err = host2.Peerstore().AddProtocols(host1.ID(), string(StoreID_v20beta4)) err = host2.Peerstore().AddProtocols(host1.ID(), string(StoreID_v20beta4))
require.NoError(t, err) require.NoError(t, err)
s2 := NewWakuStore(host2, nil, nil, 0, 0, tests.Logger()) s2 := NewWakuStore(host2, nil, nil, 0, 0, utils.Logger())
s2.Start(ctx) s2.Start(ctx)
defer s2.Stop() defer s2.Stop()

View File

@ -17,7 +17,7 @@ func TestStoreQuery(t *testing.T) {
msg1 := tests.CreateWakuMessage(defaultContentTopic, utils.GetUnixEpoch()) msg1 := tests.CreateWakuMessage(defaultContentTopic, utils.GetUnixEpoch())
msg2 := tests.CreateWakuMessage("2", utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage("2", utils.GetUnixEpoch())
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(protocol.NewEnvelope(msg1, defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg1, defaultPubSubTopic))
_ = s.storeMessage(protocol.NewEnvelope(msg2, defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg2, defaultPubSubTopic))
@ -43,7 +43,7 @@ func TestStoreQueryMultipleContentFilters(t *testing.T) {
msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch())
msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch())
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(protocol.NewEnvelope(msg1, defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg1, defaultPubSubTopic))
_ = s.storeMessage(protocol.NewEnvelope(msg2, defaultPubSubTopic)) _ = s.storeMessage(protocol.NewEnvelope(msg2, defaultPubSubTopic))
@ -77,7 +77,7 @@ func TestStoreQueryPubsubTopicFilter(t *testing.T) {
msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch())
msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch())
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic1))
_ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic2))
_ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic2))
@ -109,7 +109,7 @@ func TestStoreQueryPubsubTopicNoMatch(t *testing.T) {
msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch())
msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch())
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic2))
_ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic2))
_ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic2)) _ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic2))
@ -131,7 +131,7 @@ func TestStoreQueryPubsubTopicAllMessages(t *testing.T) {
msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch()) msg2 := tests.CreateWakuMessage(topic2, utils.GetUnixEpoch())
msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch()) msg3 := tests.CreateWakuMessage(topic3, utils.GetUnixEpoch())
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
_ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg1, pubsubTopic1))
_ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg2, pubsubTopic1))
_ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic1)) _ = s.storeMessage(protocol.NewEnvelope(msg3, pubsubTopic1))
@ -150,7 +150,7 @@ func TestStoreQueryForwardPagination(t *testing.T) {
topic1 := "1" topic1 := "1"
pubsubTopic1 := "topic1" pubsubTopic1 := "topic1"
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
msg := tests.CreateWakuMessage(topic1, utils.GetUnixEpoch()) msg := tests.CreateWakuMessage(topic1, utils.GetUnixEpoch())
msg.Payload = []byte{byte(i)} msg.Payload = []byte{byte(i)}
@ -174,7 +174,7 @@ func TestStoreQueryBackwardPagination(t *testing.T) {
topic1 := "1" topic1 := "1"
pubsubTopic1 := "topic1" pubsubTopic1 := "topic1"
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
msg := &pb.WakuMessage{ msg := &pb.WakuMessage{
Payload: []byte{byte(i)}, Payload: []byte{byte(i)},
@ -200,7 +200,7 @@ func TestStoreQueryBackwardPagination(t *testing.T) {
} }
func TestTemporalHistoryQueries(t *testing.T) { func TestTemporalHistoryQueries(t *testing.T) {
s := NewWakuStore(nil, nil, nil, 0, 0, tests.Logger()) s := NewWakuStore(nil, nil, nil, 0, 0, utils.Logger())
var messages []*pb.WakuMessage var messages []*pb.WakuMessage
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {

View File

@ -3,12 +3,12 @@ package swap
import ( import (
"testing" "testing"
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
func TestSwapCreditDebit(t *testing.T) { func TestSwapCreditDebit(t *testing.T) {
swap := NewWakuSwap(tests.Logger(), []SwapOption{ swap := NewWakuSwap(utils.Logger(), []SwapOption{
WithMode(SoftMode), WithMode(SoftMode),
WithThreshold(0, 0), WithThreshold(0, 0),
}...) }...)

View File

@ -39,7 +39,7 @@ func (a *AdminService) PostV1Peers(req *http.Request, args *PeersArgs, reply *Su
for _, peer := range args.Peers { for _, peer := range args.Peers {
addr, err := ma.NewMultiaddr(peer) addr, err := ma.NewMultiaddr(peer)
if err != nil { if err != nil {
a.log.Error("Error building multiaddr", err) a.log.Error("Error building multiaddr", zap.Error(err))
reply.Success = false reply.Success = false
reply.Error = err.Error() reply.Error = err.Error()
return nil return nil
@ -47,7 +47,7 @@ func (a *AdminService) PostV1Peers(req *http.Request, args *PeersArgs, reply *Su
err = a.node.DialPeerWithMultiAddress(req.Context(), addr) err = a.node.DialPeerWithMultiAddress(req.Context(), addr)
if err != nil { if err != nil {
a.log.Error("Error dialing peers", err) a.log.Error("Error dialing peers", zap.Error(err))
reply.Success = false reply.Success = false
reply.Error = err.Error() reply.Error = err.Error()
return nil return nil
@ -65,7 +65,7 @@ func isWakuProtocol(protocol string) bool {
func (a *AdminService) GetV1Peers(req *http.Request, args *GetPeersArgs, reply *PeersReply) error { func (a *AdminService) GetV1Peers(req *http.Request, args *GetPeersArgs, reply *PeersReply) error {
peers, err := a.node.Peers() peers, err := a.node.Peers()
if err != nil { if err != nil {
a.log.Error("Error getting peers", err) a.log.Error("Error getting peers", zap.Error(err))
return nil return nil
} }
for _, peer := range peers { for _, peer := range peers {

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/go-waku/tests" "github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/node" "github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/relay" "github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -23,7 +24,7 @@ func makeAdminService(t *testing.T) *AdminService {
require.NoError(t, err) require.NoError(t, err)
err = n.Start() err = n.Start()
require.NoError(t, err) require.NoError(t, err)
return &AdminService{n, tests.Logger()} return &AdminService{n, utils.Logger()}
} }
func TestV1Peers(t *testing.T) { func TestV1Peers(t *testing.T) {
@ -32,7 +33,7 @@ func TestV1Peers(t *testing.T) {
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
relay, err := relay.NewWakuRelay(context.Background(), host, nil, 0, tests.Logger()) relay, err := relay.NewWakuRelay(context.Background(), host, nil, 0, utils.Logger())
require.NoError(t, err) require.NoError(t, err)
defer relay.Stop() defer relay.Stop()

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/go-waku/waku/v2/protocol/filter" "github.com/status-im/go-waku/waku/v2/protocol/filter"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/protocol/relay" "github.com/status-im/go-waku/waku/v2/protocol/relay"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -28,7 +29,7 @@ func makeFilterService(t *testing.T) *FilterService {
_, err = n.Relay().SubscribeToTopic(context.Background(), testTopic) _, err = n.Relay().SubscribeToTopic(context.Background(), testTopic)
require.NoError(t, err) require.NoError(t, err)
return NewFilterService(n, tests.Logger()) return NewFilterService(n, utils.Logger())
} }
func TestFilterSubscription(t *testing.T) { func TestFilterSubscription(t *testing.T) {
@ -38,13 +39,13 @@ func TestFilterSubscription(t *testing.T) {
host, err := tests.MakeHost(context.Background(), port, rand.Reader) host, err := tests.MakeHost(context.Background(), port, rand.Reader)
require.NoError(t, err) require.NoError(t, err)
node, err := relay.NewWakuRelay(context.Background(), host, v2.NewBroadcaster(10), 0, tests.Logger()) node, err := relay.NewWakuRelay(context.Background(), host, v2.NewBroadcaster(10), 0, utils.Logger())
require.NoError(t, err) require.NoError(t, err)
_, err = node.SubscribeToTopic(context.Background(), testTopic) _, err = node.SubscribeToTopic(context.Background(), testTopic)
require.NoError(t, err) require.NoError(t, err)
_, _ = filter.NewWakuFilter(context.Background(), host, false, tests.Logger()) _, _ = filter.NewWakuFilter(context.Background(), host, false, utils.Logger())
d := makeFilterService(t) d := makeFilterService(t)
defer d.node.Stop() defer d.node.Stop()

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"testing" "testing"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/node" "github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -16,7 +16,7 @@ func makePrivateService(t *testing.T) *PrivateService {
err = n.Start() err = n.Start()
require.NoError(t, err) require.NoError(t, err)
return NewPrivateService(n, tests.Logger()) return NewPrivateService(n, utils.Logger())
} }
func TestGetV1SymmetricKey(t *testing.T) { func TestGetV1SymmetricKey(t *testing.T) {

View File

@ -7,9 +7,9 @@ import (
"time" "time"
"github.com/multiformats/go-multiaddr" "github.com/multiformats/go-multiaddr"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/node" "github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/protocol/pb" "github.com/status-im/go-waku/waku/v2/protocol/pb"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -19,7 +19,7 @@ func makeRelayService(t *testing.T) *RelayService {
require.NoError(t, err) require.NoError(t, err)
err = n.Start() err = n.Start()
require.NoError(t, err) require.NoError(t, err)
return NewRelayService(n, tests.Logger()) return NewRelayService(n, utils.Logger())
} }
func TestPostV1Message(t *testing.T) { func TestPostV1Message(t *testing.T) {

View File

@ -56,7 +56,7 @@ func (s *StoreService) GetV1Messages(req *http.Request, args *StoreMessagesArgs,
options..., options...,
) )
if err != nil { if err != nil {
s.log.Error("Error querying messages:", err) s.log.Error("Error querying messages:", zap.Error(err))
reply.Error = err.Error() reply.Error = err.Error()
return nil return nil
} }

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"testing" "testing"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/node" "github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -15,7 +15,7 @@ func makeStoreService(t *testing.T) *StoreService {
require.NoError(t, err) require.NoError(t, err)
err = n.Start() err = n.Start()
require.NoError(t, err) require.NoError(t, err)
return &StoreService{n, tests.Logger()} return &StoreService{n, utils.Logger()}
} }
func TestStoreGetV1Messages(t *testing.T) { func TestStoreGetV1Messages(t *testing.T) {

View File

@ -41,7 +41,7 @@ func NewWakuRpc(node *node.WakuNode, address string, port int, log *zap.SugaredL
wrpc.log.Error(err) wrpc.log.Error(err)
} }
err = s.RegisterService(&StoreService{node, log.Named("store")}, "Store") err = s.RegisterService(&StoreService{node, log}, "Store")
if err != nil { if err != nil {
wrpc.log.Error(err) wrpc.log.Error(err)
} }

View File

@ -4,8 +4,8 @@ import (
"context" "context"
"testing" "testing"
"github.com/status-im/go-waku/tests"
"github.com/status-im/go-waku/waku/v2/node" "github.com/status-im/go-waku/waku/v2/node"
"github.com/status-im/go-waku/waku/v2/utils"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/require"
) )
@ -14,7 +14,7 @@ func TestWakuRpc(t *testing.T) {
n, err := node.New(context.Background(), options) n, err := node.New(context.Background(), options)
require.NoError(t, err) require.NoError(t, err)
rpc := NewWakuRpc(n, "127.0.0.1", 8080, tests.Logger()) rpc := NewWakuRpc(n, "127.0.0.1", 8080, utils.Logger())
require.NotNil(t, rpc.server) require.NotNil(t, rpc.server)
require.Equal(t, rpc.server.Addr, "127.0.0.1:8080") require.Equal(t, rpc.server.Addr, "127.0.0.1:8080")
} }

View File

@ -20,7 +20,7 @@ func SetLogLevel(level string) error {
} }
// Logger creates a zap.Logger with some reasonable defaults // Logger creates a zap.Logger with some reasonable defaults
func Logger() *zap.Logger { func Logger() *zap.SugaredLogger {
if log == nil { if log == nil {
cfg := zap.Config{ cfg := zap.Config{
Encoding: "console", Encoding: "console",
@ -45,5 +45,5 @@ func Logger() *zap.Logger {
log = logger.Named("gowaku") log = logger.Named("gowaku")
} }
return log return log.Sugar()
} }

View File

@ -29,7 +29,7 @@ func SelectPeer(host host.Host, protocolId string, log *zap.SugaredLogger) (*pee
for _, peer := range host.Peerstore().Peers() { for _, peer := range host.Peerstore().Peers() {
protocols, err := host.Peerstore().SupportsProtocols(peer, protocolId) protocols, err := host.Peerstore().SupportsProtocols(peer, protocolId)
if err != nil { if err != nil {
log.Error("error obtaining the protocols supported by peers", err) log.Error("error obtaining the protocols supported by peers", zap.Error(err))
return nil, err return nil, err
} }
@ -57,7 +57,7 @@ func SelectPeerWithLowestRTT(ctx context.Context, host host.Host, protocolId str
for _, peer := range host.Peerstore().Peers() { for _, peer := range host.Peerstore().Peers() {
protocols, err := host.Peerstore().SupportsProtocols(peer, protocolId) protocols, err := host.Peerstore().SupportsProtocols(peer, protocolId)
if err != nil { if err != nil {
log.Error("error obtaining the protocols supported by peers", err) log.Error("error obtaining the protocols supported by peers", zap.Error(err))
return nil, err return nil, err
} }

View File

@ -33,14 +33,14 @@ func TestSelectPeer(t *testing.T) {
h1.Peerstore().AddAddrs(h3.ID(), h2.Network().ListenAddresses(), peerstore.PermanentAddrTTL) h1.Peerstore().AddAddrs(h3.ID(), h2.Network().ListenAddresses(), peerstore.PermanentAddrTTL)
// No peers with selected protocol // No peers with selected protocol
_, err = SelectPeer(h1, proto, tests.Logger()) _, err = SelectPeer(h1, proto, Logger())
require.Error(t, ErrNoPeersAvailable, err) require.Error(t, ErrNoPeersAvailable, err)
// Peers with selected protocol // Peers with selected protocol
_ = h1.Peerstore().AddProtocols(h2.ID(), proto) _ = h1.Peerstore().AddProtocols(h2.ID(), proto)
_ = h1.Peerstore().AddProtocols(h3.ID(), proto) _ = h1.Peerstore().AddProtocols(h3.ID(), proto)
_, err = SelectPeerWithLowestRTT(ctx, h1, proto, tests.Logger()) _, err = SelectPeerWithLowestRTT(ctx, h1, proto, Logger())
require.NoError(t, err) require.NoError(t, err)
} }
@ -69,13 +69,13 @@ func TestSelectPeerWithLowestRTT(t *testing.T) {
h1.Peerstore().AddAddrs(h3.ID(), h2.Network().ListenAddresses(), peerstore.PermanentAddrTTL) h1.Peerstore().AddAddrs(h3.ID(), h2.Network().ListenAddresses(), peerstore.PermanentAddrTTL)
// No peers with selected protocol // No peers with selected protocol
_, err = SelectPeerWithLowestRTT(ctx, h1, proto, tests.Logger()) _, err = SelectPeerWithLowestRTT(ctx, h1, proto, Logger())
require.Error(t, ErrNoPeersAvailable, err) require.Error(t, ErrNoPeersAvailable, err)
// Peers with selected protocol // Peers with selected protocol
_ = h1.Peerstore().AddProtocols(h2.ID(), proto) _ = h1.Peerstore().AddProtocols(h2.ID(), proto)
_ = h1.Peerstore().AddProtocols(h3.ID(), proto) _ = h1.Peerstore().AddProtocols(h3.ID(), proto)
_, err = SelectPeerWithLowestRTT(ctx, h1, proto, tests.Logger()) _, err = SelectPeerWithLowestRTT(ctx, h1, proto, Logger())
require.NoError(t, err) require.NoError(t, err)
} }