2018-03-02 09:25:30 +00:00
|
|
|
package node
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2019-08-20 15:38:40 +00:00
|
|
|
"github.com/ethereum/go-ethereum/accounts"
|
2018-03-02 09:25:30 +00:00
|
|
|
|
2020-01-02 09:10:19 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
2018-06-08 11:29:50 +00:00
|
|
|
"github.com/status-im/status-go/params"
|
2021-01-14 22:15:13 +00:00
|
|
|
"github.com/status-im/status-go/whisper"
|
2018-03-02 09:25:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestWhisperLightModeEnabledSetsEmptyBloomFilter(t *testing.T) {
|
2018-04-16 12:36:09 +00:00
|
|
|
config := params.NodeConfig{
|
2020-01-08 11:12:23 +00:00
|
|
|
EnableNTPSync: true,
|
2018-09-13 16:31:29 +00:00
|
|
|
WhisperConfig: params.WhisperConfig{
|
2018-04-16 12:36:09 +00:00
|
|
|
Enabled: true,
|
|
|
|
LightClient: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
node := New()
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, node.Start(&config, &accounts.Manager{}))
|
2018-03-02 09:25:30 +00:00
|
|
|
defer func() {
|
2018-04-16 12:36:09 +00:00
|
|
|
require.NoError(t, node.Stop())
|
2018-03-02 09:25:30 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
var whisper *whisper.Whisper
|
2018-04-16 12:36:09 +00:00
|
|
|
require.NoError(t, node.gethService(&whisper))
|
2018-03-02 09:25:30 +00:00
|
|
|
|
|
|
|
bloomFilter := whisper.BloomFilter()
|
|
|
|
expectedEmptyBloomFilter := make([]byte, 64)
|
|
|
|
require.NotNil(t, bloomFilter)
|
|
|
|
require.Equal(t, expectedEmptyBloomFilter, bloomFilter)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestWhisperLightModeEnabledSetsNilBloomFilter(t *testing.T) {
|
2018-04-16 12:36:09 +00:00
|
|
|
config := params.NodeConfig{
|
2020-01-08 11:12:23 +00:00
|
|
|
EnableNTPSync: true,
|
2018-09-13 16:31:29 +00:00
|
|
|
WhisperConfig: params.WhisperConfig{
|
2018-04-16 12:36:09 +00:00
|
|
|
Enabled: true,
|
|
|
|
LightClient: false,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
node := New()
|
2019-08-20 15:38:40 +00:00
|
|
|
require.NoError(t, node.Start(&config, &accounts.Manager{}))
|
2018-03-02 09:25:30 +00:00
|
|
|
defer func() {
|
2018-04-16 12:36:09 +00:00
|
|
|
require.NoError(t, node.Stop())
|
2018-03-02 09:25:30 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
var whisper *whisper.Whisper
|
2018-04-16 12:36:09 +00:00
|
|
|
require.NoError(t, node.gethService(&whisper))
|
2018-03-02 09:25:30 +00:00
|
|
|
require.Nil(t, whisper.BloomFilter())
|
|
|
|
}
|
2020-02-18 11:21:01 +00:00
|
|
|
|
|
|
|
func TestBridgeSetup(t *testing.T) {
|
|
|
|
testCases := []struct {
|
|
|
|
Name string
|
2020-10-08 06:01:28 +00:00
|
|
|
Skip string
|
2020-02-18 11:21:01 +00:00
|
|
|
Cfg params.NodeConfig
|
|
|
|
ErrorMessage string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
Name: "no whisper and waku",
|
|
|
|
Cfg: params.NodeConfig{
|
|
|
|
BridgeConfig: params.BridgeConfig{Enabled: true},
|
|
|
|
},
|
|
|
|
ErrorMessage: "setup bridge: failed to get Whisper: unknown service",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "only whisper",
|
|
|
|
Cfg: params.NodeConfig{
|
|
|
|
WhisperConfig: params.WhisperConfig{
|
|
|
|
Enabled: true,
|
|
|
|
LightClient: false,
|
|
|
|
},
|
|
|
|
BridgeConfig: params.BridgeConfig{Enabled: true},
|
|
|
|
},
|
|
|
|
ErrorMessage: "setup bridge: failed to get Waku: unknown service",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "only waku",
|
|
|
|
Cfg: params.NodeConfig{
|
|
|
|
WakuConfig: params.WakuConfig{
|
|
|
|
Enabled: true,
|
|
|
|
LightClient: false,
|
|
|
|
},
|
|
|
|
BridgeConfig: params.BridgeConfig{Enabled: true},
|
|
|
|
},
|
|
|
|
ErrorMessage: "setup bridge: failed to get Whisper: unknown service",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "both",
|
2020-10-08 06:01:28 +00:00
|
|
|
Skip: "This test is flaky, setting it as skip for now",
|
2020-02-18 11:21:01 +00:00
|
|
|
Cfg: params.NodeConfig{
|
|
|
|
WhisperConfig: params.WhisperConfig{
|
|
|
|
Enabled: true,
|
|
|
|
LightClient: false,
|
|
|
|
},
|
|
|
|
WakuConfig: params.WakuConfig{
|
|
|
|
Enabled: true,
|
|
|
|
LightClient: false,
|
|
|
|
},
|
|
|
|
BridgeConfig: params.BridgeConfig{Enabled: true},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tc := range testCases {
|
2020-10-08 06:01:28 +00:00
|
|
|
if tc.Skip != "" {
|
|
|
|
t.Skip(tc.Skip)
|
|
|
|
continue
|
|
|
|
}
|
2020-02-18 11:21:01 +00:00
|
|
|
t.Run(tc.Name, func(t *testing.T) {
|
|
|
|
node := New()
|
|
|
|
err := node.Start(&tc.Cfg, &accounts.Manager{})
|
|
|
|
if err != nil {
|
|
|
|
require.EqualError(t, err, tc.ErrorMessage)
|
|
|
|
} else if tc.ErrorMessage != "" {
|
|
|
|
t.Fatalf("expected an error: %s", tc.ErrorMessage)
|
|
|
|
}
|
|
|
|
require.NoError(t, node.Stop())
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|