status-go/wakuv2/waku_test.go

86 lines
2.0 KiB
Go
Raw Normal View History

package wakuv2
import (
"errors"
"testing"
"time"
"github.com/cenkalti/backoff/v3"
"github.com/stretchr/testify/require"
"github.com/status-im/status-go/protocol/tt"
)
var testENRBootstrap = "enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@prod.nodes.status.im"
func TestDiscoveryV5(t *testing.T) {
config := &Config{}
config.EnableDiscV5 = true
config.DiscV5BootstrapNodes = []string{testENRBootstrap}
config.DiscoveryLimit = 20
config.UDPPort = 9001
w, err := New("", "", config, nil, nil, nil)
require.NoError(t, err)
require.NoError(t, w.Start())
err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) == 0 {
return errors.New("no peers discovered")
}
return nil
})
require.NoError(t, err)
require.NotEqual(t, 0, len(w.Peers()))
require.NoError(t, w.Stop())
}
func TestRestartDiscoveryV5(t *testing.T) {
config := &Config{}
config.EnableDiscV5 = true
// Use wrong discv5 bootstrap address, to simulate being offline
config.DiscV5BootstrapNodes = []string{"enrtree://AOGECG2SPND25EEFMAJ5WF3KSGJNSGV356DSTL2YVLLZWIV6SAYBM@1.1.1.2"}
config.DiscoveryLimit = 20
config.UDPPort = 9002
w, err := New("", "", config, nil, nil, nil)
require.NoError(t, err)
require.NoError(t, w.Start())
require.False(t, w.seededBootnodesForDiscV5)
options := func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 2 * time.Second
}
// Sanity check, not great, but it's probably helpful
err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) == 0 {
return errors.New("no peers discovered")
}
return nil
}, options)
require.Error(t, err)
w.discV5BootstrapNodes = []string{testENRBootstrap}
options = func(b *backoff.ExponentialBackOff) {
b.MaxElapsedTime = 30 * time.Second
}
err = tt.RetryWithBackOff(func() error {
if len(w.Peers()) == 0 {
return errors.New("no peers discovered")
}
return nil
}, options)
require.NoError(t, err)
require.True(t, w.seededBootnodesForDiscV5)
require.NotEqual(t, 0, len(w.Peers()))
require.NoError(t, w.Stop())
}