forked from cerc-io/plugeth
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
This commit is contained in:
parent
91eec1251c
commit
df488975bd
@ -82,6 +82,18 @@ func TestMain(m *testing.M) {
|
|||||||
func runSwarm(t *testing.T, args ...string) *cmdtest.TestCmd {
|
func runSwarm(t *testing.T, args ...string) *cmdtest.TestCmd {
|
||||||
tt := cmdtest.NewTestCmd(t, nil)
|
tt := cmdtest.NewTestCmd(t, nil)
|
||||||
|
|
||||||
|
found := false
|
||||||
|
for _, v := range args {
|
||||||
|
if v == "--bootnodes" {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !found {
|
||||||
|
args = append([]string{"--bootnodes", ""}, args...)
|
||||||
|
}
|
||||||
|
|
||||||
// Boot "swarm". This actually runs the test binary but the TestMain
|
// Boot "swarm". This actually runs the test binary but the TestMain
|
||||||
// function will prevent any tests from running.
|
// function will prevent any tests from running.
|
||||||
tt.Run("swarm-test", args...)
|
tt.Run("swarm-test", args...)
|
||||||
@ -252,6 +264,7 @@ func existingTestNode(t *testing.T, dir string, bzzaccount string) *testNode {
|
|||||||
|
|
||||||
// start the node
|
// start the node
|
||||||
node.Cmd = runSwarm(t,
|
node.Cmd = runSwarm(t,
|
||||||
|
"--bootnodes", "",
|
||||||
"--port", p2pPort,
|
"--port", p2pPort,
|
||||||
"--nat", "extip:127.0.0.1",
|
"--nat", "extip:127.0.0.1",
|
||||||
"--datadir", dir,
|
"--datadir", dir,
|
||||||
@ -327,6 +340,7 @@ func newTestNode(t *testing.T, dir string) *testNode {
|
|||||||
|
|
||||||
// start the node
|
// start the node
|
||||||
node.Cmd = runSwarm(t,
|
node.Cmd = runSwarm(t,
|
||||||
|
"--bootnodes", "",
|
||||||
"--port", p2pPort,
|
"--port", p2pPort,
|
||||||
"--nat", "extip:127.0.0.1",
|
"--nat", "extip:127.0.0.1",
|
||||||
"--datadir", dir,
|
"--datadir", dir,
|
||||||
|
@ -773,6 +773,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
|
|||||||
node, err := enode.ParseV4(url)
|
node, err := enode.ParseV4(url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
|
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
|
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
|
||||||
}
|
}
|
||||||
@ -800,12 +801,14 @@ func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
|
|||||||
|
|
||||||
cfg.BootstrapNodesV5 = make([]*discv5.Node, 0, len(urls))
|
cfg.BootstrapNodesV5 = make([]*discv5.Node, 0, len(urls))
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
node, err := discv5.ParseNode(url)
|
if url != "" {
|
||||||
if err != nil {
|
node, err := discv5.ParseNode(url)
|
||||||
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
|
if err != nil {
|
||||||
continue
|
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
|
||||||
}
|
}
|
||||||
cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user