Skip to content

Commit df48897

Browse files
acudzelig
authored andcommitted
cmd/swarm: dont connect to bootnodes in tests (#19270)
* cmd/swarm: dont connect to bootnodes in tests * cmd/utils: check for empty string when parsing enode
1 parent 91eec12 commit df48897

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

‎cmd/swarm/run_test.go‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ func TestMain(m *testing.M) {
8282
func runSwarm(t *testing.T, args ...string) *cmdtest.TestCmd {
8383
tt := cmdtest.NewTestCmd(t, nil)
8484

85+
found := false
86+
for _, v := range args {
87+
if v == "--bootnodes" {
88+
found = true
89+
break
90+
}
91+
}
92+
93+
if !found {
94+
args = append([]string{"--bootnodes", ""}, args...)
95+
}
96+
8597
// Boot "swarm". This actually runs the test binary but the TestMain
8698
// function will prevent any tests from running.
8799
tt.Run("swarm-test", args...)
@@ -252,6 +264,7 @@ func existingTestNode(t *testing.T, dir string, bzzaccount string) *testNode {
252264

253265
// start the node
254266
node.Cmd = runSwarm(t,
267+
"--bootnodes", "",
255268
"--port", p2pPort,
256269
"--nat", "extip:127.0.0.1",
257270
"--datadir", dir,
@@ -327,6 +340,7 @@ func newTestNode(t *testing.T, dir string) *testNode {
327340

328341
// start the node
329342
node.Cmd = runSwarm(t,
343+
"--bootnodes", "",
330344
"--port", p2pPort,
331345
"--nat", "extip:127.0.0.1",
332346
"--datadir", dir,

‎cmd/utils/flags.go‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
773773
node, err := enode.ParseV4(url)
774774
if err != nil {
775775
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
776+
continue
776777
}
777778
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
778779
}
@@ -800,12 +801,14 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
800801

801802
cfg.BootstrapNodesV5 = make([]*discv5.Node, 0, len(urls))
802803
for _, url := range urls {
803-
node, err := discv5.ParseNode(url)
804-
if err != nil {
805-
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
806-
continue
804+
if url != "" {
805+
node, err := discv5.ParseNode(url)
806+
if err != nil {
807+
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
808+
continue
809+
}
810+
cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
807811
}
808-
cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
809812
}
810813
}
811814

0 commit comments

Comments
 (0)