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")
|
2019-08-21 19:15:51 +00:00
|
|
|
proc connHandler(conn: Connection): Future[void] {.async ,gcsafe.} =
|
|
|
|
result = conn.write(cstring("Hello!"), 6)
|
2019-08-21 04:58:12 +00:00
|
|
|
|
|
|
|
let transport: TcpTransport = newTransport(TcpTransport, ma, connHandler)
|
|
|
|
await transport.listen()
|
|
|
|
let streamTransport: StreamTransport = await connect(ma)
|
2019-08-21 19:15:51 +00:00
|
|
|
let msg = await streamTransport.read(6)
|
2019-08-21 04:58:12 +00:00
|
|
|
result = cast[string](msg) == "Hello!"
|
|
|
|
|
|
|
|
check:
|
|
|
|
waitFor(testListener()) == true
|