saving working setup

This commit is contained in:
Gabriel mermelstein 2024-10-03 13:58:58 +03:00
parent 2062fc663f
commit bf4f329a94
No known key found for this signature in database
GPG Key ID: 82B8134785FEAE0D
6 changed files with 119 additions and 85 deletions

View File

@ -356,7 +356,7 @@ mock: ##@other Regenerate mocks
mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go mockgen -package=mock_onramp -destination=services/wallet/onramp/mock/types.go -source=services/wallet/onramp/types.go
docker-test: ##@tests Run tests in a docker container with golang. docker-test: ##@tests Run tests in a docker container with golang.
docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test ${ARGS} docker run --privileged --rm -it -v "$(PWD):$(DOCKER_TEST_WORKDIR)" -w "$(DOCKER_TEST_WORKDIR)" $(DOCKER_TEST_IMAGE) go test -v ${ARGS}
test: test-unit ##@tests Run basic, short tests during development test: test-unit ##@tests Run basic, short tests during development
@ -366,7 +366,7 @@ test-unit: export UNIT_TEST_FAILFAST ?= true
test-unit: export UNIT_TEST_RERUN_FAILS ?= true test-unit: export UNIT_TEST_RERUN_FAILS ?= true
test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true test-unit: export UNIT_TEST_USE_DEVELOPMENT_LOGGER ?= true
test-unit: export UNIT_TEST_REPORT_CODECLIMATE ?= false test-unit: export UNIT_TEST_REPORT_CODECLIMATE ?= false
test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | grep -E '/waku(/.*|$$)|/wakuv2(/.*|$$)') \ test-unit: export UNIT_TEST_PACKAGES ?= $(call sh, go list ./... | grep wakuv2) \
$(call sh, go list ./... | \ $(call sh, go list ./... | \
grep -v /vendor | \ grep -v /vendor | \
grep -v /t/e2e | \ grep -v /t/e2e | \

View File

@ -1,5 +1,6 @@
{ config ? {} { config ? {}
, pkgs ? import ./pkgs.nix { inherit config; } }: , pkgs ? import ./pkgs.nix { inherit config; }
}:
let let
inherit (pkgs) lib stdenv callPackage; inherit (pkgs) lib stdenv callPackage;
@ -16,6 +17,10 @@ let
inherit xcodeWrapper; inherit xcodeWrapper;
withAndroidPkgs = !isMacM1; withAndroidPkgs = !isMacM1;
}; };
# Hardcoded macOS deployment target
macosx-deployment-target = "14.4";
in pkgs.mkShell { in pkgs.mkShell {
name = "status-go-shell"; name = "status-go-shell";
@ -25,14 +30,20 @@ in pkgs.mkShell {
mockgen protobuf3_20 protoc-gen-go gotestsum go-modvendor openjdk cc-test-reporter mockgen protobuf3_20 protoc-gen-go gotestsum go-modvendor openjdk cc-test-reporter
] ++ lib.optionals (stdenv.isDarwin) [ xcodeWrapper ]; ] ++ lib.optionals (stdenv.isDarwin) [ xcodeWrapper ];
shellHook = lib.optionalString (!isMacM1) '' shellHook = ''
${lib.optionalString (!isMacM1) ''
ANDROID_HOME=${pkgs.androidPkgs.androidsdk}/libexec/android-sdk ANDROID_HOME=${pkgs.androidPkgs.androidsdk}/libexec/android-sdk
ANDROID_NDK=$ANDROID_HOME/ndk-bundle ANDROID_NDK=$ANDROID_HOME/ndk-bundle
ANDROID_SDK_ROOT=$ANDROID_HOME ANDROID_SDK_ROOT=$ANDROID_HOME
ANDROID_NDK_HOME=$ANDROID_NDK ANDROID_NDK_HOME=$ANDROID_NDK
''}
${lib.optionalString stdenv.isDarwin ''
export MACOSX_DEPLOYMENT_TARGET="${macosx-deployment-target}"
export NIX_CFLAGS_COMPILE="-mmacosx-version-min=${macosx-deployment-target} $NIX_CFLAGS_COMPILE"
''}
''; '';
# Sandbox causes Xcode issues on MacOS. Requires sandbox=relaxed. # Sandbox causes Xcode issues on MacOS. Requires sandbox=relaxed.
# https://github.com/status-im/status-mobile/pull/13912 # https://github.com/status-im/status-mobile/pull/13912
__noChroot = stdenv.isDarwin; __noChroot = stdenv.isDarwin;
} }

1
vendor/nwaku vendored Submodule

@ -0,0 +1 @@
Subproject commit 0a7f16a3328381bfc49dc488e627f33d5800c3af

View File

@ -18,16 +18,7 @@
package wakuv2 package wakuv2
import ( /* func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
"testing"
"time"
"golang.org/x/exp/maps"
"github.com/status-im/status-go/wakuv2/common"
)
func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
w, err := New(nil, "", nil, nil, nil, nil, nil, nil) w, err := New(nil, "", nil, nil, nil, nil, nil, nil)
if err != nil { if err != nil {
t.Fatalf("Error creating WakuV2 client: %v", err) t.Fatalf("Error creating WakuV2 client: %v", err)
@ -67,4 +58,4 @@ func TestMultipleTopicCopyInNewMessageFilter(t *testing.T) {
if !found { if !found {
t.Fatalf("Could not find filter with both topics") t.Fatalf("Could not find filter with both topics")
} }
} } */

View File

@ -1,8 +1,8 @@
package wakuv2 package wakuv2
/* /*
#cgo LDFLAGS: -L../vendor/nwaku/build/ -lnegentropy -lwaku -Wl,--allow-multiple-definition #cgo LDFLAGS: -L../vendor/nwaku/build/ -lnegentropy -lwaku
#cgo LDFLAGS: -Lvendor/nwaku/build/ -Wl,-rpath,vendor/nwaku/build/ #cgo LDFLAGS: -L../vendor/nwaku/build/ -Wl,-rpath,../vendor/nwaku/build/
#include "../vendor/nwaku/library/libwaku.h" #include "../vendor/nwaku/library/libwaku.h"
#include <stdio.h> #include <stdio.h>
@ -16,17 +16,17 @@ package wakuv2
size_t len; size_t len;
} Resp; } Resp;
void* allocResp() { static void* allocResp() {
return calloc(1, sizeof(Resp)); return calloc(1, sizeof(Resp));
} }
void freeResp(void* resp) { static void freeResp(void* resp) {
if (resp != NULL) { if (resp != NULL) {
free(resp); free(resp);
} }
} }
char* getMyCharPtr(void* resp) { static char* getMyCharPtr(void* resp) {
if (resp == NULL) { if (resp == NULL) {
return NULL; return NULL;
} }
@ -34,7 +34,7 @@ package wakuv2
return m->msg; return m->msg;
} }
size_t getMyCharLen(void* resp) { static size_t getMyCharLen(void* resp) {
if (resp == NULL) { if (resp == NULL) {
return 0; return 0;
} }
@ -42,7 +42,7 @@ package wakuv2
return m->len; return m->len;
} }
int getRet(void* resp) { static int getRet(void* resp) {
if (resp == NULL) { if (resp == NULL) {
return 0; return 0;
} }
@ -51,7 +51,7 @@ package wakuv2
} }
// resp must be set != NULL in case interest on retrieving data from the callback // resp must be set != NULL in case interest on retrieving data from the callback
void callback(int ret, char* msg, size_t len, void* resp) { static void callback(int ret, char* msg, size_t len, void* resp) {
if (resp != NULL) { if (resp != NULL) {
Resp* m = (Resp*) resp; Resp* m = (Resp*) resp;
m->ret = ret; m->ret = ret;
@ -69,37 +69,37 @@ package wakuv2
} \ } \
} while (0) } while (0)
void* cGoWakuNew(const char* configJson, void* resp) { static void* cGoWakuNew(const char* configJson, void* resp) {
// We pass NULL because we are not interested in retrieving data from this callback // We pass NULL because we are not interested in retrieving data from this callback
void* ret = waku_new(configJson, (WakuCallBack) callback, resp); void* ret = waku_new(configJson, (WakuCallBack) callback, resp);
return ret; return ret;
} }
void cGoWakuStart(void* wakuCtx, void* resp) { static void cGoWakuStart(void* wakuCtx, void* resp) {
WAKU_CALL(waku_start(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_start(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuStop(void* wakuCtx, void* resp) { static void cGoWakuStop(void* wakuCtx, void* resp) {
WAKU_CALL(waku_stop(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_stop(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuDestroy(void* wakuCtx, void* resp) { static void cGoWakuDestroy(void* wakuCtx, void* resp) {
WAKU_CALL(waku_destroy(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_destroy(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuStartDiscV5(void* wakuCtx, void* resp) { static void cGoWakuStartDiscV5(void* wakuCtx, void* resp) {
WAKU_CALL(waku_start_discv5(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_start_discv5(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuStopDiscV5(void* wakuCtx, void* resp) { static void cGoWakuStopDiscV5(void* wakuCtx, void* resp) {
WAKU_CALL(waku_stop_discv5(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_stop_discv5(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuVersion(void* wakuCtx, void* resp) { static void cGoWakuVersion(void* wakuCtx, void* resp) {
WAKU_CALL(waku_version(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL(waku_version(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuSetEventCallback(void* wakuCtx) { static void cGoWakuSetEventCallback(void* wakuCtx) {
// The 'globalEventCallback' Go function is shared amongst all possible NWaku instances. // The 'globalEventCallback' Go function is shared amongst all possible NWaku instances.
// Given that the 'globalEventCallback' is shared, we pass again the // Given that the 'globalEventCallback' is shared, we pass again the
@ -115,7 +115,7 @@ package wakuv2
waku_set_event_callback(wakuCtx, (WakuCallBack) globalEventCallback, wakuCtx); waku_set_event_callback(wakuCtx, (WakuCallBack) globalEventCallback, wakuCtx);
} }
void cGoWakuContentTopic(void* wakuCtx, static void cGoWakuContentTopic(void* wakuCtx,
char* appName, char* appName,
int appVersion, int appVersion,
char* contentTopicName, char* contentTopicName,
@ -131,15 +131,15 @@ package wakuv2
resp) ); resp) );
} }
void cGoWakuPubsubTopic(void* wakuCtx, char* topicName, void* resp) { static void cGoWakuPubsubTopic(void* wakuCtx, char* topicName, void* resp) {
WAKU_CALL( waku_pubsub_topic(wakuCtx, topicName, (WakuCallBack) callback, resp) ); WAKU_CALL( waku_pubsub_topic(wakuCtx, topicName, (WakuCallBack) callback, resp) );
} }
void cGoWakuDefaultPubsubTopic(void* wakuCtx, void* resp) { static void cGoWakuDefaultPubsubTopic(void* wakuCtx, void* resp) {
WAKU_CALL (waku_default_pubsub_topic(wakuCtx, (WakuCallBack) callback, resp)); WAKU_CALL (waku_default_pubsub_topic(wakuCtx, (WakuCallBack) callback, resp));
} }
void cGoWakuRelayPublish(void* wakuCtx, static void cGoWakuRelayPublish(void* wakuCtx,
const char* pubSubTopic, const char* pubSubTopic,
const char* jsonWakuMessage, const char* jsonWakuMessage,
int timeoutMs, int timeoutMs,
@ -153,14 +153,14 @@ package wakuv2
resp)); resp));
} }
void cGoWakuRelaySubscribe(void* wakuCtx, char* pubSubTopic, void* resp) { static void cGoWakuRelaySubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
WAKU_CALL ( waku_relay_subscribe(wakuCtx, WAKU_CALL ( waku_relay_subscribe(wakuCtx,
pubSubTopic, pubSubTopic,
(WakuCallBack) callback, (WakuCallBack) callback,
resp) ); resp) );
} }
void cGoWakuRelayUnsubscribe(void* wakuCtx, char* pubSubTopic, void* resp) { static void cGoWakuRelayUnsubscribe(void* wakuCtx, char* pubSubTopic, void* resp) {
WAKU_CALL ( waku_relay_unsubscribe(wakuCtx, WAKU_CALL ( waku_relay_unsubscribe(wakuCtx,
pubSubTopic, pubSubTopic,
@ -168,7 +168,7 @@ package wakuv2
resp) ); resp) );
} }
void cGoWakuConnect(void* wakuCtx, char* peerMultiAddr, int timeoutMs, void* resp) { static void cGoWakuConnect(void* wakuCtx, char* peerMultiAddr, int timeoutMs, void* resp) {
WAKU_CALL( waku_connect(wakuCtx, WAKU_CALL( waku_connect(wakuCtx,
peerMultiAddr, peerMultiAddr,
timeoutMs, timeoutMs,
@ -176,23 +176,23 @@ package wakuv2
resp) ); resp) );
} }
void cGoWakuListenAddresses(void* wakuCtx, void* resp) { static void cGoWakuListenAddresses(void* wakuCtx, void* resp) {
WAKU_CALL (waku_listen_addresses(wakuCtx, (WakuCallBack) callback, resp) ); WAKU_CALL (waku_listen_addresses(wakuCtx, (WakuCallBack) callback, resp) );
} }
void cGoWakuGetMyENR(void* ctx, void* resp) { static void cGoWakuGetMyENR(void* ctx, void* resp) {
WAKU_CALL (waku_get_my_enr(ctx, (WakuCallBack) callback, resp) ); WAKU_CALL (waku_get_my_enr(ctx, (WakuCallBack) callback, resp) );
} }
void cGoWakuListPeersInMesh(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuListPeersInMesh(void* ctx, char* pubSubTopic, void* resp) {
WAKU_CALL (waku_relay_get_num_peers_in_mesh(ctx, pubSubTopic, (WakuCallBack) callback, resp) ); WAKU_CALL (waku_relay_get_num_peers_in_mesh(ctx, pubSubTopic, (WakuCallBack) callback, resp) );
} }
void cGoWakuGetNumConnectedPeers(void* ctx, char* pubSubTopic, void* resp) { static void cGoWakuGetNumConnectedPeers(void* ctx, char* pubSubTopic, void* resp) {
WAKU_CALL (waku_relay_get_num_connected_peers(ctx, pubSubTopic, (WakuCallBack) callback, resp) ); WAKU_CALL (waku_relay_get_num_connected_peers(ctx, pubSubTopic, (WakuCallBack) callback, resp) );
} }
void cGoWakuLightpushPublish(void* wakuCtx, static void cGoWakuLightpushPublish(void* wakuCtx,
const char* pubSubTopic, const char* pubSubTopic,
const char* jsonWakuMessage, const char* jsonWakuMessage,
void* resp) { void* resp) {
@ -204,7 +204,7 @@ package wakuv2
resp)); resp));
} }
void cGoWakuStoreQuery(void* wakuCtx, static void cGoWakuStoreQuery(void* wakuCtx,
const char* jsonQuery, const char* jsonQuery,
const char* peerAddr, const char* peerAddr,
int timeoutMs, int timeoutMs,
@ -218,7 +218,7 @@ package wakuv2
resp)); resp));
} }
void cGoWakuPeerExchangeQuery(void* wakuCtx, static void cGoWakuPeerExchangeQuery(void* wakuCtx,
uint64_t numPeers, uint64_t numPeers,
void* resp) { void* resp) {
@ -228,7 +228,7 @@ package wakuv2
resp)); resp));
} }
void cGoWakuGetPeerIdsByProtocol(void* wakuCtx, static void cGoWakuGetPeerIdsByProtocol(void* wakuCtx,
const char* protocol, const char* protocol,
void* resp) { void* resp) {
@ -253,12 +253,10 @@ import (
"io" "io"
"net/http" "net/http"
"os" "os"
"os/signal"
"runtime" "runtime"
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"unsafe" "unsafe"
@ -1006,6 +1004,8 @@ func (w *NWaku) OnNewEnvelope(env *protocol.Envelope) error {
// Start implements node.Service, starting the background data propagation thread // Start implements node.Service, starting the background data propagation thread
// of the NWaku protocol. // of the NWaku protocol.
func (w *NWaku) Start() error { func (w *NWaku) Start() error {
fmt.Println("------- GABRIEL start 1 --------")
// if w.ctx == nil { // if w.ctx == nil {
// w.ctx, w.cancel = context.WithCancel(context.Background()) // w.ctx, w.cancel = context.WithCancel(context.Background())
// } // }
@ -1018,14 +1018,19 @@ func (w *NWaku) Start() error {
// w.goingOnline = make(chan struct{}) // w.goingOnline = make(chan struct{})
err := w.WakuStart() err := w.WakuStart()
fmt.Println("------- GABRIEL start 2 --------")
if err != nil { if err != nil {
fmt.Println("Error happened:", err.Error()) fmt.Println("Error happened:", err.Error())
return err return err
} }
fmt.Println("------- GABRIEL start 3 --------")
ch := make(chan os.Signal, 1) // ch := make(chan os.Signal, 1)
signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM) // fmt.Println("------- GABRIEL start 4 --------")
<-ch // signal.Notify(ch, syscall.SIGINT, syscall.SIGTERM)
// fmt.Println("------- GABRIEL start 5 --------")
// <-ch
fmt.Println("------- GABRIEL start 6 --------")
// if err = w.node.Start(w.ctx); err != nil { // if err = w.node.Start(w.ctx); err != nil {
// return fmt.Errorf("failed to start go-waku node: %v", err) // return fmt.Errorf("failed to start go-waku node: %v", err)
@ -1850,13 +1855,17 @@ func wakuNew(nodeKey *ecdsa.PrivateKey,
func (self *NWaku) WakuStart() error { func (self *NWaku) WakuStart() error {
fmt.Println("------- GABRIEL WakuStart 1 --------")
var resp = C.allocResp() var resp = C.allocResp()
defer C.freeResp(resp) defer C.freeResp(resp)
fmt.Println("------- GABRIEL WakuStart 2 --------")
C.cGoWakuStart(self.wakuCtx, resp) C.cGoWakuStart(self.wakuCtx, resp)
fmt.Println("------- GABRIEL WakuStart 3 --------")
if C.getRet(resp) == C.RET_OK { if C.getRet(resp) == C.RET_OK {
return nil return nil
} }
fmt.Println("------- GABRIEL WakuStart 4 --------")
errMsg := "error WakuStart: " + C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp))) errMsg := "error WakuStart: " + C.GoStringN(C.getMyCharPtr(resp), C.int(C.getMyCharLen(resp)))
return errors.New(errMsg) return errors.New(errMsg)
} }
@ -2387,11 +2396,17 @@ func New(nodeKey *ecdsa.PrivateKey,
onHistoricMessagesRequestFailed func([]byte, peer.ID, error), onHistoricMessagesRequestFailed func([]byte, peer.ID, error),
onPeerStats func(types.ConnStatus)) (*NWaku, error) { onPeerStats func(types.ConnStatus)) (*NWaku, error) {
fmt.Println("--------- GABRIEL new 1 -----------")
// Lock the main goroutine to its current OS thread // Lock the main goroutine to its current OS thread
runtime.LockOSThread() runtime.LockOSThread()
fmt.Println("--------- GABRIEL new 2 -----------")
WakuSetup() // This should only be called once in the whole app's life WakuSetup() // This should only be called once in the whole app's life
fmt.Println("--------- GABRIEL new 3 -----------")
node, err := wakuNew(nodeKey, node, err := wakuNew(nodeKey,
fleet, fleet,
cfg, logger, appDB, ts, onHistoricMessagesRequestFailed, cfg, logger, appDB, ts, onHistoricMessagesRequestFailed,
@ -2400,17 +2415,21 @@ func New(nodeKey *ecdsa.PrivateKey,
return nil, err return nil, err
} }
fmt.Println("--------- GABRIEL new 4 -----------")
defaultPubsubTopic, err := node.WakuDefaultPubsubTopic() defaultPubsubTopic, err := node.WakuDefaultPubsubTopic()
if err != nil { if err != nil {
fmt.Println("Error happened:", err.Error()) fmt.Println("Error happened:", err.Error())
} }
fmt.Println("--------- GABRIEL new 5 -----------")
err = node.WakuRelaySubscribe(defaultPubsubTopic) err = node.WakuRelaySubscribe(defaultPubsubTopic)
if err != nil { if err != nil {
fmt.Println("Error happened:", err.Error()) fmt.Println("Error happened:", err.Error())
} }
fmt.Println("--------- GABRIEL new 6 -----------")
node.WakuSetEventCallback() node.WakuSetEventCallback()
fmt.Println("--------- GABRIEL new 7 -----------")
return node, nil return node, nil

View File

@ -3,20 +3,15 @@ package wakuv2
import ( import (
"context" "context"
"crypto/rand" "crypto/rand"
"encoding/json"
"errors" "errors"
"fmt"
"math/big" "math/big"
"os" "os"
"sync"
"testing" "testing"
"time" "time"
"go.uber.org/zap"
"github.com/cenkalti/backoff/v3" "github.com/cenkalti/backoff/v3"
"github.com/libp2p/go-libp2p/core/metrics"
"github.com/libp2p/go-libp2p/core/peer" "github.com/libp2p/go-libp2p/core/peer"
libp2pprotocol "github.com/libp2p/go-libp2p/core/protocol"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
@ -28,20 +23,11 @@ import (
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
"github.com/waku-org/go-waku/waku/v2/dnsdisc" "github.com/waku-org/go-waku/waku/v2/dnsdisc"
wps "github.com/waku-org/go-waku/waku/v2/peerstore"
"github.com/waku-org/go-waku/waku/v2/protocol" "github.com/waku-org/go-waku/waku/v2/protocol"
"github.com/waku-org/go-waku/waku/v2/protocol/filter"
"github.com/waku-org/go-waku/waku/v2/protocol/legacy_store"
"github.com/waku-org/go-waku/waku/v2/protocol/lightpush"
"github.com/waku-org/go-waku/waku/v2/protocol/pb" "github.com/waku-org/go-waku/waku/v2/protocol/pb"
"github.com/waku-org/go-waku/waku/v2/protocol/relay"
"github.com/waku-org/go-waku/waku/v2/protocol/store" "github.com/waku-org/go-waku/waku/v2/protocol/store"
"github.com/status-im/status-go/appdatabase"
"github.com/status-im/status-go/connection"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol/tt" "github.com/status-im/status-go/protocol/tt"
"github.com/status-im/status-go/t/helpers"
"github.com/status-im/status-go/wakuv2/common" "github.com/status-im/status-go/wakuv2/common"
) )
@ -63,7 +49,7 @@ func setDefaultConfig(config *Config, lightMode bool) {
} }
} }
func TestDiscoveryV5(t *testing.T) { /* func TestDiscoveryV5(t *testing.T) {
config := &Config{} config := &Config{}
setDefaultConfig(config, false) setDefaultConfig(config, false)
config.DiscV5BootstrapNodes = []string{testStoreENRBootstrap} config.DiscV5BootstrapNodes = []string{testStoreENRBootstrap}
@ -153,7 +139,7 @@ func TestRelayPeers(t *testing.T) {
require.NoError(t, w.Start()) require.NoError(t, w.Start())
_, err = w.RelayPeersByTopic(config.DefaultShardPubsubTopic) _, err = w.RelayPeersByTopic(config.DefaultShardPubsubTopic)
require.Error(t, err) require.Error(t, err)
} } */
func parseNodes(rec []string) []*enode.Node { func parseNodes(rec []string) []*enode.Node {
var ns []*enode.Node var ns []*enode.Node
@ -178,8 +164,11 @@ func parseNodes(rec []string) []*enode.Node {
// --nat=extip:${IP_ADDRESS} --discv5-discovery --discv5-udp-port=9000 --rest-address=0.0.0.0 --store // --nat=extip:${IP_ADDRESS} --discv5-discovery --discv5-udp-port=9000 --rest-address=0.0.0.0 --store
func TestBasicWakuV2(t *testing.T) { func TestBasicWakuV2(t *testing.T) {
fmt.Println("Starting TestBasicWakuV2")
nwakuInfo, err := GetNwakuInfo(nil, nil) nwakuInfo, err := GetNwakuInfo(nil, nil)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Retrieved nwaku information")
// Creating a fake DNS Discovery ENRTree // Creating a fake DNS Discovery ENRTree
tree, url := makeTestTree("n", parseNodes([]string{nwakuInfo.EnrUri}), nil) tree, url := makeTestTree("n", parseNodes([]string{nwakuInfo.EnrUri}), nil)
@ -188,6 +177,7 @@ func TestBasicWakuV2(t *testing.T) {
if envEnrTreeAddress != "" { if envEnrTreeAddress != "" {
enrTreeAddress = envEnrTreeAddress enrTreeAddress = envEnrTreeAddress
} }
fmt.Printf("Created fake DNS Discovery ENRTree with address: %s\n", enrTreeAddress)
config := &Config{} config := &Config{}
setDefaultConfig(config, false) setDefaultConfig(config, false)
@ -196,13 +186,19 @@ func TestBasicWakuV2(t *testing.T) {
config.DiscV5BootstrapNodes = []string{enrTreeAddress} config.DiscV5BootstrapNodes = []string{enrTreeAddress}
config.DiscoveryLimit = 20 config.DiscoveryLimit = 20
config.WakuNodes = []string{enrTreeAddress} config.WakuNodes = []string{enrTreeAddress}
fmt.Println("Configured Waku node")
w, err := New(nil, "", config, nil, nil, nil, nil, nil) w, err := New(nil, "", config, nil, nil, nil, nil, nil)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Created new Waku node")
require.NoError(t, w.Start()) require.NoError(t, w.Start())
fmt.Println("Started Waku node")
enr, err := w.ENR() enr, err := w.ENR()
require.NoError(t, err) require.NoError(t, err)
require.NotNil(t, enr) require.NotNil(t, enr)
fmt.Println("Retrieved ENR from Waku node")
// DNSDiscovery // DNSDiscovery
ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second) ctx, cancel := context.WithTimeout(context.TODO(), 30*time.Second)
@ -210,12 +206,14 @@ func TestBasicWakuV2(t *testing.T) {
discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress, dnsdisc.WithResolver(config.Resolver)) discoveredNodes, err := dnsdisc.RetrieveNodes(ctx, enrTreeAddress, dnsdisc.WithResolver(config.Resolver))
require.NoError(t, err) require.NoError(t, err)
fmt.Printf("Discovered %d nodes via DNS discovery\n", len(discoveredNodes))
// Peer used for retrieving history // Peer used for retrieving history
r, err := rand.Int(rand.Reader, big.NewInt(int64(len(discoveredNodes)))) r, err := rand.Int(rand.Reader, big.NewInt(int64(len(discoveredNodes))))
require.NoError(t, err) require.NoError(t, err)
storeNode := discoveredNodes[int(r.Int64())] storeNode := discoveredNodes[int(r.Int64())]
fmt.Printf("Selected store node with ID: %s\n", storeNode.PeerID)
options := func(b *backoff.ExponentialBackOff) { options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 30 * time.Second b.MaxElapsedTime = 30 * time.Second
@ -229,14 +227,17 @@ func TestBasicWakuV2(t *testing.T) {
return nil return nil
}, options) }, options)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Successfully discovered at least one peer")
// Dropping Peer // Dropping Peer
err = w.DropPeer(storeNode.PeerID) err = w.DropPeer(storeNode.PeerID)
require.NoError(t, err) require.NoError(t, err)
fmt.Printf("Dropped peer with ID: %s\n", storeNode.PeerID)
// Dialing with peerID // Dialing with peerID
err = w.DialPeerByID(storeNode.PeerID) err = w.DialPeerByID(storeNode.PeerID)
require.NoError(t, err) require.NoError(t, err)
fmt.Printf("Dialed peer with ID: %s\n", storeNode.PeerID)
err = tt.RetryWithBackOff(func() error { err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) < 1 { if len(w.Peers()) < 1 {
@ -245,6 +246,7 @@ func TestBasicWakuV2(t *testing.T) {
return nil return nil
}, options) }, options)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Successfully re-established connection with at least one peer")
filter := &common.Filter{ filter := &common.Filter{
PubsubTopic: config.DefaultShardPubsubTopic, PubsubTopic: config.DefaultShardPubsubTopic,
@ -254,11 +256,13 @@ func TestBasicWakuV2(t *testing.T) {
_, err = w.Subscribe(filter) _, err = w.Subscribe(filter)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Subscribed to filter")
msgTimestamp := w.timestamp() msgTimestamp := w.timestamp()
contentTopic := maps.Keys(filter.ContentTopics)[0] contentTopic := maps.Keys(filter.ContentTopics)[0]
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
fmt.Println("Waited 2 seconds before sending message")
_, err = w.Send(config.DefaultShardPubsubTopic, &pb.WakuMessage{ _, err = w.Send(config.DefaultShardPubsubTopic, &pb.WakuMessage{
Payload: []byte{1, 2, 3, 4, 5}, Payload: []byte{1, 2, 3, 4, 5},
@ -268,11 +272,14 @@ func TestBasicWakuV2(t *testing.T) {
}, nil) }, nil)
require.NoError(t, err) require.NoError(t, err)
fmt.Println("Sent test message")
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
fmt.Println("Waited 1 second after sending message")
messages := filter.Retrieve() messages := filter.Retrieve()
require.Len(t, messages, 1) require.Len(t, messages, 1)
fmt.Println("Successfully retrieved 1 message from filter")
timestampInSeconds := msgTimestamp / int64(time.Second) timestampInSeconds := msgTimestamp / int64(time.Second)
marginInSeconds := 20 marginInSeconds := 20
@ -299,13 +306,18 @@ func TestBasicWakuV2(t *testing.T) {
if marginInSeconds < 40 { if marginInSeconds < 40 {
marginInSeconds += 5 marginInSeconds += 5
} }
fmt.Printf("Query failed or returned no messages. Increasing margin to %d seconds\n", marginInSeconds)
return errors.New("no messages received from store node") return errors.New("no messages received from store node")
} }
fmt.Printf("Query successful, received %d messages\n", envelopeCount)
return nil return nil
}, options) }, options)
require.NoError(t, err) require.NoError(t, err)
require.NoError(t, w.Stop()) require.NoError(t, w.Stop())
fmt.Println("Stopped Waku node")
fmt.Println("TestBasicWakuV2 completed successfully")
} }
type mapResolver map[string]string type mapResolver map[string]string
@ -331,7 +343,7 @@ func makeTestTree(domain string, nodes []*enode.Node, links []string) (*ethdnsdi
return tree, url return tree, url
} }
func TestPeerExchange(t *testing.T) { /* func TestPeerExchange(t *testing.T) {
logger, err := zap.NewDevelopment() logger, err := zap.NewDevelopment()
require.NoError(t, err) require.NoError(t, err)
// start node which serve as PeerExchange server // start node which serve as PeerExchange server
@ -410,8 +422,8 @@ func TestPeerExchange(t *testing.T) {
require.NoError(t, pxServerNode.Stop()) require.NoError(t, pxServerNode.Stop())
require.NoError(t, discV5Node.Stop()) require.NoError(t, discV5Node.Stop())
} }
*/
func TestWakuV2Filter(t *testing.T) { /* func TestWakuV2Filter(t *testing.T) {
t.Skip("flaky test") t.Skip("flaky test")
enrTreeAddress := testBootENRBootstrap enrTreeAddress := testBootENRBootstrap
@ -612,7 +624,7 @@ func TestWakuV2Store(t *testing.T) {
) )
require.NoError(t, err) require.NoError(t, err)
require.True(t, envelopeCount > 0, "no messages received from store node") require.True(t, envelopeCount > 0, "no messages received from store node")
} } */
func waitForPeerConnection(t *testing.T, peerID peer.ID, peerCh chan peer.IDSlice) { func waitForPeerConnection(t *testing.T, peerID peer.ID, peerCh chan peer.IDSlice) {
waitForPeerConnectionWithTimeout(t, peerID, peerCh, 3*time.Second) waitForPeerConnectionWithTimeout(t, peerID, peerCh, 3*time.Second)
@ -652,7 +664,7 @@ func waitForEnvelope(t *testing.T, contentTopic string, envCh chan common.Envelo
} }
} }
func TestOnlineChecker(t *testing.T) { /* func TestOnlineChecker(t *testing.T) {
w, err := New(nil, "shards.staging", nil, nil, nil, nil, nil, nil) w, err := New(nil, "shards.staging", nil, nil, nil, nil, nil, nil)
require.NoError(t, w.Start()) require.NoError(t, w.Start())
@ -689,9 +701,9 @@ func TestOnlineChecker(t *testing.T) {
f := &common.Filter{} f := &common.Filter{}
lightNode.filterManager.SubscribeFilter("test", protocol.NewContentFilter(f.PubsubTopic, f.ContentTopics.ContentTopics()...)) lightNode.filterManager.SubscribeFilter("test", protocol.NewContentFilter(f.PubsubTopic, f.ContentTopics.ContentTopics()...))
} } */
func TestLightpushRateLimit(t *testing.T) { /* func TestLightpushRateLimit(t *testing.T) {
logger, err := zap.NewDevelopment() logger, err := zap.NewDevelopment()
require.NoError(t, err) require.NoError(t, err)
@ -790,9 +802,9 @@ func TestLightpushRateLimit(t *testing.T) {
messages := filter.Retrieve() messages := filter.Retrieve()
require.Len(t, messages, 2) require.Len(t, messages, 2)
} } */
func TestTelemetryFormat(t *testing.T) { /* func TestTelemetryFormat(t *testing.T) {
logger, err := zap.NewDevelopment() logger, err := zap.NewDevelopment()
require.NoError(t, err) require.NoError(t, err)
@ -815,4 +827,4 @@ func TestTelemetryFormat(t *testing.T) {
requestBody := tc.getTelemetryRequestBody(m) requestBody := tc.getTelemetryRequestBody(m)
_, err = json.Marshal(requestBody) _, err = json.Marshal(requestBody)
require.NoError(t, err) require.NoError(t, err)
} } */