Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions node/bridge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,32 @@ func TestBridge_WithMockedCoreClient(t *testing.T) {
err = node.Start(ctx)
require.NoError(t, err)

ctx, cancel = context.WithCancel(context.Background())
t.Cleanup(cancel)

err = node.Stop(ctx)
require.NoError(t, err)
}

func TestBridge_WithMutualPeers(t *testing.T) {
repo := MockStore(t, DefaultConfig(Bridge))
peers := []string{
"/ip6/100:0:114b:abc5:e13a:c32f:7a9e:f00a/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
"/ip4/192.168.1.10/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
}
node, err := New(Bridge, repo, WithMutualPeers(peers))
require.NoError(t, err)
require.NotNil(t, node)

assert.Equal(t, node.Config.P2P.MutualPeers, peers)
}

func TestBridge_WithBootstrapPeers(t *testing.T) {
repo := MockStore(t, DefaultConfig(Bridge))
peers := []string{
"/ip6/100:0:114b:abc5:e13a:c32f:7a9e:f00a/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
"/ip4/192.168.1.10/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
}
node, err := New(Bridge, repo, WithBootstrapPeers(peers))
require.NoError(t, err)
require.NotNil(t, node)

assert.Equal(t, node.Config.P2P.BootstrapPeers, peers)
}
9 changes: 9 additions & 0 deletions node/config_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,18 @@ func WithConfig(custom *Config) Option {
}
}

// WithMutualPeers sets the `MutualPeers` field in the config.
func WithMutualPeers(addrs []string) Option {
return func(cfg *Config, _ *settings) (_ error) {
cfg.P2P.MutualPeers = addrs
return nil
}
}

// WithBootstrapPeers sets the `BootstrapPeers` field in the config.
func WithBootstrapPeers(addrs []string) Option {
return func(cfg *Config, _ *settings) (_ error) {
cfg.P2P.BootstrapPeers = addrs
return nil
}
}
26 changes: 26 additions & 0 deletions node/light_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,29 @@ func TestNewLightWithHost(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, node.Host.ID(), nw.Peers()[0])
}

func TestLight_WithMutualPeers(t *testing.T) {
repo := MockStore(t, DefaultConfig(Light))
peers := []string{
"/ip6/100:0:114b:abc5:e13a:c32f:7a9e:f00a/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
"/ip4/192.168.1.10/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
}
node, err := New(Light, repo, WithMutualPeers(peers))
require.NoError(t, err)
require.NotNil(t, node)

assert.Equal(t, node.Config.P2P.MutualPeers, peers)
}

func TestLight_WithBootstrapPeers(t *testing.T) {
repo := MockStore(t, DefaultConfig(Light))
peers := []string{
"/ip6/100:0:114b:abc5:e13a:c32f:7a9e:f00a/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
"/ip4/192.168.1.10/tcp/2121/p2p/12D3KooWSRqDfpLsQxpyUhLC9oXHD2WuZ2y5FWzDri7LT4Dw9fSi",
}
node, err := New(Light, repo, WithBootstrapPeers(peers))
require.NoError(t, err)
require.NotNil(t, node)

assert.Equal(t, node.Config.P2P.BootstrapPeers, peers)
}