From c77b7265735e913beb56d88126941efb925e9003 Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Sat, 1 Jun 2019 09:00:12 -0700 Subject: [PATCH] fix string formatting of bootstrap peers --- config/bootstrap_peers.go | 13 ++++++++++--- config/bootstrap_peers_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 config/bootstrap_peers_test.go diff --git a/config/bootstrap_peers.go b/config/bootstrap_peers.go index 9141c8bee899..f4a13dc9d060 100644 --- a/config/bootstrap_peers.go +++ b/config/bootstrap_peers.go @@ -73,9 +73,16 @@ func ParseBootstrapPeers(addrs []string) ([]peer.AddrInfo, error) { // BootstrapPeerStrings formats a list of AddrInfos as a bootstrap peer list // suitable for serialization. func BootstrapPeerStrings(bps []peer.AddrInfo) []string { - bpss := make([]string, len(bps)) - for i, p := range bps { - bpss[i] = p.String() + bpss := make([]string, 0, len(bps)) + for _, pi := range bps { + addrs, err := peer.AddrInfoToP2pAddrs(&pi) + if err != nil { + // programmer error. + panic(err) + } + for _, addr := range addrs { + bpss = append(bpss, addr.String()) + } } return bpss } diff --git a/config/bootstrap_peers_test.go b/config/bootstrap_peers_test.go new file mode 100644 index 000000000000..eeea9b5fdc03 --- /dev/null +++ b/config/bootstrap_peers_test.go @@ -0,0 +1,24 @@ +package config + +import ( + "sort" + "testing" +) + +func TestBoostrapPeerStrings(t *testing.T) { + parsed, err := ParseBootstrapPeers(DefaultBootstrapAddresses) + if err != nil { + t.Fatal(err) + } + + formatted := BootstrapPeerStrings(parsed) + sort.Strings(formatted) + expected := append([]string{}, DefaultBootstrapAddresses...) + sort.Strings(expected) + + for i, s := range formatted { + if expected[i] != s { + t.Fatalf("expected %s, %s", expected[i], s) + } + } +}