Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG-PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Month, DD, YYYY

### FEATURES

- [node/config: add WithBootstrapPeers option #375](https://github.com/celestiaorg/celestia-node/pull/375) [@Bidon15](https://github.com/Bidon15)
Comment thread
Bidon15 marked this conversation as resolved.
Outdated
- [feat(cmd): give a birth to cel-shed and p2p key utilities #281](https://github.com/celestiaorg/celestia-node/pull/281) [@Wondertan](https://github.com/Wondertan)
- [feat(cmd|node): MutualPeers Node option and CLI flag #280](https://github.com/celestiaorg/celestia-node/pull/280) [@Wondertan](https://github.com/Wondertan)
- [node: enhance DI allowing overriding of dependencies](https://github.com/celestiaorg/celestia-node/pull/290) [@Wondertan](https://github.com/Wondertan)
Expand Down
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
}
}
13 changes: 13 additions & 0 deletions node/light_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,16 @@ func TestNewLightWithHost(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, node.Host.ID(), nw.Peers()[0])
}

func TestLight_WithBootstrapPeers(t *testing.T) {
Comment thread
Bidon15 marked this conversation as resolved.
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)
}