diff --git a/pkg/rpc/client/rpc_test.go b/pkg/rpc/client/rpc_test.go index f87e57296..856c72216 100644 --- a/pkg/rpc/client/rpc_test.go +++ b/pkg/rpc/client/rpc_test.go @@ -517,25 +517,25 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{ invoke: func(c *Client) (interface{}, error) { return c.GetPeers() }, - serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"unconnected":[{"address":"172.200.0.1","port":"20333"}],"connected":[{"address":"127.0.0.1","port":"20335"}],"bad":[{"address":"172.200.0.254","port":"20332"}]}}`, + serverResponse: `{"id":1,"jsonrpc":"2.0","result":{"unconnected":[{"address":"172.200.0.1","port":20333}],"connected":[{"address":"127.0.0.1","port":20335}],"bad":[{"address":"172.200.0.254","port":20332}]}}`, result: func(c *Client) interface{} { return &result.GetPeers{ Unconnected: result.Peers{ { Address: "172.200.0.1", - Port: "20333", + Port: 20333, }, }, Connected: result.Peers{ { Address: "127.0.0.1", - Port: "20335", + Port: 20335, }, }, Bad: result.Peers{ { Address: "172.200.0.254", - Port: "20332", + Port: 20332, }, }, } diff --git a/pkg/rpc/response/result/peers.go b/pkg/rpc/response/result/peers.go index b18acc0e8..67c637c36 100644 --- a/pkg/rpc/response/result/peers.go +++ b/pkg/rpc/response/result/peers.go @@ -1,6 +1,7 @@ package result import ( + "strconv" "strings" ) @@ -18,7 +19,7 @@ type ( // Peer represents the peer. Peer struct { Address string `json:"address"` - Port string `json:"port"` + Port uint16 `json:"port"` } ) @@ -50,9 +51,10 @@ func (g *GetPeers) AddBad(addrs []string) { func (p *Peers) addPeers(addrs []string) { for i := range addrs { addressParts := strings.Split(addrs[i], ":") + port, _ := strconv.Atoi(addressParts[1]) // We know it's a good port number. peer := Peer{ Address: addressParts[0], - Port: addressParts[1], + Port: uint16(port), } *p = append(*p, peer) diff --git a/pkg/rpc/response/result/peers_test.go b/pkg/rpc/response/result/peers_test.go index 6e5a9339e..8187f4154 100644 --- a/pkg/rpc/response/result/peers_test.go +++ b/pkg/rpc/response/result/peers_test.go @@ -20,7 +20,7 @@ func TestGetPeers(t *testing.T) { require.Equal(t, 1, len(gp.Connected)) require.Equal(t, 1, len(gp.Bad)) require.Equal(t, "192.168.0.1", gp.Connected[0].Address) - require.Equal(t, "10333", gp.Connected[0].Port) + require.Equal(t, uint16(10333), gp.Connected[0].Port) require.Equal(t, "127.0.0.1", gp.Bad[0].Address) - require.Equal(t, "20333", gp.Bad[0].Port) + require.Equal(t, uint16(20333), gp.Bad[0].Port) }