-
Notifications
You must be signed in to change notification settings - Fork 109
/
test_wire_protocol.nim
51 lines (43 loc) · 1.58 KB
/
test_wire_protocol.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Nimbus
# Copyright (c) 2019-2023 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# https://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
# https://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except
# according to those terms.
import
eth/p2p, eth/p2p/rlpx,
chronos, testutils/unittests,
../nimbus/sync/protocol
var nextPort = 30303
proc localAddress*(port: int): Address =
let port = Port(port)
result = Address(udpPort: port, tcpPort: port,
ip: parseIpAddress("127.0.0.1"))
proc setupTestNode*(
rng: ref HmacDrbgContext,
capabilities: varargs[ProtocolInfo, `protocolInfo`]): EthereumNode {.gcsafe.} =
# Don't create new RNG every time in production code!
let keys1 = KeyPair.random(rng[])
var node = newEthereumNode(
keys1, localAddress(nextPort), NetworkId(1),
addAllCapabilities = false,
bindUdpPort = Port(nextPort), bindTcpPort = Port(nextPort),
rng = rng)
nextPort.inc
for capability in capabilities:
node.addCapability capability
node
suite "Testing protocol handlers":
asyncTest "Failing connection handler":
let rng = newRng()
var node1 = setupTestNode(rng, eth)
var node2 = setupTestNode(rng, eth)
node2.startListening()
let peer = await node1.rlpxConnect(newNode(node2.toENode()))
check:
peer.isNil == false
# To check if the disconnection handler did not run
#node1.protocolState(eth).count == 0