mirror of https://github.com/status-im/go-waku.git
test: Add more test for waku node
This commit is contained in:
parent
54f647aa4f
commit
e176975aed
|
@ -2,8 +2,6 @@ package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
|
||||||
"encoding/hex"
|
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -19,7 +17,7 @@ func TestBasicSendingReceiving(t *testing.T) {
|
||||||
hostAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
hostAddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:0")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
key, err := randomHex(32)
|
key, err := RandomHex(32)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
prvKey, err := crypto.HexToECDSA(key)
|
prvKey, err := crypto.HexToECDSA(key)
|
||||||
|
@ -50,14 +48,6 @@ func TestBasicSendingReceiving(t *testing.T) {
|
||||||
require.Contains(t, string(payload.Data), "test")
|
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 {
|
func write(ctx context.Context, wakuNode *node.WakuNode, msgContent string) error {
|
||||||
var contentTopic string = "test"
|
var contentTopic string = "test"
|
||||||
var version uint32 = 0
|
var version uint32 = 0
|
||||||
|
|
|
@ -2,6 +2,8 @@ package tests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"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 {
|
func CreateWakuMessage(contentTopic string, timestamp float64) *pb.WakuMessage {
|
||||||
return &pb.WakuMessage{Payload: []byte{1, 2, 3}, ContentTopic: contentTopic, Version: 0, Timestamp: timestamp}
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue