2021-11-12 09:19:42 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
|
|
|
"github.com/multiformats/go-multiaddr"
|
|
|
|
"github.com/stretchr/testify/require"
|
2022-11-09 19:53:01 +00:00
|
|
|
"github.com/waku-org/go-waku/tests"
|
|
|
|
"github.com/waku-org/go-waku/waku/persistence"
|
|
|
|
"github.com/waku-org/go-waku/waku/v2/protocol/store"
|
2021-11-12 09:19:42 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
2022-03-18 19:56:34 +00:00
|
|
|
storeFactory := func(w *WakuNode) store.Store {
|
2023-04-17 00:04:12 +00:00
|
|
|
return store.NewWakuStore(w.opts.messageProvider, w.timesource, w.log)
|
2022-03-18 19:56:34 +00:00
|
|
|
}
|
|
|
|
|
2021-11-12 09:19:42 +00:00
|
|
|
options := []WakuNodeOption{
|
2021-11-17 16:19:42 +00:00
|
|
|
WithHostAddress(hostAddr),
|
2023-02-08 16:02:06 +00:00
|
|
|
WithAdvertiseAddresses(addr),
|
2021-11-12 09:19:42 +00:00
|
|
|
WithMultiaddress([]multiaddr.Multiaddr{addr}),
|
|
|
|
WithPrivateKey(prvKey),
|
|
|
|
WithLibP2POptions(),
|
|
|
|
WithWakuRelay(),
|
2023-04-11 14:38:16 +00:00
|
|
|
WithLegacyWakuFilter(true),
|
2021-11-17 16:19:42 +00:00
|
|
|
WithDiscoveryV5(123, nil, false),
|
2023-01-03 15:17:25 +00:00
|
|
|
WithWakuStore(),
|
2022-05-30 18:48:22 +00:00
|
|
|
WithMessageProvider(&persistence.DBStore{}),
|
2021-11-12 09:19:42 +00:00
|
|
|
WithLightPush(),
|
|
|
|
WithKeepAlive(time.Hour),
|
|
|
|
WithConnectionStatusChannel(connStatusChan),
|
2022-03-18 19:56:34 +00:00
|
|
|
WithWakuStoreFactory(storeFactory),
|
2021-11-12 09:19:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|