aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/node_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'p2p/discover/node_test.go')
-rw-r--r--p2p/discover/node_test.go71
1 files changed, 43 insertions, 28 deletions
diff --git a/p2p/discover/node_test.go b/p2p/discover/node_test.go
index 8ea9018c5..4c95d316f 100644
--- a/p2p/discover/node_test.go
+++ b/p2p/discover/node_test.go
@@ -48,46 +48,61 @@ var parseNodeTests = []struct {
},
{
rawurl: "enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150",
- wantResult: &Node{
- ID: MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
- IP: net.ParseIP("127.0.0.1"),
- UDP: 52150,
- TCP: 52150,
- },
+ wantResult: newNode(
+ MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
+ net.IP{0x7f, 0x0, 0x0, 0x1},
+ 52150,
+ 52150,
+ ),
},
{
rawurl: "enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@[::]:52150",
- wantResult: &Node{
- ID: MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
- IP: net.ParseIP("::"),
- UDP: 52150,
- TCP: 52150,
- },
+ wantResult: newNode(
+ MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
+ net.ParseIP("::"),
+ 52150,
+ 52150,
+ ),
+ },
+ {
+ rawurl: "enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@[2001:db8:3c4d:15::abcd:ef12]:52150",
+ wantResult: newNode(
+ MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
+ net.ParseIP("2001:db8:3c4d:15::abcd:ef12"),
+ 52150,
+ 52150,
+ ),
},
{
rawurl: "enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150?discport=22334",
- wantResult: &Node{
- ID: MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
- IP: net.ParseIP("127.0.0.1"),
- UDP: 22334,
- TCP: 52150,
- },
+ wantResult: newNode(
+ MustHexID("0x1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439"),
+ net.IP{0x7f, 0x0, 0x0, 0x1},
+ 22334,
+ 52150,
+ ),
},
}
func TestParseNode(t *testing.T) {
for i, test := range parseNodeTests {
n, err := ParseNode(test.rawurl)
- if err == nil && test.wantError != "" {
- t.Errorf("test %d: got nil error, expected %#q", i, test.wantError)
- continue
- }
- if err != nil && err.Error() != test.wantError {
- t.Errorf("test %d: got error %#q, expected %#q", i, err.Error(), test.wantError)
- continue
- }
- if !reflect.DeepEqual(n, test.wantResult) {
- t.Errorf("test %d: result mismatch:\ngot: %#v, want: %#v", i, n, test.wantResult)
+ if test.wantError != "" {
+ if err == nil {
+ t.Errorf("test %d: got nil error, expected %#q", i, test.wantError)
+ continue
+ } else if err.Error() != test.wantError {
+ t.Errorf("test %d: got error %#q, expected %#q", i, err.Error(), test.wantError)
+ continue
+ }
+ } else {
+ if err != nil {
+ t.Errorf("test %d: unexpected error: %v", i, err)
+ continue
+ }
+ if !reflect.DeepEqual(n, test.wantResult) {
+ t.Errorf("test %d: result mismatch:\ngot: %#v, want: %#v", i, n, test.wantResult)
+ }
}
}
}