diff --git a/tests/connection_test.go b/tests/connection_test.go index 873bf9a1..003535c4 100644 --- a/tests/connection_test.go +++ b/tests/connection_test.go @@ -2,8 +2,6 @@ package tests import ( "context" - "crypto/rand" - "encoding/hex" "net" "testing" @@ -19,7 +17,7 @@ func TestBasicSendingReceiving(t *testing.T) { hostAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:0") require.NoError(t, err) - key, err := randomHex(32) + key, err := RandomHex(32) require.NoError(t, err) prvKey, err := crypto.HexToECDSA(key) @@ -50,14 +48,6 @@ func TestBasicSendingReceiving(t *testing.T) { require.Contains(t, string(payload.Data), "test") } -func randomHex(n int) (string, error) { - bytes := make([]byte, n) - if _, err := rand.Read(bytes); err != nil { - return "", err - } - return hex.EncodeToString(bytes), nil -} - func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) error { var contentTopic string = "test" var version uint32 = 0 diff --git a/tests/utils.go b/tests/utils.go index 2bdaf2ad..d078b6bc 100644 --- a/tests/utils.go +++ b/tests/utils.go @@ -2,6 +2,8 @@ package tests import ( "context" + "crypto/rand" + "encoding/hex" "fmt" "io" "net" @@ -72,3 +74,11 @@ func MakeHost(ctx context.Context, port int, randomness io.Reader) (host.Host, e func CreateWakuMessage(contentTopic string, timestamp float64) *pb.WakuMessage { return &pb.WakuMessage{Payload: []byte{1, 2, 3}, ContentTopic: contentTopic, Version: 0, Timestamp: timestamp} } + +func RandomHex(n int) (string, error) { + bytes := make([]byte, n) + if _, err := rand.Read(bytes); err != nil { + return "", err + } + return hex.EncodeToString(bytes), nil +} diff --git a/waku/v2/node/wakunode2_test.go b/waku/v2/node/wakunode2_test.go new file mode 100644 index 00000000..e8a56283 --- /dev/null +++ b/waku/v2/node/wakunode2_test.go @@ -0,0 +1,34 @@ +package node + +import ( + "context" + "net" + "testing" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/status-im/go-waku/tests" + "github.com/stretchr/testify/require" +) + +func TestWakuNode2(t *testing.T) { + hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0") + + key, err := tests.RandomHex(32) + require.NoError(t, err) + prvKey, err := crypto.HexToECDSA(key) + require.NoError(t, err) + + ctx := context.Background() + + wakuNode, err := New(ctx, + WithPrivateKey(prvKey), + WithHostAddress([]*net.TCPAddr{hostAddr}), + WithWakuRelay(), + ) + require.NoError(t, err) + + err = wakuNode.Start() + defer wakuNode.Stop() + + require.NoError(t, err) +} diff --git a/waku/v2/node/wakuoptions_test.go b/waku/v2/node/wakuoptions_test.go new file mode 100644 index 00000000..ecea197f --- /dev/null +++ b/waku/v2/node/wakuoptions_test.go @@ -0,0 +1,59 @@ +package node + +import ( + "net" + "testing" + "time" + + "github.com/ethereum/go-ethereum/crypto" + "github.com/multiformats/go-multiaddr" + rendezvous "github.com/status-im/go-waku-rendezvous" + "github.com/status-im/go-waku/tests" + "github.com/stretchr/testify/require" +) + +func TestWakuOptions(t *testing.T) { + connStatusChan := make(chan ConnStatus, 100) + + key, err := tests.RandomHex(32) + require.NoError(t, err) + + prvKey, err := crypto.HexToECDSA(key) + require.NoError(t, err) + + hostAddr, _ := net.ResolveTCPAddr("tcp", "0.0.0.0:0") + + addr, err := multiaddr.NewMultiaddr("/ip4/0.0.0.0/tcp/4000/ws") + require.NoError(t, err) + + advertiseAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:4000") + require.NoError(t, err) + + options := []WakuNodeOption{ + WithHostAddress([]*net.TCPAddr{hostAddr}), + WithAdvertiseAddress([]*net.TCPAddr{advertiseAddr}, false, 4000), + WithMultiaddress([]multiaddr.Multiaddr{addr}), + WithPrivateKey(prvKey), + WithLibP2POptions(), + WithWakuRelay(), + WithRendezvous(), + WithRendezvousServer(rendezvous.NewStorage(nil)), + WithWakuFilter(true), + WithWakuStore(true, true), + WithWakuStoreAndRetentionPolicy(true, time.Hour, 100), + WithMessageProvider(nil), + WithLightPush(), + WithKeepAlive(time.Hour), + WithConnectionStatusChannel(connStatusChan), + } + + params := new(WakuNodeParameters) + + for _, opt := range options { + require.NoError(t, opt(params)) + } + + require.NotNil(t, params.multiAddr) + require.NotNil(t, params.privKey) + require.NotNil(t, params.connStatusC) +}