nim-eth-p2p/tests/tserver.nim

35 lines
946 B
Nim
Raw Normal View History

#
# Ethereum P2P
# (c) Copyright 2018
# Status Research & Development GmbH
#
# Licensed under either of
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
import sequtils
import eth_keys, asyncdispatch2
import eth_p2p
2018-05-10 12:51:33 +00:00
2018-06-19 11:16:36 +00:00
const clientId = "nim-eth-p2p/0.0.1"
2018-05-10 12:51:33 +00:00
proc localAddress(port: int): Address =
let port = Port(port)
result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1"))
proc test() {.async.} =
let node1Keys = newKeyPair()
let node1Address = localAddress(30303)
var node1 = newEthereumNode(node1Keys, node1Address, 1, nil)
node1.startListening()
2018-05-10 12:51:33 +00:00
let node2Keys = newKeyPair()
var node2 = newEthereumNode(node2Keys, localAddress(30304), 1, nil)
2018-05-10 12:51:33 +00:00
let node1AsRemote = newNode(initENode(node1Keys.pubKey, node1Address))
let peer = await node2.rlpxConnect(node1AsRemote)
2018-05-10 12:51:33 +00:00
doAssert(not peer.isNil)
waitFor test()