2023-02-13 14:22:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/shims/net,
|
|
|
|
testutils/unittests,
|
|
|
|
presto,
|
|
|
|
presto/client as presto_client,
|
|
|
|
libp2p/peerinfo,
|
|
|
|
libp2p/multiaddress,
|
|
|
|
libp2p/crypto/crypto
|
|
|
|
import
|
2023-04-05 09:58:59 +00:00
|
|
|
../../waku/v2/waku_node,
|
2023-04-05 14:01:51 +00:00
|
|
|
../../waku/v2/node/waku_node as waku_node2, # TODO: Remove after moving `git_version` to the app code.
|
2023-02-13 14:22:24 +00:00
|
|
|
../../waku/v2/node/rest/server,
|
|
|
|
../../waku/v2/node/rest/client,
|
|
|
|
../../waku/v2/node/rest/responses,
|
|
|
|
../../waku/v2/node/rest/debug/handlers as debug_api,
|
2023-04-05 14:01:51 +00:00
|
|
|
../../waku/v2/node/rest/debug/client as debug_api_client,
|
|
|
|
../testlib/common,
|
|
|
|
../testlib/wakucore,
|
|
|
|
../testlib/wakunode
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc testWakuNode(): WakuNode =
|
|
|
|
let
|
|
|
|
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
|
|
|
bindIp = ValidIpAddress.init("0.0.0.0")
|
|
|
|
extIp = ValidIpAddress.init("127.0.0.1")
|
|
|
|
port = Port(58000)
|
|
|
|
|
2023-04-05 14:01:51 +00:00
|
|
|
newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
suite "Waku v2 REST API - Debug":
|
|
|
|
asyncTest "Get node info - GET /debug/v1/info":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58001)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
installDebugApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
let response = await client.debugInfoV1()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.listenAddresses == @[$node.switch.peerInfo.addrs[^1] & "/p2p/" & $node.switch.peerInfo.peerId]
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "Get node version - GET /debug/v1/version":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
|
|
|
let restPort = Port(58002)
|
|
|
|
let restAddress = ValidIpAddress.init("0.0.0.0")
|
|
|
|
let restServer = RestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
|
|
|
|
installDebugApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# When
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
let response = await client.debugVersionV1()
|
|
|
|
|
|
|
|
# Then
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2023-04-05 14:01:51 +00:00
|
|
|
response.data == waku_node2.git_version
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|