mirror of https://github.com/status-im/nim-eth.git
108 lines
5.3 KiB
Nim
108 lines
5.3 KiB
Nim
#
|
|
# Ethereum P2P
|
|
# (c) Copyright 2018
|
|
# Status Research & Development GmbH
|
|
#
|
|
# Licensed under either of
|
|
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
|
# MIT license (LICENSE-MIT)
|
|
|
|
{.used.}
|
|
|
|
import
|
|
std/[net, options],
|
|
unittest2,
|
|
../../eth/p2p/[enode, bootnodes]
|
|
|
|
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 = [
|
|
some IncorrectScheme,
|
|
some IncorrectNodeId,
|
|
some IncorrectIP,
|
|
some IncorrectPort,
|
|
some IncorrectDiscPort,
|
|
some IncorrectScheme,
|
|
some IncorrectNodeId,
|
|
some IncorrectScheme,
|
|
none(ENodeError),
|
|
none(ENodeError),
|
|
none(ENodeError),
|
|
none(ENodeError),
|
|
]
|
|
|
|
for index in 0..<len(enodes):
|
|
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[]
|
|
|
|
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 = [
|
|
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
|
|
]
|
|
|
|
for index in 0..<len(enodes):
|
|
let res = ENode.fromString(enodes[index])
|
|
|
|
check (results[index].isSome and res.error == results[index].get) or
|
|
res.isOk
|
|
|
|
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(KovanBootnodes)
|