nim-libp2p/tests/testtransport.nim

23 lines
794 B
Nim
Raw Normal View History

2019-08-21 04:58:12 +00:00
import unittest
import chronos
import ../libp2p/connection, ../libp2p/transport, ../libp2p/tcptransport,
../libp2p/multiaddress, ../libp2p/wire
suite "TCP transport suite":
test "test listener":
proc testListener(): Future[bool] {.async.} =
let ma: MultiAddress = Multiaddress.init("/ip4/127.0.0.1/tcp/53335")
proc connHandler(conn: Connection): Future[void] {.gcsafe.} =
let msg = "Hello"
conn.write(msg.cstring, 6)
let transport: TcpTransport = newTransport(TcpTransport, ma, connHandler)
await transport.listen()
let streamTransport: StreamTransport = await connect(ma)
let msg = await streamTransport.read()
echo "HERE!!!!"
result = cast[string](msg) == "Hello!"
check:
waitFor(testListener()) == true