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
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
waku_node,
|
|
|
|
node/waku_node as waku_node2,
|
|
|
|
# TODO: Remove after moving `git_version` to the app code.
|
|
|
|
waku_api/rest/server,
|
|
|
|
waku_api/rest/client,
|
|
|
|
waku_api/rest/responses,
|
|
|
|
waku_api/rest/debug/handlers as debug_api,
|
|
|
|
waku_api/rest/debug/client as debug_api_client,
|
|
|
|
],
|
2023-04-05 14:01:51 +00:00
|
|
|
../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()
|
2023-12-14 06:16:39 +00:00
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
|
|
|
extIp = parseIpAddress("127.0.0.1")
|
2024-06-12 13:07:33 +00:00
|
|
|
port = Port(0)
|
2023-02-13 14:22:24 +00:00
|
|
|
|
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()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
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
|
2024-03-15 23:08:47 +00:00
|
|
|
response.data.listenAddresses ==
|
|
|
|
@[$node.switch.peerInfo.addrs[^1] & "/p2p/" & $node.switch.peerInfo.peerId]
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
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()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-02-13 14:22:24 +00:00
|
|
|
|
|
|
|
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()
|