aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/discover/node_test.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-04-23 18:11:21 +0800
committerFelix Lange <fjl@twurst.com>2015-04-30 21:02:23 +0800
commit72ab6d325555c742c6b70202d865ec23b50734d6 (patch)
tree92522e695c39ab4ee31321b5b469611f001fd684 /p2p/discover/node_test.go
parentb34a8ef624499e15cc3a2a51bddd94391f9b993e (diff)
downloaddexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar.gz
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar.bz2
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar.lz
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar.xz
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.tar.zst
dexon-72ab6d325555c742c6b70202d865ec23b50734d6.zip
p2p/discover: track sha3(ID) in Node
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)
+ }
}
}
}