2022-06-15 15:02:02 +02:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-16 00:08:47 +01:00
|
|
|
import stew/results, stew/byteutils, testutils/unittests, json_serialization
|
2024-07-06 03:33:38 +05:30
|
|
|
import waku/waku_api/rest/serdes, waku/waku_api/rest/debug/types
|
2022-06-02 11:45:00 +02:00
|
|
|
|
2023-02-13 15:22:24 +01:00
|
|
|
suite "Waku v2 REST API - Debug - serialization":
|
2022-06-02 11:45:00 +02:00
|
|
|
suite "DebugWakuInfo - decode":
|
|
|
|
test "optional field is not provided":
|
|
|
|
# Given
|
|
|
|
let jsonBytes = toBytes("""{ "listenAddresses":["123"] }""")
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = decodeFromJsonBytes(DebugWakuInfo, jsonBytes, requireAllFields = true)
|
|
|
|
|
|
|
|
# Then
|
2023-02-13 15:22:24 +01:00
|
|
|
require(res.isOk())
|
2022-06-02 11:45:00 +02:00
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value.listenAddresses == @["123"]
|
2023-02-13 15:22:24 +01:00
|
|
|
value.enrUri.isNone()
|
2022-06-02 11:45:00 +02:00
|
|
|
|
|
|
|
suite "DebugWakuInfo - encode":
|
|
|
|
test "optional field is none":
|
|
|
|
# Given
|
|
|
|
let data = DebugWakuInfo(listenAddresses: @["GO"], enrUri: none(string))
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = encodeIntoJsonBytes(data)
|
|
|
|
|
|
|
|
# Then
|
2023-02-13 15:22:24 +01:00
|
|
|
require(res.isOk())
|
2022-06-02 11:45:00 +02:00
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value == toBytes("""{"listenAddresses":["GO"]}""")
|