Commit 5f727445 authored by Janos Guljas's avatar Janos Guljas

add swarm.MustParseHexAddress and use it in tests

parent 21dbbe42
...@@ -21,9 +21,9 @@ import ( ...@@ -21,9 +21,9 @@ import (
func TestPingpong(t *testing.T) { func TestPingpong(t *testing.T) {
rtt := time.Minute rtt := time.Minute
peerID, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c") peerID := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
unknownPeerID, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59e") unknownPeerID := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59e")
errorPeerID, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59a") errorPeerID := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59a")
testErr := errors.New("test error") testErr := errors.New("test error")
pingpongService := pingpongmock.New(func(ctx context.Context, address swarm.Address, msgs ...string) (time.Duration, error) { pingpongService := pingpongmock.New(func(ctx context.Context, address swarm.Address, msgs ...string) (time.Duration, error) {
......
...@@ -22,7 +22,7 @@ import ( ...@@ -22,7 +22,7 @@ import (
func TestConnect(t *testing.T) { func TestConnect(t *testing.T) {
underlay := "/ip4/127.0.0.1/tcp/7070/p2p/16Uiu2HAkx8ULY8cTXhdVAcMmLcH9AsTKz6uBQ7DPLKRjMLgBVYkS" underlay := "/ip4/127.0.0.1/tcp/7070/p2p/16Uiu2HAkx8ULY8cTXhdVAcMmLcH9AsTKz6uBQ7DPLKRjMLgBVYkS"
errorUnderlay := "/ip4/127.0.0.1/tcp/7070/p2p/16Uiu2HAkw88cjH2orYrB6fDui4eUNdmgkwnDM8W681UbfsPgM9QY" errorUnderlay := "/ip4/127.0.0.1/tcp/7070/p2p/16Uiu2HAkw88cjH2orYrB6fDui4eUNdmgkwnDM8W681UbfsPgM9QY"
overlay, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c") overlay := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
testErr := errors.New("test error") testErr := errors.New("test error")
client, cleanup := newTestServer(t, testServerOptions{ client, cleanup := newTestServer(t, testServerOptions{
...@@ -57,9 +57,9 @@ func TestConnect(t *testing.T) { ...@@ -57,9 +57,9 @@ func TestConnect(t *testing.T) {
} }
func TestDisconnect(t *testing.T) { func TestDisconnect(t *testing.T) {
address, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c") address := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
unknownAdddress, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59e") unknownAdddress := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59e")
errorAddress, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59a") errorAddress := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59a")
testErr := errors.New("test error") testErr := errors.New("test error")
client, cleanup := newTestServer(t, testServerOptions{ client, cleanup := newTestServer(t, testServerOptions{
......
...@@ -62,8 +62,8 @@ func (s *StreamMock) Close() error { ...@@ -62,8 +62,8 @@ func (s *StreamMock) Close() error {
} }
func TestHandshake(t *testing.T) { func TestHandshake(t *testing.T) {
node1Addr, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c") node1Addr := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
node2Addr, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59b") node2Addr := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59b")
logger := logging.New(ioutil.Discard, 0) logger := logging.New(ioutil.Discard, 0)
info := Info{ info := Info{
Address: node1Addr, Address: node1Addr,
...@@ -179,8 +179,8 @@ func TestHandshake(t *testing.T) { ...@@ -179,8 +179,8 @@ func TestHandshake(t *testing.T) {
} }
func TestHandle(t *testing.T) { func TestHandle(t *testing.T) {
node1Addr, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c") node1Addr := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c")
node2Addr, _ := swarm.ParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59b") node2Addr := swarm.MustParseHexAddress("ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59b")
nodeInfo := Info{ nodeInfo := Info{
Address: node1Addr, Address: node1Addr,
NetworkID: 0, NetworkID: 0,
......
...@@ -52,7 +52,7 @@ func TestPing(t *testing.T) { ...@@ -52,7 +52,7 @@ func TestPing(t *testing.T) {
// ping // ping
peerID := "ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c" peerID := "ca1e9f3938cc1425c6061b96ad9eb93e134dfe8734ad490164ef20af9d1cf59c"
peerIDAddress, _ := swarm.ParseHexAddress(peerID) peerIDAddress := swarm.MustParseHexAddress(peerID)
greetings := []string{"hey", "there", "fella"} greetings := []string{"hey", "there", "fella"}
rtt, err := client.Ping(context.Background(), peerIDAddress, greetings...) rtt, err := client.Ping(context.Background(), peerIDAddress, greetings...)
if err != nil { if err != nil {
......
...@@ -30,6 +30,16 @@ func ParseHexAddress(s string) (a Address, err error) { ...@@ -30,6 +30,16 @@ func ParseHexAddress(s string) (a Address, err error) {
return NewAddress(b), nil return NewAddress(b), nil
} }
// MustParseHexAddress returns an Address from a hex-encoded string
// representation, and panics if there is a parse error.
func MustParseHexAddress(s string) Address {
a, err := ParseHexAddress(s)
if err != nil {
panic(err)
}
return a
}
// String returns a hex-encoded representation of the Address. // String returns a hex-encoded representation of the Address.
func (a Address) String() string { func (a Address) String() string {
return hex.EncodeToString(a.b) return hex.EncodeToString(a.b)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment