2019-02-05 15:40:29 +00:00
|
|
|
#
|
|
|
|
# Ethereum P2P
|
|
|
|
# (c) Copyright 2018
|
|
|
|
# Status Research & Development GmbH
|
|
|
|
#
|
|
|
|
# Licensed under either of
|
|
|
|
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
|
|
|
# MIT license (LICENSE-MIT)
|
|
|
|
|
2021-04-18 15:10:10 +00:00
|
|
|
{.used.}
|
|
|
|
|
2021-04-06 11:33:24 +00:00
|
|
|
import
|
2021-12-11 18:12:55 +00:00
|
|
|
std/[net, options],
|
|
|
|
unittest2,
|
2022-02-27 04:53:11 +00:00
|
|
|
../../eth/p2p/[enode, bootnodes]
|
2019-02-05 15:40:29 +00:00
|
|
|
|
|
|
|
suite "ENode":
|
|
|
|
test "Go-Ethereum tests":
|
|
|
|
const enodes = [
|
|
|
|
"http://foobar",
|
|
|
|
"enode://01010101@123.124.125.126:3",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@hostname:3",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:foo",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:3?discport=foo",
|
|
|
|
"01010101",
|
|
|
|
"enode://01010101",
|
|
|
|
"://foo",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@[::]:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@[2001:db8:3c4d:15::abcd:ef12]:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@127.0.0.1:52150?discport=22334",
|
|
|
|
]
|
|
|
|
|
|
|
|
const results = [
|
2020-04-06 16:24:15 +00:00
|
|
|
some IncorrectScheme,
|
|
|
|
some IncorrectNodeId,
|
|
|
|
some IncorrectIP,
|
|
|
|
some IncorrectPort,
|
|
|
|
some IncorrectDiscPort,
|
|
|
|
some IncorrectScheme,
|
|
|
|
some IncorrectNodeId,
|
|
|
|
some IncorrectScheme,
|
|
|
|
none(ENodeError),
|
|
|
|
none(ENodeError),
|
|
|
|
none(ENodeError),
|
|
|
|
none(ENodeError),
|
2019-02-05 15:40:29 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for index in 0..<len(enodes):
|
2020-04-06 16:24:15 +00:00
|
|
|
let res = ENode.fromString(enodes[index])
|
|
|
|
check (results[index].isSome and res.error == results[index].get) or
|
|
|
|
res.isOk
|
|
|
|
|
|
|
|
if res.isOk:
|
|
|
|
check enodes[index] == $res[]
|
2019-02-05 15:40:29 +00:00
|
|
|
|
|
|
|
test "Custom validation tests":
|
|
|
|
const enodes = [
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@256.0.0.1:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.256.0.1:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.256.1:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.256:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439:@1.1.1.255:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439:bar@1.1.1.255:52150",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.255:-1",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.255:65536",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.255:1024?discport=-1",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.255:1024?discport=65536",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@1.1.1.255:1024?discport=65535#bar",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a439@",
|
|
|
|
"enode://1dd9d65c4552b5eb43d5ad55a2ee3f56c6cbc1c64a5c8d659f51fcd51bace24351232b8d7821617d2b29b54b81cdefb9b3e9c37d7fd5f63270bcc9e1a6f6a43Z@1.1.1.1:25?discport=22"
|
|
|
|
]
|
|
|
|
|
|
|
|
const results = [
|
2020-04-06 16:24:15 +00:00
|
|
|
some IncorrectIP,
|
|
|
|
some IncorrectIP,
|
|
|
|
some IncorrectIP,
|
|
|
|
some IncorrectIP,
|
|
|
|
none(ENodeError),
|
|
|
|
some IncorrectUri,
|
|
|
|
some IncorrectPort,
|
|
|
|
some IncorrectPort,
|
|
|
|
some IncorrectDiscPort,
|
|
|
|
some IncorrectDiscPort,
|
|
|
|
some IncorrectUri,
|
|
|
|
some IncorrectIP,
|
|
|
|
some IncorrectNodeId
|
2019-02-05 15:40:29 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for index in 0..<len(enodes):
|
2020-04-06 16:24:15 +00:00
|
|
|
let res = ENode.fromString(enodes[index])
|
2019-02-05 15:40:29 +00:00
|
|
|
|
2020-04-06 16:24:15 +00:00
|
|
|
check (results[index].isSome and res.error == results[index].get) or
|
|
|
|
res.isOk
|
2022-02-27 04:53:11 +00:00
|
|
|
|
|
|
|
test "Bootnodes test":
|
|
|
|
proc runBNTest(bns: openArray[string]): bool =
|
|
|
|
for z in bns:
|
|
|
|
let res = ENode.fromString(z)
|
|
|
|
if res.isErr: return false
|
|
|
|
true
|
|
|
|
|
|
|
|
check runBNTest(MainnetBootnodes)
|
|
|
|
check runBNTest(RopstenBootnodes)
|
|
|
|
check runBNTest(RinkebyBootnodes)
|
|
|
|
check runBNTest(GoerliBootnodes)
|
|
|
|
check runBNTest(DiscoveryV5Bootnodes)
|
|
|
|
check runBNTest(KovanBootnodes)
|
|
|
|
check runBNTest(StatusBootNodes)
|
|
|
|
check runBNTest(StatusBootNodesStaging)
|
|
|
|
check runBNTest(StatusBootNodesTest)
|