test(waku api): Add tests for waku api

This commit is contained in:
Emil Ivanichkov 2024-03-13 18:15:22 +02:00 committed by Emil Ivanichkov
parent 1de5bbfedb
commit 433d00d7fc
4 changed files with 75 additions and 12 deletions

View File

@ -13,8 +13,7 @@ import
waku/common/logging,
# Local modules
./waku_handshake_utils,
./waku_node
./waku_handshake_utils
type WakuPairResult* = object
wakuNode*: WakuNode

View File

@ -63,8 +63,8 @@ proc run(snm: SNM) {.async.} =
proc setupLogLevel*(level: LogLevel) =
topics_registry.setLogLevel(level)
proc doRunStatusNodeManager(config: StatusNodeManagerConfig,
rng: ref HmacDrbgContext) =
proc doRunStatusNodeManager*(config: StatusNodeManagerConfig,
rng: ref HmacDrbgContext) =
notice "Starting Status Node Manager"
let snm = waitFor SNM.init(rng, config)

View File

@ -1,8 +0,0 @@
# This is just an example to get you started. You may wish to put all of your
# tests into a single file, or separate them into multiple `test1`, `test2`
# etc. files (better names are recommended, just make sure the name starts with
# the letter 't').
#
# To run these tests, simply execute `nimble test`.
import unittest

72
tests/test_waku_api.nim Normal file
View File

@ -0,0 +1,72 @@
import
std/json,
confutils, chronos,
libp2p/crypto/crypto,
presto/[route, segpath, server, client],
serialization, json_serialization,
sequtils,
stew/byteutils,
testutils/unittests,
# unittest,
../src/status_node_manager,
../src/status_node_manager/[config, utils, waku],
../src/status_node_manager/status_node_manager_status,
../src/status_node_manager/rest/common,
../src/status_node_manager/rest/apis/waku/[
rest_waku_api,
rest_waku_calls,
types
]
const wakuApiPort = 13100
proc startSNM(rng: ref HmacDrbgContext) =
let conf = try: StatusNodeManagerConfig.load(cmdLine = mapIt([
"--rest=true",
"--rest-address=127.0.0.1",
"--rest-port=" & $wakuApiPort,
], it))
except:
quit 1
doRunStatusNodeManager(conf, rng)
proc runTest(wakuApiPort: Port) {.async.} =
let client = RestClientRef.new(initTAddress("127.0.0.1", wakuApiPort))
suite "Waku API tests":
const testRequestData = WakuPairRequestData(
qr: "testQr",
qrMessageNameTag: "testQrMessageNameTag",
pubSubTopic: "testPubSubTopic",
)
asyncTest "Server side is not complete, so request with correct data, it should return 500 error.":
let
response = await client.wakuPairPlain(testRequestData)
responseJson = Json.decode(response.data, JsonNode)
check:
response.status == 500
responseJson["message"].getStr() == "Internal Server Error"
proc delayedTests() {.async.} =
while snmStatus != SNMStatus.Running:
await sleepAsync(1.seconds)
await sleepAsync(2.seconds)
let deadline = sleepAsync(10.minutes)
await runTest(Port(wakuApiPort)) or deadline
snmStatus = SNMStatus.Stopping
proc main() {.async.} =
let rng = HmacDrbgContext.new()
asyncSpawn delayedTests()
startSNM(rng)
waitFor main()